[SOLVED] MapDB persistence doesn't restore DateTime


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:

Items {
* : strategy = everyChange, restoreOnStartup

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:

“name”: “IgorSHandy_ZuletztGesehen”,
“datapoints”: “1”,
“data”: [
“time”: 1556252606905,
“state”: “2019-04-26T06:23:26.000+0200”

What I’m doing wrong?

Thank you,

?? You mean a DateTime type Item, linked to a binding channel?

MapDB should restore DateTime Items (works for me) … but a binding can immediately overwrite that.

Exactly. It’s a Network Binding - Network Device Thing, the item is linked to lastseen channel.

The last state was saved in MapDB.

But after the mobile device left the network and OH2 service has been restarted the value was not restored. The item has still an UNDEF state.

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.

Thank you.
I will investigate it. I have to learn more about how everything works. I’m just at the beginning.

Solved with rule using ‘System started’ trigger:

rule "initialize"
    System started
    createTimer(now.plusSeconds(60), [|
        if (<item>.state == UNDEF) {
            logInfo("initialize.rules", "<item> UNDEF --> " + <item>.previousState().state.toString)

Maybe is there a better trigger (e.g. after network binding starts).