Dear all,
I don’t know how to do something.
I have an item with a value defined at each starting with sendCommand(item,value), i would like to change this value and keep it in the case where I re-start openhab.
What is the best way to have a value not null, and to have the possibility to change this value and save it for the next start of openhab.
Thanks
Yann
Hello YannF,
what you’re describing is persistence.
This is described pretty detailled here:
https://docs.openhab.org/configuration/persistence.html#restoring-item-states-on-restart
You will need to set up some sort of a Database on your system and then define what values you would like to store.
This will also enable you to set it up to restore the values from this database on restart.
Personally I use an influxdb on Docker. This seems to work without problems since a few months now.
You need to use persistence
Install the mapdb persistence service in the paperUI
The mapdb persistence is included in openHAB and is recommended for this use of restoreOnStartup
addons>persistence>mapdb install
A file called mapdb.persist should be created in you conf/persistence folder
Edit the file to:
// mapdb persistence
Strategies {
default = everyChange
}
Items {
item : strategy = everyChange, restoreOnStartup
}
PS on a side note, when the item is known use the sendCommand
method instead of the action: item.sendCommand(value)
See: https://www.openhab.org/docs/configuration/rules-dsl.html#myitem-sendcommand-new-state-versus-sendcommand-myitem-new-state
Thanks to all
I will try it this afternoon or next week, I will update this topic when it works.
If you get stuck send message will help you on this no worries
It’s only a 10min job and needed for dealing with system restarts
-
Go to paper ui
-
Install mapdb under persistence
addons>persistence>mapdb install
-
Still in paperui change default persistence to mapdb under settings persistence
-
Create the text file linked above and save in OH persistence folder it has too be called mapdb.persist
// mapdb persistence
Strategies {
default = everyChange
}
Items {
item : strategy = everyChange, restoreOnStartup
}
Done
You can change the loglevel too see if its working or check OH PERSISTENCE folders for new files being created
@vzorglub I used parts of your post and re worded