Problem with previousState

Continuing the discussion from Problem with previousState:

Hi,

I’m facing another situation with ‘.previousState()’.

The issue is with the TRADFRI lights, since they are initialized after persistence kicks in on system reboot.

I’m able to get this value from influxdb, but as @rlkoshak mentioned it is the same state as current once reload is finished. This is, of course, due to fact that state is changed from UNDF to “Current state” which triggers new persistence record to be added to DB.

It is well known problem that TRADFRI lights go to ON state after power loss, and in this situation when system is rebooted, previous state of TRADFRI items is ON as well.

For this reason I would need to return not previous state but one before. Using previousState(true) approach would get good result only in this situation, but let’s say that I deliberately rebooted OH server and I have couple of light ON. In this situation I would get “mirror image”, so all lights that were ON would go OFF and via versa.

The persist rule is set to

“* : strategy = everyChange, restoreOnStartup”

So the question is how to get “previousState(+1)” because it would work in both cases.

Any help would be appreciated.