My rule:
rule “Bathroom Temperature is lower than Target Temperature”
when
Item Bathroom_Temperature_tado received update
then
logInfo("Bathroom", "Temperature was changed, checking....")
logInfo("Bathroom", "Previous value was " + Bathroom_Temperature_tado.previousState(true).state)
logInfo("Bathroom", "Current value is " + Bathroom_Temperature_tado.state as Number)
end
The log file:
2019-03-28 10:48:36.648 [INFO ] [ipse.smarthome.model.script.Bathroom] - Temperature was changed, checking…
2019-03-28 10:48:36.701 [INFO ] [ipse.smarthome.model.script.Bathroom] - Previous value was 22.68
2019-03-28 10:48:36.702 [INFO ] [ipse.smarthome.model.script.Bathroom] - Current value is 22.68 °C
Log of two runs of the rule:
2019-03-28 10:46:06.211 [INFO ] [ipse.smarthome.model.script.Bathroom] - Nothing to do.
2019-03-28 10:46:06.212 [INFO ] [ipse.smarthome.model.script.Bathroom] - Previous value was 22.44
2019-03-28 10:46:06.213 [INFO ] [ipse.smarthome.model.script.Bathroom] - Current value is 22.44 °C
2019-03-28 10:46:36.322 [INFO ] [ipse.smarthome.model.script.Bathroom] - Temperature was changed, checking…
2019-03-28 10:46:36.324 [INFO ] [ipse.smarthome.model.script.Bathroom] - Nothing to do.
2019-03-28 10:46:36.325 [INFO ] [ipse.smarthome.model.script.Bathroom] - Previous value was 22.68
2019-03-28 10:46:36.326 [INFO ] [ipse.smarthome.model.script.Bathroom] - Current value is 22.68 °C
The linked thread solution was to use the implicit variable previouseState but in my case this does not solve it. I get the same values as before.
mapdb persistence will only keep the current state, not the previous state. If you want historic data, you’ll have to use another persistence service such as rrd4j, influxdb, mysql…