to address a connection loss to a Homematic server (CCU or Homegear) I want to identify an entity that has been unchanged for a given time. However, I cannot figure out an appropriate trigger for this.
In other words: How do I trigger an automation, if a sensor’s state has not changed for a given time? Would this work?
automation:
- alias: 'reconnect to homegear'
trigger:
platform: state
entity_id: sensor.my_temperature_sensor
for:
hours: 1
action:
service: homematic.reconnect
I think the issue is, that - in case of a lost connection - the sensor.my_temperature_sensor does not change at all. The template platform watches for changes on the identified entities in the value template and obviously now() is not taken into consideration.
I changed the automation now to trigger every 5 minutes, but only act on an actual connection loss.
Hi, i recently looked into this issue of identifying stale devices as well.
While there is a timestamp that indicates when an entity has last changed, this does not help the cause because the value may stay the same for a while (e.g. temperatures, lock state, etc.). You would need to have a timestamp that is updated every time a value is received /polled even when the value itself is the same.
Apparently there is no such timestamp. The only workaround for this is to set up the entities to update every time a value is received. This updates the timestamp but also the value itself even of it has not changed. Thus there are more logbook entries, more strain on the DB, useless time series values etc…
In my opinion this is a design flaw in the current implementation. If you integrate devices that communicate via RF, the detection whether a device has disappeared or is not sending info in the expected frequencies is essential for monitoring the health of such devices.
@jo-me While you are correct, the pattern still is applicable for my setup, as “my_temperature_sensor” is a device, that periodically sends a value, updating the last_updated value.
However, if no more data is received, because the gateway becomes unresponsive, the last_updates remains the same as well and that’s why my original trigger does not … trigger.
Just want to verify that now().timestamp() - states.sensor.my_temperature_sensor.last_updated returns a float/int. You may have to jog that syntax around a bit.
I think I need more than this. The sensor would stay “on” for some time after a re-connect, because the affected sensor sends periodically, not on demand