Trying to get last non null value from persistance

Hello everyone,

I have some items connected to things that sometime return null. For exemple, it query my unifi controller for the mac of a client but after a while, this client disapear from my controller. Because of that, it doesn’t find it and return null. I have non null value of that mac saved into my persistance. Is there a way to get that value back to the item instead of the null? Or a way to retrieve it when firing a rule?

Thank you

There is a lastState property of a rule which stores the state of the Item it had prior to it’s current state. I don’t know what rules language you use so can’t tell you exactly how to use it, but if you look at the docs for your language of choice you will find it.

That’s the simplest way to get at the previous state of the Item. Otherwise, you can use persistence. As you notice, NULL doesn’t get saved. So the most recent state should be the previous state.

<item>.previousState(true) Gets the previous State of a persisted Item, skips Items with equal State values and searches the first Item with State not equal the current State (returns HistoricItem)

Ah great, that will help! Thank you!