I’m a OH2 beginner and started with OH 2.4.0 on linux x86_64.
I defined some items and now I will setup persistence service. I configured MapDB to save last state of all items and restore it on startup:
The MapDB persistent service is set as default persistence service. There is also JDBC (MariaDB) persistence configured to store some history data (like temperature).
Both persistence services are working fine. There are MapDB files in /var/lib/openhab2/persistence/mapdb written periodically and also MariaDB tables with values.
But the last state of the item is not restored on OH service startup.
I defined an item of type Network Binding. It’s my mobile device. I would like to restore the last seen value but after restart OH the value is empty. The value (DateTime) is stored in MapDB:
It’s not “still” has an UNDEF state.
Items get a NULL state at boot time.
Restore-on-startup will overwrite that with your stored timestamp.
Then the binding starts, has no memory of when your target was last online, and so (correctly) overwrites the Item state with UNDEF (meaning no idea).
You’ll need another method to protect your stored last-seen timestamp from the binding. Maybe a second, unbound, DateTime Item and a rule that triggers from the binding channel changing but ignores NULL/UNDEF states.
rule "initialize"
when
System started
then
createTimer(now.plusSeconds(60), [|
if (<item>.state == UNDEF) {
logInfo("initialize.rules", "<item> UNDEF --> " + <item>.previousState().state.toString)
<item>.sendCommand(<item>.previousState().state.toString)
}
])
Maybe is there a better trigger (e.g. after network binding starts).