Persistence rrd4j and historicstates

Hi

I’m new to persistence, I will make a log of my rain sensor, for each hour, day, week
I use OH2 and I think a need to use the historicstates, but I am really not sure.
So I need help for build the persist, rule and I item files.

I have some items, Oregon_RainTotal counting up all the time then it is rains one message for 0,5mm rain, so this number can´t be used for anything, but you can count how many inputs there has been the last hour,day,week.

I did find this code on this site, but I don’t know if this is the right code for my job.

Number Oregon_RainTotal "Total rainfall [%.2f mm]" (Rain)
Number Oregon_RainTotal_H "Rainfall Hour [%.2f mm]" (Rain)
Number Oregon_RainTotal_D "Rainfall Day: [%.2f mm]" (Rain)
Number Oregon_RainTotal_W "Rainfall Week: [%.2f mm]" (Rain)

and then I have this rule I found, dont know if it can work for me

rule "Rain Total Changed"
when
    Time cron "* 0/1 * * * ?"
then
    // Post totals update
    Oregon_RainTotal_H.postUpdate(Oregon_RainTotal.deltaSince(now.minusHours(1))
    Oregon_RainTotal_D.postUpdate(Oregon_RainTotal.deltaSince(now.minusDays(1))
    Oregon_RainTotal_W.postUpdate(Oregon_RainTotal.deltaSince(now.minusWeeks(1))

end

)
)

I know anything about persistence but I can see that I need something to get this to work

Isn’t there anybody who can help me further on in my rain project

Which persistence are you using? Any at all so far?
You should be persisting Oregon_RainTotal in order to get anything for your other items.

Hi thanks for helping

I don’t know witch persistence there is best for my project, now I installed RRD4j is it okay?

I’m using rrd4j. However I have no experience in using historicstates with rrd4j, that migth no function.
But I’m sure you do need a working persistence in order to use historicstates!

I have no experience with persistence so I don’t know how to write the persis file, can I use something else instead of the historicstates to give me the log data?

That depends on what you actually want to display.
In your case (RainFallSince…) I’d think you will finally need something like the historic states.
However I’d start by creating a working peristence.
Read through the docs (for rrd4j the OpenHab1 docs are still valid) and try to start your persistence. When encountering any problems just ask again.

Note: Just checked on my persited item (rrd4j database), the call:

MyItem.deltaSince(now.minusDays(1),“rrd4j”)

worked! Output was “0.0100000000000000088817841970012523233890533447265625”

Should this code make a connection to a specific rrd4j .persise file, how is this done!
Could you show your persise file, and the full rule file, because I get nothing with this code

What have you done so far in order to start persisting?
Load the rrd4j persistence service via PaperUI. (I guess yes)
Configure rrd4j via the persist and config files in order to tell what and how often to persist and to configure how the values and how many values are kept inside the database. (I guess not)

My files:
rrd4j.cfg saved under Services

MyLogger.def=GAUGE,90,0,3,60
MyLogger.archives=MAX,.5,1,1440:MAX,.5,5,2016:MAX,.5,15,2668
MyLogger.items=MyItem1, MyItem2,…
That configures rrd4j to saved my Items in three archives wich cover a day (euch minute), aber Werk (5 minute steps) and 4weeks(15 Minute steps).

My rrd4j.persist which is saved under persistence

Strategies {
everyMinute : "0 * * * * ?"
everyHour : "0 0 * * * ?"
everyDay : “0 0 0 * * ?”
}

Items {
MyItem1,MyItem2,… : strategy = everyMinute
}

In this file you state which Items Arena saved and in what timesteps. Note that rrd4j needs a strategie of everyMinute!

[Edit] I’m writing on a tablet, had to remove so ein typos

Hi

I¨m having truble with this log thing

so far I have done this, with no output on my 4 rain total items

my items:

Number Oregon_RainTotal_H "Regn seneste Time [%.2f mm]" (Vejrst)
Number Oregon_RainTotal_D "Regn seneste Dag: [%.2f mm]" (Vejrst)
Number Oregon_RainTotal_W "Regn seneste Uge: [%.2f mm]" (Vejrst)
Number Oregon_RainTotal_M "Regn seneste Minut: [%.2f mm]" (Vejrst)

Number Oregon_RainTotal "Total regnfald [%.2f mm]" (Vejrst) //sensor mm total

my rules:

rule "Rain Total Changed"
when
    Time cron "0 * * * * ?"
then
    // Post totals update
    Oregon_RainTotal_H.postUpdate(Oregon_RainTotal.deltaSince(now.minusHours(1),"rrd4j")
    Oregon_RainTotal_D.postUpdate(Oregon_RainTotal.deltaSince(now.minusDays(1),"rrd4j")
    Oregon_RainTotal_W.postUpdate(Oregon_RainTotal.deltaSince(now.minusWeeks(1),"rrd4j")
    Oregon_RainTotal_M.postUpdate(Oregon_RainTotal.deltaSince(now.minusMinute(1),"rrd4j")

end

)
)

rrd4j.persist:

// persistence strategies have a name and a definition and are referred to in the "Items" section
Strategies {
	// for rrd charts, we need a cron strategy
	everyMinute : "0 * * * * ?"
	everyHour : "0 0 * * * ?"
 	everyDay : "0 0 0 * * ?"
 	everyWeek :"0 0 0 0 * ?"
}

Items {
	 Oregon_RainTotal : strategy = everyMinute
}

// vim: syntax=Xtend

rrd4j.cfg:

MyLogger.def=GAUGE,90,0,3,60
MyLogger.archives=MAX,.5,1,1440:MAX,.5,5,2016:MAX,.5,15,2668
MyLogger.items=Oregon_RainTotal
#That configures rrd4j to saved my Items in three archives wich cover a day (euch minute), aber Werk (5 minute steps) and 4weeks(15 Minute steps). 

I have no idea what I have done worng.

I’d use the RestAPI in order to check wether any value is persited for the Item “Oregon_RainTotal” at all.

I get value to the Oregon_RainTotal item, I can see it in the oh log and in my UI

But i i check the /persistence/items/Oregon_RainTotal, i get this, so it looks like the persistence does not work as I should

{
  "name": "Oregon_RainTotal",
  "datapoints": "0",
  "data": []
}

That says persistence isn’t working.
I’d try a restart of OH.
If that doesn’t help try to delete to .rrd files under userdata persistence/rrd4j

I see you are using my setup of rrd4j.
This setup is used for data that isn’the summed up like your rain data. Make sure the values are summed up elsewhere.
Also my rrd4j database will not hold any data older then 4 Weeks!

After a reboot I get data in to the database but not out the items:

{
  "name": "Oregon_RainTotal",
  "datapoints": "7",
  "data": [
    {
      "time": 1492380240000,
      "state": "2"
    },
    {
      "time": 1492380480000,
      "state": "2"
    },
    {
      "time": 1492380720000,
      "state": "2.5"
    },
    {
      "time": 1492380960000,
      "state": "3.5"
    },
    {
      "time": 1492381200000,
      "state": "5"
    },
    {
      "time": 1492381440000,
      "state": "5"
    },
    {
      "time": 1492381680000,
      "state": "5"
    }
  ]
}

So, finally the persistence is working somehow.
First thing to note, you only get one value every 4 minutes stored. Using the settings you posted above it should be every minute ( which is needed for rrd4j)???
In your rule, put in some lines of login for in order to have printouts in the log.
Something like:

logInfo (“RainTotal Changed”, “Oregon_RainTotal.deltaSince(now.minusHours(1)): {}”, Oregon_RainTotal.deltaSince (now.minusHours (1)),“rrd4j”)

Note that this might not show anything until you have saved data correctly for anow hour!

Hi
I have data coming in to my Oregon_RainTotal_H item now so it’s working now, so maybe _D and _W is comming as well.
How do I change the time from 4min to 1 min?
Isn’t this 1min “0 * * * * ?”

Do you know how to read the time stamp in the rrd file because this “time”: 1492381680000 makes no sense

Presently I have no idea why your setup (which is as you posted my setup of rrd4j) is saving only at a 4 minute step. That isn’t done in the Rules! It is set in the .persistence file as the strategy.
The timestamp is in milliseconds counted from a starting point (which I don’t know/care). The difference between consecutive values should be 60000 for minute steps.