Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save robertbeal/5b1d051dd095dc7258c89ee0b196e220 to your computer and use it in GitHub Desktop.
Save robertbeal/5b1d051dd095dc7258c89ee0b196e220 to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Low battery level detection & notification for all battery sensors
blueprint:
name: Offline Devices Notifier
description: Notifies for switches, sensors, and binary sensors
#By Tahutipai 2024-02-21
#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: Select what time to run the check
default: '10:00:00'
selector:
time: {}
day:
name: Day to run the check on
description: Select when to run the check
default: "0"
selector:
select:
options:
- label: "Monday"
value: "0"
- label: "Tuesday"
value: "1"
- label: "Wednesday"
value: "2"
- label: "Thursday"
value: "3"
- label: "Friday"
value: "4"
- label: "Saturday"
value: "5"
- label: "Sunday"
value: "6"
exclude:
name: Exclusions
description: Select what to exclude from the check
default: []
selector:
target: {}
actions:
name: Actions
description: Action your notification. {{offline_devices}} will replaced with the name of any offline devices
selector:
action: {}
source_url: https://gist.github.com/robertbeal/5b1d051dd095dc7258c89ee0b196e220
variables:
day: !input 'day'
exclude: !input 'exclude'
offline_devices: >-
{% set result = namespace(offline_devices=[]) %}
{% set domains = ['sensor', 'binary_sensor', 'switch'] %}
{% set excluded_entities = exclude | selectattr('entity_id', 'defined') | map(attribute='entity_id') | list %}
{% set excluded_devices = exclude | selectattr('device_id', 'defined') | map(attribute='device_id') | list %}
{% set excluded_areas = exclude | selectattr('area_id', 'defined') | map(attribute='area_id') | list %}
{% set excluded_labels = exclude.label_id | default([]) %}
{% for domain in domains %}
{% for entity in states[domain] | selectattr('state', 'eq', 'unavailable') %}
{% set device_id = device_id(entity.entity_id) %}
{% set device_name = device_attr(device_id, "name") %}
{% set device_area = area_id(device_id) %}
{% if
entity.entity_id not in excluded_entities and
device_id not in excluded_devices and
device_area not in excluded_areas and
device_name not in excluded_labels
%}
{% set result.offline_devices = result.offline_devices + [entity.entity_id] %}
{% endif %}
{% endfor %}
{% endfor %}
{{result.offline_devices|sort|unique|join('\n')}}
trigger:
- platform: time
at: !input 'time'
condition:
- '{{ 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