No previous and last update data from Zwave device

When i try to get previous state and last update data from Zwave device - i get null values.

logInfo(“MotionAlarm1”, "temp now-> " + ZWaveNode006FGMS001MotionSensor_SensorTemperature.state.toString)

logInfo("MotionAlarm1", "temp prev-> " + ZWaveNode006FGMS001MotionSensor_SensorTemperature.previousState().toString())

logInfo("MotionAlarm1", "temp lastUpdate-> " + ZWaveNode006FGMS001MotionSensor_SensorTemperature.lastUpdate)

temp now-> 26.3 °C
temp prev-> null
temp lastUpdate-> null

What am I doing wrong?

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?

1 Like

OpenHAB to remain flexible has many persistence options so it does not have any configured by default. The options all have strengths and weak.

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?

The Z-Wave protocol does not provide historical information. Where do you see they say they do provide it?

1 Like

These are using Persistence Extensions. Do you have a Persistence Service setup?

Before working with OpenHAB (started a week ago) I have worked with products like z-way-server from z 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

I setup persistence rrd4j. I need to get data on the previous state and the maximum value for the time period, as well as their timestamps. Settings:

// Strategy name
// | Seconds
// | | Minutes
// | | | Hours
// | | | | Day of month
// | | | | | Month
// | | | | | | Day of week
// | | | | | | | Year
every5sec : “0/5 * * * * ?”
every15sec : “0/15 * * * * ?”
everyMinute : “0 * * * * ?”
every30min : “0 30 * * * ?”
everyHour : “0 0 * * * ?”
everyDay : “0 0 0 * * ?”
default = everyChange

Items {
* : strategy = everyChange, restoreOnStartup

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”
Item ZWaveNode006FGMS001MotionSensor_MotionAlarm changed
logInfo(“MotionAlarm1”, "Sensor from " + ZWaveNode006FGMS001MotionSensor_MotionAlarm.previousState().state + " to " + ZWaveNode006FGMS001MotionSensor_MotionAlarm.state.toString)


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

OpenHAB also has this - this is the persistence system that is referred to above. It is not a function of the ZWave system itself.


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”
   Item ZWaveNode006FGMS001MotionSensor_MotionAlarm changed
   logInfo(“MotionAlarm1”, "Sensor from " + previousState.toString + " to " + ZWaveNode006FGMS001MotionSensor_MotionAlarm.state.toString)

There is no timestamping information available with that, though.

1 Like

Thanks for your reply! Yes, it is working! I will try to setup and use InfluxDB for values timestamping

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.