I have a situation where 2 of my Xiaomi devices had dropped from the network and it took a day or so before I noticed the temperature was not changing anymore.
I see with the Zigbeenetwork map component that there is a last seen datetimestamp for each device in the network topology graph. Is there a way to check these times for all zigbee devices and if now - last_seen is over a certain amount of hours, raise a notification.
Sure, Iāve got this sensor for doing exactly that. Itās written for Z-Wave, but merging it with the logic from the follow template (for displaying the last seen time of my Zigbee2MQTT devices), should work:
{% for state in states.sensor -%}
{%- if state.attributes.linkquality %}
{%- if "linkquality" in state.name %}
{{ relative_time(state.last_updated) }} ago for {{ state.name | lower }}<BR>
{%- endif -%}
{%- endif -%}
{%- endfor %}
Iāve not, yet, extended the Z-Wave binary sensor to Zigbee, or made the notifications smarter, but this automation has the groundwork for a smarter notification.
No, for example the temp/hum sensors just keep their last transmitted value in HA. Perhaps if Z2M or HA is restarted that these values become āUnavailableā but nowadays I donāt have to reboot either a lot anymore.
Will have a look at your solution, meanwhile I wonder if using the relatively new Z2M config option
last_seen: 'disable'
# Optional: Add an elapsed attribute to MQTT messages, contains milliseconds since the previous msg (default: false)
could be used for this.
E.g. an automation triggering a script every 4 hours that checks all the last_seen timestamps and reports if a sensor hasnāt been seen for 2-3 or so hours.
I would like to get a notification when a device has not been seen for 1+ days. So somehow I would need to have an automation that checks letās say every few hours to see if the output of such a template contains ā1 day agoā for example and then fires a notification.
I was thinking of using timedelta first but HA doesnāt know about it it seems (when I tried in the Template tab).
You could just look to see if the state last updated 24 hours ago, in seconds:
{% for state in states.sensor -%}
{%- if (as_timestamp(now()) - as_timestamp(state.last_updated) > (24 * 60 * 60) ) %}
{{ state.name | lower }} was last seen {{ relative_time(state.last_updated) }} ago
{% endif -%}
{%- endfor %}
You could probably use it in the kind of template condition I have here to allow you to only fire the notification if thereās a problem.
Hey why did you pick last_updated and not last_seen? For instance, I unplugged a zigbee router a week ago. Last_seen is a week ago. Last_updated is 12 hours ago.
Ahah fair enough. I wanted to write it with last_seen but I am not able to use the relative time:
Last updated looks like 2020-11-05 05:25:22.336481+00:00
whereas last_seen looks like 2020-10-24 09:39:10
I tried using as_timestamp then timestamp_local but it still does not workā¦
Any clue please?