Does restoreOnStartup require an everyChange/everyUpdate strategy

The docs aren’t particularly clear on this, but do I have to define a time-based storage strategy in order to use restoreOnStartup? That is, will

Items {
    someItem/someGroup*:   stategy = restoreOnStartup

work? Or do I have to define a strategy with:

Items {
    someItem/someGroup*:    strategy = every###, restoreOnStartup

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.

1 Like

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.

1 Like

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.

Good luck

1 Like

You are thinking of rrd4j. MapDB stores all item types.

1 Like

Glad to have that confirmed. I didn’t encounter that restriction in the mapDB binding documentation, and the logs showed strings actively being stored.

Hi Vincent, can you please help me create this " persistence groups"

i am at the point that i don’t really need all items restored…
i dont see it in the docs , maybe we can add this…

Yes, what do you need persisted?

i want to exclude my MQTT for exmple (all items start with MQTT%%%% exmaple MQTTPcLight)
its making my lights go off and on when i reboot

I have group called Restore for all the items I want restored.
Simple as that

i never used groups before so if you can please tell me if i am doing it right

my current settings is the below
lets say i will create a group for all items i want to be restored

so i will put (restore)
next, to every item i want in that group but what will be the settings for the

Strategies {
Items {
*: strategy = everyChange, restoreOnStartup


Group gRestore //for Items to restore on startup (mapdb)
Switch YourSwitch <poweroutlet> (gRestore) { channel="yxyxyxyyx" }
...//more items


Strategies {
everyMinute	: "0 * * * * ?"
everyDay        : "0 0 0 * * ?"
default = everyChange
Items { 
gRestore* : strategy = everyChange, restoreOnStartup

See also:


Thanks @sihui


Thank you both !!! :slight_smile: