2024-02-21 UPDATE
I consider this blueprint deprecated, please click here for an updated and improved version
the below information is retained for historical purposes only
Explanation
This blueprint will alert you when any of your Zigbee or Zwave battery powered devices have fallen off the network, aka gone “Unavailable”.
It is not necessary to specify a list of devices to check, as this template draws heavily from the excellent work of Sbyx, who came up with the idea of scanning all devices which have a class of “battery”.
What defines a device as “unavailable”? This is somewhat subjective with battery powered Zigbee devices - and differs depending on the manufacturer. If you haven’t heard from your Cousin Vinney in 3 weeks, that doesn’t mean he’s dead - it might just mean he has nothing to say…
Similarly, to preserve battery, many devices only report in very infrequently - But they should report immediately in case of an Event - such as a water leak, or a door closing.
If you are running ZHA (the default HA Zigbee Integration), you can customise what you consider to be “unavailable” in your HA settings. Go to Settings->Devices->Zigbee(ZHA), and click “Configure”. You should see a setting “consider battery powered devices unavailable after (seconds)
”. Personally, I set mine to 10800s
(3 hours).
If you are running DeConz or Z2M, the process for setting the timeout will be different, and out of the scope of this help document.
This blueprint will scan your network at a time of day of your choosing, and notify you of any devices that are Unavailable at that time.
Usage
Click this badge to install the blueprint:
You can specify sensors to exclude from the scan - be aware that selecting a device
doesn’t work, you must expand and choose the specific sensor Entities you wish to exclude.
You can choose any actions to be run if sensor(s) are offline, for example speaking a list via TTS, or sending a message to your phone. The following example shows how to provide a list of the offline sensors:
message: ‘The following devices are unavailable {{sensors}}’
Note: if you use Telegram, then change {{ sensors }}
to the following:
{{sensors|replace("_"," ")}}
Limitations & Notes
-
This blueprint does not check mains-powered devices, such as smart plugs. In practice, I rarely find these devices go offline.
-
This blueprint only checks your network once a day, so it’s possible your device may have been offline for a day, before you receive a notification.
-
This is my first ever blueprint, let me know if there are issues.
-
This works with the default HA Zigbee/ZWave integrations, but has not yet been tested with Zigbee2MQTT - would appreciate if someone can test and send feedback
-
Shoutout to @Sbyx
Changelog
- 2022-02-19 First version created
Blueprint raw Yaml
blueprint:
name: Zigbee/ZWave battery device has gone offline
description: Report when a Zigbee or ZWave, or any battery device has gone offline
#based on the work of Sybx @ https://community.home-assistant.io/t/low-battery-level-detection-notification-for-all-battery-sensors/258664
domain: automation
input:
time:
name: Time to test on
description: Test is run at configured time
default: '10:00:00'
selector:
time: {}
day:
name: Weekday to test on
description: 'Test is run at configured time either everyday (0) or on a given
weekday (1: Monday ... 7: Sunday)'
default: 0
selector:
number:
min: 0.0
max: 7.0
mode: slider
step: 1.0
exclude:
name: Excluded Sensors
description: Battery sensors (e.g. smartphone) to exclude from detection. Only entities are supported, devices must be expanded!
default: {entity_id: []}
selector:
target:
entity:
device_class: battery
actions:
name: Actions
description: Notifications or similar to be run. {{sensors}} is replaced with
the names of sensors being low on battery.
selector:
action: {}
source_url: https://gist.github.com/Tahutipai/971bf0e07e50ce6190e0dacd73262e2e
variables:
day: !input 'day'
exclude: !input 'exclude'
sensors: >-
{% set result = namespace(sensors=[]) %}
{% for state in states.sensor | selectattr('attributes.device_class', 'defined') | selectattr('attributes.device_class', '==', 'battery') %}
{% if "unavailable" in state | string and not state.entity_id in exclude.entity_id %}
{% set result.sensors = result.sensors + [state.name] %}
{% endif %}
{% endfor %}
{% for state in states.binary_sensor | selectattr('attributes.device_class', 'defined') | selectattr('attributes.device_class', '==', 'battery') %}
{% if "unavailable" in state | string and not state.entity_id in exclude.entity_id %}
{% set result.sensors = result.sensors + [state.name] %}
{% endif %}
{% endfor %}
{{result.sensors|join(', ')}}
trigger:
- platform: time
at: !input 'time'
condition:
- '{{ sensors != '''' and (day | int == 0 or day | int == now().isoweekday()) }}'
action:
- choose: []
default: !input 'actions'
mode: single
EDIT: Already getting feedback that people would prefer to be notified of mains-powered zigbee devices being offline as well. Which makes sense. I can’t find anyway in ZHA to get a list of all Zigbee devices. I guess one could just grab all entities that are “unavailable”, but that seems a little far reaching, albeit useful. I’m guessing most people just want to monitor their SmartSwitches? This is an assumption - so someone please tell me if its wrong
So I’ve added a test version of a blueprint that gets all battery devices, and ALL types of switches. This feels a little unclean designwise, but perhaps will work well in practice? I struggle to think of types of switches, other than physical SmartSwitches, that can go “unavailable”? If someone wishes to try that new blueprint, I would appreciate any feedback. Click below to install it: