Clarification needed for persistence

Hi all,

I discovered that one of my items did not respont properly to persistence.deltaBetween. The associated hardware (Thing) has been implemented around end of January, persistance I did activate a couple of days ago (since I do not persist all). Just to make it easier to follow, it is a shelly3 Pro EM which monitors my power/energy consumption.

I want to get the amount of energy since year beginning. Which is usally easy to get with

var ldtYear = now.withMonth(1).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
var nEnergySinceStartofYear = iNetzbetzug.persistence.deltaBetween(ldtYear, now, ‘rrdj4’);

I assume that the missing value at year start leads to the null value retrieved by deltaBetween. To get around this, I tried to insert a value at that timestamp, with

var timestamp = time.toZDT(‘2026-01-01T00:00:00’);
myItem.persistence.persist(timestamp, ‘0 Wh’, ‘rrdj4’);

which is running without any error, but I discoverd in the debug log of persistence that the value is not persited. A crosscheck discovered that this is true.

Now my question:

  1. Is this a exspected behaviour of persistence in oh 5?
  2. Should there at least a warning, that the value is not written?
  3. How do I get over my issue with deltaBetween?

Thanks for all reviewers and comments.

Best

markus

rrd4j persistence does not allow writing in the past or the future, only at current time. That is the nature of the database and has always been like that. To write at other timestamps, you need to configure an alternative persistence solution using another persistence extension.

You are correct deltaBetween needs persisted data to work with. If there is nothing at or before your first timestamp in the request, it will not guess and not give an answer. It is impossible to know what the answer should be. The data is not there.

mhhh, I tried mapdb, same result

  1. No warning/ error at persist
  2. no value to retrieve after persist

Do you mind to suggest a persistence service that does allow persist data in the past? Or suggest any other option I might have?

mapsb is definitely not going to work. As the docs say, it only saves one value. There is no delta between for one value.

Any of the other ones support this. Influxdb is popular.

Mapdb only stores one value and, as mentioned, the way rrd4j works to keep a constant size for storage doesn’t allow for saving stuff in the past or the future.

Configure your rule to use the day you enabled persistence.

Create a reminder for new years next year to change the rule to use the start of the year.

If you are clever you could even encode this into the rule itself.

let currYear = time.toZDT().year();
val startTime = (currYear < 2026) ? time.toZDT('<dt persistence started>') : time.toZDT(currYear+'-01-01T00:00:00');

Ok, then lets be smart, I did the following:

  var nMinPersistedTime = iNetzbetzug.persistence.minimumSince(ldtYear).timestamp;
  var nEnergySinceStartofYear = iNetzbetzug.persistence.deltaBetween(nMinPersistedTime, now).numericState;

which is an elegant solution that works from now on and in the next years.

Thanks for clarification about different persistence services. I would love to read about limits/capabilities of rrdj4 very short, in the persistence docs here Persistence | openHAB , because if someone is not picking his own service it is the default and might clarify about the capabilities. A thing there a lot of people acting like me, when try to use Persistence, looking in the docs about it, but not following every link to further information.