Last active
February 12, 2025 16:42
-
-
Save Geek-MD/e79ed1aec5f527cb2c11e223110e31d9 to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Low Battery Notificator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Low Battery Notificator | |
description: Trigger actions when a device's battery level falls below a defined threshold, but only within a specific time range. | |
domain: automation | |
author: Edison Montes @_GeekMD_ | |
homeassistant: | |
min_version: 2024.6.0 | |
input: | |
battery_level: | |
name: Battery Level Threshold | |
description: The battery percentage below which the notification will be triggered. | |
default: 10 | |
selector: | |
number: | |
min: 1 | |
max: 100 | |
unit_of_measurement: "%" | |
start_time: | |
name: Start Time | |
description: The time from which the automation is allowed to trigger. | |
default: "08:00:00" | |
selector: | |
time: {} | |
end_time: | |
name: End Time | |
description: The time until which the automation is allowed to trigger. | |
default: "22:00:00" | |
selector: | |
time: {} | |
excluded_devices: | |
name: Excluded Devices | |
description: Devices that should be ignored when checking battery levels. | |
default: [] | |
selector: | |
entity: | |
multiple: true | |
domain: sensor | |
device_class: battery | |
actions: | |
name: Actions | |
description: Actions to be executed when a device's battery level is below the threshold. Use {{ low_battery_devices }} in messages to include the names of affected devices. | |
selector: | |
action: {} | |
variables: | |
battery_sensors: > | |
{{ states.sensor | selectattr('attributes.device_class', 'defined') | |
| selectattr('attributes.device_class', 'eq', 'battery') | |
| map(attribute='entity_id') | list }} | |
excluded_devices: !input excluded_devices | |
low_battery_devices: > | |
{% set min_level = battery_level | int %} | |
{% set devices = states.sensor | |
| selectattr('attributes.device_class', 'defined') | |
| selectattr('attributes.device_class', 'eq', 'battery') | |
| selectattr('state', 'match', '^\d+$') | |
| map(attribute='entity_id') | |
| reject('in', excluded_devices) | |
| map('states', 'int') | |
| select('lt', min_level) | |
| list %} | |
{% set device_names = devices | map('device_attr', 'friendly_name') | list %} | |
{{ device_names if device_names else [] }} | |
trigger: | |
- platform: state | |
entity_id: !input excluded_devices | |
to: '\d+' | |
condition: | |
- condition: template | |
value_template: "{{ low_battery_devices | length > 0 }}" | |
- condition: time | |
after: !input start_time | |
before: !input end_time | |
action: | |
- sequence: !input actions | |
mode: single |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment