Number items calculated by a rule not stored into rrd4j persistence

Hello,

I have a problem saving number items calculated by a rule into a rrd4j persistence

The raw number item “GoogleMaps_duration_in_traffic_value” is stored correctly and can be shown in the chart of the Habpanel. The current converted number “GoogleMaps_duration_in_traffic_value_minutes” can be shown in Habpanel (Dummy Widget) but is not stored into the rrd4j.
So conversion works but storing or reading rrd4j does not work.
What am I doing wrong?

Here my configuration:

OpenHAB 2.3

Item to get Google Maps traffic duration in seconds

Number	GoogleMaps_duration_in_traffic_value		"Duration [%s]"		(gGoogleMaps)	{ http="<[https://maps.googleapis.com/maps/api/distancematrix/json?origins=Amsterdam&destinations=Rotterdam&language=NL&departure_time=now&traffic_model=best_guess&mode=driving&key=YOUR_API_KEY:300000:JSONPATH($.rows[0].elements[0].duration_in_traffic.value)]" }
Number  GoogleMaps_duration_in_traffic_value_minutes   "Duration [%f]"         (gGoogleMaps)

Rule to convert seconds to minutes

rule "Calculate GoogleMaps_duration_in_traffic_value_minutes"
when
  Item GoogleMaps_duration_in_traffic_value received update
then
  val v = GoogleMaps_duration_in_traffic_value.state as DecimalType
  GoogleMaps_duration_in_traffic_value_minutes.postUpdate(v / 60.0)
end

services/rrd4j.cfg

ctr5min.def=COUNTER,900,0,U,300
ctr5min.archives=AVERAGE,0.5,1,365:AVERAGE,0.5,7,300
ctr5min.items=GoogleMaps_duration_in_traffic_value,GoogleMaps_duration_in_traffic_value_minutes

persistence/rrd4j.persist

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

Items {
  GoogleMaps_duration_in_traffic_value : strategy = everyMinute, restoreOnStartup
  GoogleMaps_duration_in_traffic_value_minutes : strategy = everyMinute, restoreOnStartup
}

Thanks for your help
Steffen

You did show the Definition of the item “GoogleMaps_duration_traffic_value” (a Number) but NOT “GoogleMaps_duration_in_traffic_value_minutes”. Assuming it is also defined as a Number it should work the same as the other one.
How did you set up both charts?(Assuming you try to show them on different charts)

Sorry. I did not post the item here. Is corrected now.

http://localhost:8080/rest/persistence/items/GoogleMaps_duration_in_traffic_value
shows good values

{"name":"GoogleMaps_duration_in_traffic_value","datapoints":"22","data":[{"time":1528091280000,"state":"2758.25"},{"time":1528091520000,"state":"2775"},
...
{"time":1528096080000,"state":"3246"},{"time":1528096320000,"state":"3237"}]}

http://localhost:8080/rest/persistence/items/GoogleMaps_duration_in_traffic_value_minutes
shows wrong values. As said in a habpanel dummy Widget it is shown correctly.

{"name":"GoogleMaps_duration_in_traffic_value_minutes","datapoints":"20","data":[{"time":1528091100000,"state":"2.444444450000001989309339478495530784130096435546875"},{"time":1528091400000,"state":"14316558.1699999906122684478759765625"},{"time":1528091700000,"state":"2.083333340000002475989049344207160174846649169921875"},{"time":1528092000000,"state":"14316560.436666667461395263671875"},{"time":1528092300000,"state":"5.75"},{"time":1528092600000,"state":"28633115.6066666655242443084716796875"},{"time":1528092900000,"state":"42949667.29333333671092987060546875"},{"time":1528093200000,"state":"28633117.4066666662693023681640625"},{"time":1528093500000,"state":"28633114.890000008046627044677734375"},{"time":1528093800000,"state":"28633116.5566666685044765472412109375"},{"time":1528094100000,"state":"14316557.9366666637361049652099609375"},{"time":1528094400000,"state":"42949669.460000000894069671630859375"},{"time":1528094700000,"state":"42949672.70999999344348907470703125"},{"time":1528095000000,"state":"28633116.256666667759418487548828125"},{"time":1528095300000,"state":"28633119.3233333341777324676513671875"},{"time":1528095600000,"state":"14316558.83666666410863399505615234375"},{"time":1528095900000,"state":"57266224.946666657924652099609375"},{"time":1528096200000,"state":"28633116.273333333432674407958984375"},{"time":1528096500000,"state":"14316561.2533333338797092437744140625"},{"time":1528096800000,"state":"42949670.4099999964237213134765625"}]}

In the habpanel I use the Chart Widget using Type Standard. But any other does not show better data.

The question was to which TYPE “GoogleMaps_duration_in_traffic_value_minutes” is defined in the .items file.

However, to the REST Output for “GoogleMaps_duration_in_traffic_value_minutes” showing numbers alternating between values below 10 and above 1 000 000 point to an error in the calculation. Did you see corresponding values on the DummyWidget?

Try that:
Is GoogleMaps_duration_in_traffic_value_minutes involved in any other rule or binding?

rule "Calculate GoogleMaps_duration_in_traffic_value_minutes"
when
  Item GoogleMaps_duration_in_traffic_value received update
then
  val v = (GoogleMaps_duration_in_traffic_value.state as Number) / 60.0
  GoogleMaps_duration_in_traffic_value_minutes.postUpdate(v)
end

Restart openHAB and see, if it works.
Change to

Items {GoogleMaps_duration_in_traffic_value, GoogleMaps_duration_in_traffic_value_minutes : strategy = everyMinute, restoreOnStartup}

or

Items {gGoogleMaps : strategy = everyMinute, restoreOnStartup}

@opus
No I do not see this values in the DummyWidget

@vzorglub and hr3
Your suggestions had no effect I think

What I did now is to remove the configuration lines in the services/rrd4j.cfg and now it is working a bit.
That means the correct values are stored but not every minute (accoring to the timestamp i think every 7 minutes)

{"name":"GoogleMaps_duration_in_traffic_value_minutes","datapoints":"4","data":[{"time":1528111620000,"state":"35.14999999999999857891452847979962825775146484375"},{"time":1528112040000,"state":"35.5285714285714249172087875194847583770751953125"},{"time":1528112460000,"state":"36.58333333142856957920230343006551265716552734375"},{"time":1528112880000,"state":"37.02142857142856513519291183911263942718505859375"}]}

It seems that the cron job is not running every minute??

The last number (300) is asking for a “step” size of 5 minutes (correlating with your naming of the db). If you want a value every minute a Setting of 60 would be better (IMHO).

When changing any cfg or persit file you’d better delete the old .rrd files and restart the bündle or OH completly.

Do I have to configure something in the services/rrd4j.cfg?
I have read some posts where nothing is configured here.
In my opinion services/rrd4j.cfg is only for averaging etc. but until now i do not really understand the syntax of this file.

But I would expect that the following should save the value every minute. But this seems to be not the case.

persistence/rrd4j.persist

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

Items {
  GoogleMaps_duration_in_traffic_value_minutes : strategy = everyMinute, restoreOnStartup
}

Yes I delete the files and restart OH.

If you have no rrd4j.cfg Default values will be taken.
However the value(300) is described like:

Step (set in .def=<dstype>,<heartbeat>,[<min>|U],[<max>|U],<step> with step in seconds)

Sets the timeintervall(seconds) between consecutive readings.

in the docs!

When i change

ctr5min.def=COUNTER,900,0,U,300

to

ctr5min.def=GAUGE,900,0,U,300

at least the values are correctly stored. Regarding storage frequency, averaging I have to check.

http://localhost:8080/rest/persistence/items/GoogleMaps_duration_in_traffic_value_minutes

{"name":"GoogleMaps_duration_in_traffic_value_minutes","datapoints":"1","data":[{"time":1528119300000,"state":"37.32254901764705579125802614726126194000244140625"}]}