Get Zigbee linkquality last_updated for battery devices

I am trying to create a template within an automation that has a for loop that does the following:

Loop through all my zigbee battery operated devices and retrieve the timestamp of when the corresponding linkquality value was updated.

The reason for this is I want to know if/when one of these devices goes offline. I can’t use the battery’s last_updated value as this updates very irregularly/infrequently. However, linkquality is updated several time each day. In this way I can test to see if the device was heard recently.

I have the automation set up, and I have the template working to the point where I can get a list of my devices, and even the battery levels. I now need to be able to do something like:

{{ states.sensor.entity-id-of-device_linkquality.last_updated }}

I have been able to craft a string variable that has the exact string like the line above, but putting that variable between double braces doesn’t work.

Anyone know how I can do this? Or does anyone have an alternate solution for determining the offline status for zigbee battery devices?

Tnx
JP

Are you using ZHA, Zigbee2MQTT, or deCONZ/Phoscon?

I am using Z2M

z2m has a built in availability checker. If you enable it then devices seen as ‘offline’ appear as unavailable in the HA devices section:

image

image

1 Like

This is not the solution I am looking for. Although this may be a good visual indicator for mains connected devices that are off line, it does not work for battery connected devices. Also, I am looking for a templated solution that I can use in my automation. I use a for loop that scans all battery devices and then for each battery device I find, I want to know the last time this device communicated with HA.

Anyone else got any ideas?

My mistake, the offline indicator does work for battery devices. Sorry for the confusion. Now all I have to do is work the status into my template. Thanks for giving me a new direction to explore.

1 Like

For my setup I’ve gone with 3 hours for battery devices, which allows for two messages to be missed, but that may go down to 2 hours and a few minutes to allow for a single missed message.

For end devices 10 minutes is fine, though as all of mine check in at least every 2 to 3 minutes that may get dropped to 5 minutes.

Those feed into a template sensor and automation.

Thanks Tinkerer. I’ll steal some of your ideas and code and use it in my automation.

Thanks to all on this forum…it is GREAT!!!

1 Like