[SOLVED] Questions about Persistence behavior

Hi,

I have configured the persistence using a mysql DB.
Now I’ve noticed, if I restart openhab service (at least) one item starts as NULL and then switches to the correct value. The item itself is a String item that fetches its value via http binding.

  1. Is it expected it starts with NULL value, followed by a change to the correct value?
    I would have expected it starts with the value from the DB, then it updates the value via http binding.

I’d like to check if the String item contains a new / changed value. In this case a notification will be sent to my smartphone. As mentioned above, the item starts as NULL and thus my rule (when item changed) triggers.

  1. How can I avoid this?
    In the rule I use

if (MyStringitem.previousState == NULL)

Unfortunately this leads to an error message:

The name ‘NULL’ cannot be resolved to an item or type

Any help is highly appreciated.

Stefan

Yes. Every Item state starts with NULL and then gets updated either from the binding or the persistence ( restoreOnStartup if used on the item)

I am not 100% sure about the order… I think it is: NULL->restore->binding

try:

if (MyStringitem.previousState.state == NULL)
                              ^^^^^^

Ref: After openhabe 2.3 update, homematic binding don't update item status

Thanks, now it works.

I found out that the state NULL is NOT saved in the persistence and cannot be retrieved as previousstate.
What I did:

  1. restart openhab service, so items starts as NULL
  2. Then item changes to the real value
  3. My rule (item changed) triggers
  4. Output for MyStringitem.previousState().state.toString is: current value
  5. Output for MyStringitem.previousState(true).state.toString is: older value

As you see, neither 4 nor 5 are NULL. So all I need to do is check if 4. differs from MyStringitem.state

1 Like

Please mark the thread as solved, thanks

1 Like

very correct!
I was thinking about exactly this when posting but I was not sure (asking myself if persistence would ever store NULL…:stuck_out_tongue:)

1 Like