I have the state of my heating system as an Item (0 or 1)
I have a rule which triggers on:
Item Heating changed
I am trying to delay doing anything in the rule if the state has only just changed as I actually need a more complex rule than show below.
I am therefore inspecting the following
Heating.state
Heating.lastUpdate()
Heating.previousState().state
Cut down rule here:
rule "heating_state"
when
Item Heating changed
then
logInfo("heatingRule","Heating State: {}", Heating.state)
logInfo("heatingRule","Last heating change: {}", Heating.lastUpdate())
logInfo("heatingRule","Previous heating state: {}", Heating.previousState().state)
end
Logs show that sometimes the Heating.state matches Heating.previousState().state but sometimes it doesn’t and has the previous value, and sometimes lastUpdate() corresponds to the time the rule was triggered, and sometimes it is the previous change.
2017-12-08 20:45:11.113 [INFO ] [e.smarthome.model.script.heatingRule] - Heating State: 1
2017-12-08 20:45:11.115 [INFO ] [e.smarthome.model.script.heatingRule] - Last heating change: 2017-12-08T20:45:11.077Z
2017-12-08 20:45:11.118 [INFO ] [e.smarthome.model.script.heatingRule] - Previous heating state: 1.0
2017-12-08 20:45:25.480 [INFO ] [e.smarthome.model.script.heatingRule] - Heating State: 0
2017-12-08 20:45:25.482 [INFO ] [e.smarthome.model.script.heatingRule] - Last heating change: 2017-12-08T20:45:11.077Z
2017-12-08 20:45:25.484 [INFO ] [e.smarthome.model.script.heatingRule] - Previous heating state: 1.0
2017-12-08 20:45:39.546 [INFO ] [e.smarthome.model.script.heatingRule] - Heating State: 1
2017-12-08 20:45:39.548 [INFO ] [e.smarthome.model.script.heatingRule] - Last heating change: 2017-12-08T20:45:25.480Z
2017-12-08 20:45:39.551 [INFO ] [e.smarthome.model.script.heatingRule] - Previous heating state: 0.0
2017-12-08 20:45:53.388 [INFO ] [e.smarthome.model.script.heatingRule] - Heating State: 0
2017-12-08 20:45:53.390 [INFO ] [e.smarthome.model.script.heatingRule] - Last heating change: 2017-12-08T20:45:39.546Z
2017-12-08 20:45:53.393 [INFO ] [e.smarthome.model.script.heatingRule] - Previous heating state: 1.0