This isn’t really related to ZWave I think - you are trying to restore historical data, so you should look at the persistence system are you using to store the data as I suspect that is not working properly?
I don’t use anything special to save data, I want to get the data that is provided by the Zwave Protocol - the previous value and the update time. I can’t do this with one command?
Before working with OpenHAB (started a week ago) I have worked with products like z-way-server from z wave.me and Fibaro HC2/3 (lua programming). They have API access for a large amount of data , including previous values. That’s why I thought it is available to everyone
In the settings set to use the default rrd4j. as I understand, saving to the database occurs when the values change. However, in the rule:
rule “MotionAlarm_MS1”
when
Item ZWaveNode006FGMS001MotionSensor_MotionAlarm changed
then
logInfo(“MotionAlarm1”, "Sensor from " + ZWaveNode006FGMS001MotionSensor_MotionAlarm.previousState().state + " to " + ZWaveNode006FGMS001MotionSensor_MotionAlarm.state.toString)
end
But the result is
2020-08-19 09:18:50.824 [vent.ItemStateChangedEvent] - ZWaveNode006FGMS001MotionSensor_MotionAlarm changed from OFF to ON
==> /var/log/openhab2/openhab.log <==
2020-08-19 09:18:51.053 [INFO ] [.smarthome.model.script.MotionAlarm1] – Sensor from ON to ON
Don’t forget all this openHAB processing stuff is multi-threaded.
If you start a rule on Item change … And you save to a database on Item change …
Would you like to guess what the most recent state is that the rule will read back from the database?
It’s a race condition.
I would suggest taking a step back though.
You’ve chosen rrd4j, which has special characteristics. In particular, because of its time-based compression, it is rare that anyone would use it with anything other than an everyMinute strategy.
It’s good for some purposes, other databases are better at other things, so it depends what you need. You can have more than one persistence service.
openHABs event bus provide a previousState with a change event without using persistence. This is available in rules as an implicit variable. But only for changes.
rule “MotionAlarm_MS1”
when
Item ZWaveNode006FGMS001MotionSensor_MotionAlarm changed
then
logInfo(“MotionAlarm1”, "Sensor from " + previousState.toString + " to " + ZWaveNode006FGMS001MotionSensor_MotionAlarm.state.toString)
end
There is no timestamping information available with that, though.