I used to use ZHA Toolkit to alert me when any of my ZHA devices went offline. This has worked fine, until a more recent HA release broke ZHA Toolkit, and its been playing catchup ever since.
So I thought I would investigate another way of doing this, which turns out to be pretty straight forward.
As a pre-requisite, you will need to enable the hidden LQI attribute of your zigbee devices that you want monitored.
Then simply use the script below. I’ve set mine on an hour timer, but you could trigger it how ever you want:
alias: ZHA and Wifi Offline Devices Check
description: ""
trigger:
- platform: time_pattern
hours: /1
condition:
- condition: template
value_template: >-
{{ states.sensor | selectattr('state', 'in', ['unavailable', 'none']) |
selectattr('entity_id', 'search', 'lqi') | rejectattr('name', 'search',
'Tradfri Switch') | list | count >0}}
action:
- action: notify.mobile_app_YOUR_PHONE_HERE
data:
title: Devices Offline
message: >-
{{ states.sensor | selectattr('state', 'in', ['unavailable', 'none']) |
selectattr('entity_id', 'search', 'lqi') | rejectattr('name', 'search',
'Tradfri Switch') | map(attribute='name') | list | join(', ')}}
mode: single
The condition check simply counts the number of devices in the offline state. I’ve also added an additional check:
rejectattr('name', 'search',
'Tradfri Switch')
to ignore any entities which have names including the words ‘Tradfri Switch’. This is because some of my devices present themselves as offline (when they are not, they are working fine) and I want to ignore these.