How to persist DateTime items in Openhab3

I have various DateTime items in OpenHab3. I find that after a reboot they all turn to “Null”. Shouldn’t they be persisted with the RRD4j default persistence?

There was an issue to add support for DateTime Items but I don’t know it’s status. I’m pretty sure it didn’t make it into OH 3.0. But even then, rrd4j doesn’t support all Item types. If you want to restore Strings and other similar such Items you’ll want to switch to mapdb for restoreOnStartup.

Thanks Rich. I will try the mapdb. Do I turn the rrd4j persistence off then?

I would create a new rrd4j.persist file and configure it to do everything that it does by default except for the restore on startup. That would be to persist all (supported) Items on every change and every minute. Leave rrd4j as the default as well. That way all the analyze buttons throughout MainUI will still be able to generate charts on demand.

Rich,
I just wanted to run the persist files by you to verify they’re correct before I enter them:

rrd4j.persist

 Strategies {
     default = everyUpdate
 }
 Items {
    * : strategy = everyChange, everyMinute
 }

mapdb.persist

 Strategies {
  Items {
  * : strategy = restoreOnStartup
 }

I think that will work but I’m not openHAB so try it out and watch the logs for errors.

I missed a bracket in the mapdb.persist above. This is how my it looks now:

 Strategies {
 }
 Items {
    * : strategy = restoreOnStartup
    }

Both persist files loaded at startup with no problem. However, when I rebooted my DateTime items all were NULL. Also, not sure why but my things inbox dropped from a couple hundred to 28. Any ideas? .

You need to tell MapDB when to save as well. Probably everyChange is what you want.

Would that go on the same line as the restoreOnStartup? Should I have anything in the Strategies section?

Yes, the same line. See Persistence | openHAB

Thanks Rich. I rebooted and all my DateTime items were showing the correct dates, not NULL anymore.

Hmm. I didn’t set up an rrd4j.persist file, and I don’t appear to have any issues. However, I haven’t looked closely at a startup log, so I’m thinking that OH is probably restoring from one then the other.

I don’t have a ton of items, so I don’t think it affects my startup very much. I could see this causing a delay for others, but in theory the items should always just be updating to the same value.

Whatever the case, I’ll add the rrd4j.persist file later. :wink:

By default in OH 3 rrd4j will automatically save all supported Items and restoreOnStartup on those Items.

If you’ve configured MapDB to also save and restoreOnStartup all Items, then both will be restoring the Item states at startup. It’s not going to cause much of a load but if there were some sort of problem with one of them or there is a difference between the two databases, it is non-determinisitic which one restores the Item in what order. So it’s best to override the .persist file settings for rrd4j if you plan on using MapDB for restoreOnStartup.

1 Like

Has there been any discussion of making persistence strategies to be manageable in the UI in the future? It would be great if basic strategies for each installed service could be configured in the System settings, to further remove new users from having to do text configuration (not that persistence is difficult).

I don’t see anything along these lines in openhab-webui or openhab-core in GitHub, so I’m guessing not. If I were to submit a feature request, am I correct in thinking it belongs in webui?

1 Like

I know it’s planned but it’s a bigger effort than you might think as there is nothing built in the REST API nor the JSONDB to support it. openhab-core has a lot to do before webuis can do anything with it.

Gotcha. I suspected that it would be one of those “sounds easy, really isn’t” things. :wink:

A short-term solution might be for openHABian to include MapDB and have the persist files already in place. I’ll post it to GitHub for consideration as a “nice to have”. Certainly not crucial.