Skip to content

Instantly share code, notes, and snippets.

@Geek-MD
Last active July 4, 2025 23:46
Show Gist options
  • Save Geek-MD/e79ed1aec5f527cb2c11e223110e31d9 to your computer and use it in GitHub Desktop.
Save Geek-MD/e79ed1aec5f527cb2c11e223110e31d9 to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Low Battery Notificator
blueprint:
name: Low Battery Notificator
description: Notifies when any battery sensor drops below a defined threshold, excluding selected devices. Executes periodically and at defined times, with optional logging.
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_devices:
name: Excluded Devices
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_list | join('\n') }}` in your message to list devices.
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_devices: !input excluded_devices
excluded_ids: "{{ excluded_devices | map(attribute='entity_id') | list }}"
low_battery_devices: >
{% set umbral = battery_level | int %}
{% set baterias_bajas = namespace(lista=[]) %}
{% for entidad in states.sensor
if entidad.attributes.device_class == 'battery' and entidad.entity_id not in excluded_ids %}
{% set estado = entidad.state %}
{% set nivel = estado | int(default=100) %}
{% if estado not in ['unknown', 'unavailable', 'none']
and nivel >= 0
and nivel < umbral %}
{% set nombre = entidad.attributes.friendly_name %}
{% set linea = nombre ~ ' (' ~ nivel ~ '%)' %}
{% set baterias_bajas.lista = baterias_bajas.lista + [linea] %}
{% endif %}
{% endfor %}
{{ baterias_bajas.lista }}
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_list: "{{ 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 | length }}
- 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
Devices below threshold: {{ low_battery_devices | length }}
{% if low_battery_devices | length > 0 %}
{{ low_battery_devices | join('\n') }}
{% 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