Skip to content

Instantly share code, notes, and snippets.

@Geek-MD
Last active January 30, 2026 11:02
Show Gist options
  • Select an option

  • Save Geek-MD/e79ed1aec5f527cb2c11e223110e31d9 to your computer and use it in GitHub Desktop.

Select an option

Save Geek-MD/e79ed1aec5f527cb2c11e223110e31d9 to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Low Battery Notificator
blueprint:
name: Low Battery Notificator (Exclude List)
description: >
Notifies when any battery sensor drops below a threshold.
All battery sensors are monitored except those explicitly excluded.
domain: automation
author: Edison Montes @_GeekMD_
homeassistant:
min_version: 2024.6.0
input:
start_time:
name: Start Time
description: Start of the notification window.
default: '08:00:00'
selector:
time: {}
end_time:
name: End Time
description: End of the notification window.
default: '22:00:00'
selector:
time: {}
battery_level:
name: Battery Level Threshold
description: Notify when battery is below this percentage.
default: 20
selector:
number:
min: 0
max: 100
step: 1
unit_of_measurement: '%'
mode: slider
interval_minutes:
name: Execution Interval (Minutes)
description: Run every N minutes during the time window.
default: 30
selector:
number:
min: 1
max: 120
step: 1
unit_of_measurement: min
excluded_entities:
name: Excluded Entities
description: Battery sensors to exclude from monitoring.
default: []
selector:
entity:
multiple: true
domain: sensor
device_class: battery
enable_logging:
name: Enable Logging
description: Show a persistent notification every time low battery is detected.
default: false
selector:
boolean: {}
actions:
name: Actions
description: >
Actions to run when low battery is detected.
Use {{ low_battery_devices }} directly in your message.
selector:
action: {}
trigger:
- platform: time
at: !input start_time
- platform: time
at: !input end_time
- platform: homeassistant
event: start
- platform: template
value_template: >
{% set minutes = now().minute %}
{% set interval = interval_minutes | int %}
{{ (minutes % interval) == 0 }}
variables:
battery_level: !input battery_level
interval_minutes: !input interval_minutes
enable_logging: !input enable_logging
excluded_entities: !input excluded_entities
low_battery_devices: >
{% set threshold = battery_level | int %}
{% set out = namespace(lines=[]) %}
{% for s in states.sensor %}
{% if state_attr(s.entity_id, 'device_class') == 'battery'
and s.entity_id not in excluded_entities %}
{% set val = states(s.entity_id) %}
{% if val not in ['unknown', 'unavailable', 'none'] %}
{% set level = val | int(default=100) %}
{% if 0 <= level < threshold %}
{% set name = state_attr(s.entity_id, 'friendly_name') or s.entity_id %}
{% set out.lines = out.lines + [ name ~ ' (' ~ level ~ '%)' ] %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{{ out.lines | join('\n') }}
condition:
- condition: and
conditions:
- condition: time
after: !input start_time
before: !input end_time
- condition: template
value_template: "{{ low_battery_devices | length > 0 }}"
action:
- variables:
low_battery_devices: "{{ low_battery_devices }}"
- choose:
- conditions:
- "{{ low_battery_devices | length > 0 }}"
sequence:
- choose: []
default: !input actions
- service: logbook.log
data:
name: Low Battery Notificator
message: >
Executed at {{ now().strftime('%Y-%m-%d %H:%M:%S') }}.
Devices below {{ battery_level }}%:
{{ low_battery_devices }}
- conditions:
- "{{ low_battery_devices | length == 0 }}"
sequence:
- service: logbook.log
data:
name: Low Battery Notificator
message: >
Automation executed at {{ now().strftime('%Y-%m-%d %H:%M:%S') }}.
No devices below threshold — no action taken.
- choose:
- conditions:
- "{{ enable_logging }}"
sequence:
- service: persistent_notification.create
data:
title: "Low Battery Check Executed"
message: >
Execution time: {{ now().strftime('%Y-%m-%d %H:%M:%S') }}
Interval: every {{ interval_minutes }} minutes
{% if low_battery_devices | length > 0 %}
Devices below threshold:
{{ low_battery_devices }}
{% else %}
No devices with low battery.
{% endif %}
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment