First post here so be kind
I think im missing something vital that is causing my problems and im sure someone here can help me
I run Openhab2.2 off a RPi and everything is working perfect except for checking item previous states in rules…
On an item changed event im checking the previous state of the item to determin if it has changed.
val String filename = "presence.rules"
rule "Jonas Phone"
when Item JonasPhone changed
logInfo(filename, "JonasPhone New State: "+JonasPhone.state+" Old State: " + JonasPhone.previousState.state )
This in my head should print the new value and the last persisted value, but it seems like the persistence service is too fast? And im always returning the current value.
2018-02-25 09:39:34.561 [vent.ItemStateChangedEvent] - JonasPhone changed from OFF to ON 2018-02-25 09:39:34.601 [INFO ] [marthome.model.script.presence.rules] - JonasPhone New State: ON Old State: ON
I have tried using both influxdb and rrd4j as persistence service but they both give the same symptom.
I changed to what you mentioned, unfortunately no change. This is my rr4d4j.persist
// persistence strategies have a name and a definition and are referred to in the "Items" section
// for rrd charts, we need a cron strategy
everyMinute : "0 * * * * ?"
//DemoSwitch, NoOfLights, Window_GF_Toilet, Heating* : strategy = everyChange, everyMinute, restoreOnStartup
JonasPhone, AnnelisPhone : strategy = everyChange
// let's only store temperature values in rrd
//Temperature*, Weather_Chart* : strategy = everyMinute, restoreOnStartup
// vim: syntax=Xtend
Im running the network binding to discover devices availabiliy, so there is one more line in the logs where the responsetime changed to UNDEF.
2018-02-25 11:10:35.485 [vent.ItemStateChangedEvent] - JonasPhone changed from OFF to ON
2018-02-25 11:10:35.490 [vent.ItemStateChangedEvent] - JonasPhoneResponseTime changed from UNDEF to 0.0
2018-02-25 11:10:35.526 [INFO ] [marthome.model.script.presence.rules] - JonasPhone New State: ON Old State: ON
I have weird issues with persistance. Can you try sleeping your rule for 1 min and then log? Mine seems to work only if I’m not too quick. Also I read somewhere you need everyminute with rrd4j I was thinking that the every change isn’t working right.
I think there is no persistence necessary for the previous state. It’s available as variable when the trigger indicates a status change. So not for received command as there the status change has not been processed. But for your rule it should work like that.
rule "Test previousState"
Item TestPreviousState changed
logInfo("Test previousState", "Item:\"" + triggeringItem.name + "\" state:\"" + triggeringItem.state + "\" previousState:\"" + previousState + "\"" )