Hello, recently i noticed that when I moved a zwave motion/temperature sensor out of network range, the previous temperature stayed active in homeassisant for days and I had no way of knowing the sensor was out of range and that the temperature information was old. With mqtt sensors I know I can set ‘expire_after: xx’ is there any way to do something similar for z-wave sensors?
I’m using an automation that triggers every 5 minutes and sends a notification when the value has not changed for two hours.
- alias: notify_nexus_state_on
trigger:
- platform: time_pattern
minutes: '/5'
seconds: 02
condition:
- condition: template
value_template: >
{{ (as_timestamp(now())-as_timestamp(states.sensor.aussen_temp_nexus.last_updated))
> 7200 }}
action:
- service: do_something
...
The expire_after
option works like a watchdog timer. What’s that? It’s a timer that, under normal operation, is never allowed to expire. However, when things are abnormal, the watchdog timer does get a chance to run until expiration and then it raises an alarm of some sort.
For example, when you set expire_after
to 30 seconds, the moment the sensor’s value changes the watchdog timer starts. If the sensor’s value changes within the next 30 seconds, the timer is restarted. If the sensor’s value fails to change over the next 30 seconds, the timer is able to run until expiration and then sets the sensor’s value to unavailable
.
This ‘watchdog’ behavior can be easily replicated for other components (that don’t support an expire_after
option).
- Define a timer. Set its duration to represent when the sensor’s value has become ‘stale’ (30 seconds, 3 minutes, 3 hours, or whatever).
- Define an automation that runs when the timer expires. Have the automation send you a notification (or whatever you want to indicate the sensor’s value has gone stale)
- Define one more automation that triggers whenever the sensor’s value changes. Its action is to simply (re)start the timer.
Done. You now have a watchdog timer that will report when the sensor’s value has become stale.