Save and restore previous state


I would like to have a rule reacting to a presence detector. Light should be switched on and then restored to the previous state after a few minutes.
However, the state of the light might change in between due to other rules or manual switching.

I tried the following:

  • Global variables in the head of the rules
    var Number old_value = 0
    –> did not work, I think because variable state is not preserved after rule execution
  • Using previousState
    –> did not work well with intermediary changes of the light state due to other rules, …

Am I doing wrong? How would you handle that?


Incorrect. The value will be preserved until you reload that .rules file. If it didn’t work there was something else wrong with your implementation.

Show what you tried.