I use a lot of virtual Items for controlling logic, and there’s no good reason to persist them; I’m not interesting in viewing their historical state.
The internals of restoreOnStartup aren’t clear; here’s one possibility:
Some kind of cached state could be created for any Item not defined in a strategy when the system gets a shutdown/reboot command, then
Items’ states are restored from this cache once the system boots up
The benefits of this approach would be (1) cutting down on storage requirements, and (2) ensuring that the restored state most closely matches the state of all items whenever the openHAB service stopped.
It’s also possible that the persistence service could just
Dumbly pull the Item state with the most recent timestamp from the database, which–in cases where Item strategies were defined as everyDay, everyWeek, etc.–could be completely inaccurate.
As far as I understand it, the restoreOnStartup will simply pull the last saved value from the selected persistence service; from what time point the last value is will clearly depend on your persistence strategy; if once a month…the value can be rather old.
A simply way of just persisting all numerical items and get your system back up again in case you need to update/restart is using mapDB with everyChange and use mapDB as the database from which you restore values (you can have several persistence services). MapDB stores only the most recent value (no historical data here), but is easy, quick and relatively fast; one caveat: mapDB only supports numerical values and cannot store strings or other non-numerical values.
Another way to look at this, if you do not want to restore the latest state/change, why use restoreOnStartup at all? You may have reasons, but whichever persistence service you use, it can only serve the last stored value.
That’s exactly what I was looking for. I’m using MySQL for persistence (just because I’m familiar with it), and I didn’t realize there might be an easier way of storing only the most recent value, which is totally fine with me; I just didn’t want to clutter storage with a million useless state changes.
Thanks for the answer! I’ll get it figured out from here.
Use mapdb to persist all your switches and virtual items
Use mySQL for the numerical like temperatures, etc… where it maybe useful to get history this way you won’t inflate your mySQL database with data that you won’t use.
mapdb only save the last state and so never inflates.
That’s exactly what I’m in the process of doing, actually! I didn’t realize I could use multiple persistence engines, and didn’t realize that I could specify in my rules which to use, or that mapdb does exactly what I needed.
Thanks to you and @lipp_markus for pointing me in the right direction. And if any future readers stumble across this, this post has enough to get you started.
I did the same a while ago and I had to think long and hard about which items I wanted to persist for some time. Does it acually add value to my automation? Will I ever look at this data? Will it be of some use in the future?..
Once I made my decisions, I create persistence groups and put them in the strategies of the persistence files.
Glad to have that confirmed. I didn’t encounter that restriction in the mapDB binding documentation, and the logs showed strings actively being stored.