RestoreOnStartup does not restore NULL value

Hi,

Im using OH3 and MapDB with the following strategy:


Strategies {
default = everyChange
}
Items {

  • : strategy = everyChange, restoreOnStartup
    }

Unfortunately NULL values are not restored, but only the value before the item changed to NULL. I need the NULL value to be restored - is it possible?

Best regards,
Michael.

I can’t think of a valid use case for this … NULL means unset, uninitialized.
So when an item already has a value you shouldn’t be setting it to NULL, and if you don’t noone will because it is already initialized. If you use NULL to signal some special state, that’s sorta misuse. Consider switching to use UNDEF instead.

Thanks, I changed to UNDEF, but the value is still not restored on startup.

I don’t understand. Either restoration does not work at all (if so you incorrectly described your issue), or the value that was persisted last will be restored (which is exactly the purpose of this).
So what “value” is not restored ?

Hi,

It is the value UNDEF that is not restored. Other values are restored as expected.

I use a DateTime Item to create a “OpenHab-restart-resistant-timer”, and would like to use the value UNDEF if the timer is turned off. But if I restart OpenHab then the value before UNDEF is restored instead of UNDEF. I guess MapDB can’t handle the value UNDEF and skip it?

Best regards,
Michael.

Quite right too. UNDEF signifies undefined, incalculable, not possible to store in a database, so not possible to restore either.
This is all working as designed - NULL and UNDEF are not persisted and so cannot be restored.

You will have to think of another means to signal your timer is inactive or whatever it is.

Thanks.

I now use a String to store the timer value. If the string is empty the timer is inactive. It is working just perfect :slight_smile:

Best regards,
Michael.

1 Like