Hi
How can I make an automation/ trigger only when a sensor is not changing the (latest) value for a hour? So inactivity.
Thanks!
Hi
How can I make an automation/ trigger only when a sensor is not changing the (latest) value for a hour? So inactivity.
Thanks!
trigger:
- platform: state
entity_id: sensor.whatever
to:
for:
hours: 1
Then null to:
monitors all state changes but ignores attribute changes. If you are interested in attributes of the sensor not changing as well then leave that part out.
should I set the “to” to “unknown” status or “not available”? it seems that the state of an entity remains at the last value when I look at the history of the sensor.
You can monitor the value of the entity’s last_changed
property.
In the following example, if the value of the sensor’s last_changed
property hasn’t changed in over an hour, it sends a notification.
alias: example
trigger:
- platform: template
value_template: >
{{ now() - states.sensor.temperature.last_changed >= timedelta(hours=1) }}
action:
- service: notify.persistent_notification
data:
title: Stale Temperature
message: >
{{ now().timestamp() | timestamp_local }} Value unchanged for the past hour.
Another example, demonstrating how to periodically check multiple sensors.
No leave it empty. That way HA will trigger on any state that persists for an hour. It will ignore attribute changes.
If you delete the to: altogether then HA only triggers if the state and attributes have the same values for an hour.
Thank you both! I suppose both suggested solutions will accomplish the same?
I believe there’s a subtle difference that may or may not be important to you. The difference is how they initially behave upon implementation.
After implementing the version employing a State Trigger, it will require the entity to undergo at least one state-change before it can detect if that state-change becomes stale (i.e. remains unchanged for an hour or more).
After implementing the version employing a Template Trigger, it will immediately detect if the entity’s state is stale.