Using a group to persist values

Using the below mapdb.persist code, shouldn’t the variables I assign to the group RestoreOnStartup group persist automatically? These values were not seeming to be stored until I added a restoreonstartup.rules file.

Am I missing something, or do I have to use the .persist method to force each individual variable to store it current value?

mapdb.persist

Strategies {
    everyHour : "0 0 * * * ?"
    everyDay  : "0 0 0 * * ?"

    // if no strategy is specified for an item entry below, the default list will be used
    default = everyChange
}

Items {        
    RestoreOnStartup* : strategy = everyChange, restoreOnStartup
}

restoreonstartup.rules

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

rule "Persist on change: BackyardBluetoothState"
when
	Item BackyardBluetoothState changed
then
	BackyardBluetoothState.persist
end

rule "Persist on change: AtHome_Brian"
when
	Item AtHome_Brian changed
then
	AtHome_Brian.persist
end

default.items

Group	Backyard
Group	Harmony
Group	RestoreOnStartup

Switch AtHome_Brian "Brian" <present> (RestoreOnStartup)
Switch AtHome_Nerene "Nerene" <present> (RestoreOnStartup)
String BackyardBluetoothState "Backyard Bluetooth [%s]" <bluetooth> (RestoreOnStartup, Harmony, Backyard)

P.S. I am using the refresh.rules methodology described on the Persistence wiki to restore persistent values at startup.

1 Like

Your restoreonstartup.rules file should not be needed. The following ought to work:

Strategies {
  default = everyChange
}
Items {
  RestoreOnStartup* : strategy = everyChange, restoreOnStartup
}

You might want to rename your group so it’s not so similar to the special restoreOnStartup strategy.

1 Like

That’s a good point. I will experiment. Thank you.

The solution seems to be adding an everyMinute strategy to my mapdb.persist. I don’t understand why, but works now. Here is my final mapdb.persist

Strategies {
    everyMinute : "0 * * * * ?"
    everyHour   : "0 0 * * * ?"
    everyDay    : "0 0 0 * * ?"

    default = everyChange
}
Items {
    PersistentValues* : strategy = everyChange, restoreOnStartup
}
1 Like