Comment for clarity.
All the persistence services behave as follows -
If you ask for historicState() for some instant in time, it is most likely that the data does not exist for that particular millisecond.
The persistence service therefore returns the “next oldest” data, the record from earlier than your target instant, on the assumption that data was still valid at the target instant.
Example - persisting data every hour, on the hour.
Request historicState() for 02:10, you’ll get 02:00 data
Request historicState() for 02:59, you’ll get 02:00 data
Example - persisting data every minute
Request historicState() for “now”, you’ll get data from somewhere up to a minute ago.
Request historicState() for “now - 1 min”, you’ll get data from somewhere between a minute and two minutes ago.
Yes, of course - this is in the docs.
You’re right, it will probably help you understand better what is going on.
val myRecord = myItem.historicState(someInstant,"rrd4j")
if (myRecord !== null) {
logInfo("test", myItem.name + "data " + myRecord.state.toString + " at " + myRecord.getTimestamp.toString)
} else {
logInfo("test", myItem.name + " no data")
}
For dealing with ever-increasing counters (like a kWh meter) you might also find minimumSince() to be a useful tool. This actually works better where you have “gaps” in the time sequence in an rrd4j database. Found that out the hard way.