Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save corgan2222/6e624dd2d21910d3bb7caf5613b07b60 to your computer and use it in GitHub Desktop.
Save corgan2222/6e624dd2d21910d3bb7caf5613b07b60 to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Low battery level detection & notification for all battery sensors
blueprint:
name: Report offline zigbee/zwave/battery/smart plug devices with device exclusion
description: Works with Smart Plugs, ZWave, Zigbee etc (Works with ZHA & Z2M). Now supports excluding entire devices.
#By Tahutipai 2024-02-21, updated to include device exclusion
#Originally Based on the work of Sybx @ https://community.home-assistant.io/t/low-battery-level-detection-notification-for-all-battery-sensors/258664
#Note: This has been upgraded to report only the Device that is offline, not multiple individual sensors within one Device
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_entities:
name: Excluded Entities
description: Entities to exclude from detection. Specify entity IDs.
default: []
selector:
entity: {}
exclude_devices:
name: Excluded Devices
description: Devices to exclude from detection. Specify device IDs.
default: []
selector:
device: {}
actions:
name: Actions
description: Call your notification here. {{offline_devices}} will replaced with the name of any offline devices
selector:
action: {}
source_url: https://gist.github.com/Tahutipai/971bf0e07e50ce6190e0dacd73262e2e
variables:
day: !input 'day'
exclude_entities: !input 'exclude_entities'
exclude_devices: !input 'exclude_devices'
offline_devices: >-
{% set result = namespace(offline_devices=[]) %}
{% for entity in states %}
{% if entity.state == 'unavailable' %}
{% set dev_id = state_attr(entity.entity_id, 'device_id') %}
{% if dev_id and dev_id not in exclude_devices and entity.entity_id not in exclude_entities %}
{% set device_name = device_attr(dev_id, 'name') %}
{% if device_name and device_name not in result.offline_devices %}
{% set result.offline_devices = result.offline_devices + [device_name] %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{{ result.offline_devices | join(', ') }}
trigger:
- platform: time
at: !input 'time'
condition:
- condition: template
value_template: "{{ offline_devices != '' and (day | int == 0 or day | int == now().isoweekday()) }}"
action:
- choose: []
default: !input 'actions'
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment