Expire binding and MapDB restore on startup


I have items holding sensors values that may expire to UNDEF thanks to the Expire binding if they are not updated often enough.

If the system is rebooted

  1. MapDB restores the latest “defined” value of the sensor, even if the value had expired to UNDEF before reboot
  2. This restored obsolete value won’t expire automatically until it is updated again during the new session. After an update is received, the Expire binding performs as expected.

In other words, I get the following behaviour:

  • a sensor stops working
  • the state of its associated item eventually gets reset to UNDEF by the Expire binding
  • the system is rebooted
  • MapDB restores the latest working sensor value
  • the sensor is still not working, but the old value is here to stay

I’m running the latest snapshot openHAB 2.2.0~20171008013406-1 (Build #1058) on openHABian, but I had already noticed this a week ago.

First, I would like to ask if this behaviour is expected or not. Of course I will be happy to provide more info if needed.

Thanks, Dominique

It is expected.

You can write a System started Rule and loop through all the Items with Expire binding and postUpdate their restoredState. Something like the following:

Assumes all the Items are members of gExpireReset

rule "Restart Expire Timers"
    System started
    Thread::sleep(100) // test without this first, it is probably only needed on slow machines, give 
                       // persistence a chance to finish restoreOnStart

    gExpireReset.members.filter[i|i.state != NULL].forEach[ i |  i.postUpdate(i.state) ]

Thanks Rich, it solves my issue - in a single line of code!

If I were to use another persistence service like InfluxDB to save the sensors data for charting, would it also save the UNDEF/NULL states? In that case I could use it instead of MapDB to restore the latest state at startup, and the previously UNDEF items would stay UNDEF. That would prevent glitches in the time series.

(I’ll try that tonight if I can)

Yes, Items come up with NULL as their state and one then get populated from restoreOnStartup with their previous values. That is independent of what persistence database you are using.

I recommend using MapDB if all you are using persistence for is restoreOnStartup because it only keeps the most recent value you never have to worry about running out of space. It is also faster (in my experience). You can keep InfluxDB as your default persistence.