Created
April 27, 2025 02:53
-
-
Save ShadowBelmolve/87fd5ed62f9667ab04741a3aa2f046f4 to your computer and use it in GitHub Desktop.
Basic battery level alert blueprint for Home Assistant
This file contains hidden or 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/High Battery Notification (v0.1) | |
| description: | | |
| A basic blueprint to alert when a battery needs to be charged or stopped from charging. | |
| It can send the notification and remove it when outside of the alert zones. | |
| Use the extra/pre-condition actions to add/change some variables and change when the actions are called. e.g.: | |
| ```yaml | |
| variables: | |
| ring_emergency: >- | |
| {{ | |
| (not is_charging and battery_level_value <= 10) or | |
| (is_charging and battery_level_value >= 90) | |
| }} | |
| ring_warning: >- | |
| {{ | |
| ( | |
| (not is_charging and battery_level_value <= 20) or | |
| (is_charging and battery_level_value >= 86 ) | |
| ) and | |
| (battery_level_value % 2) | round(0, 'floor') == 0 | |
| }} | |
| should_ring: "{{ring_emergency or ring_warning}}" | |
| device_ring: "{{ 'On' if should_ring }}" | |
| is_adding_notification: "{{ should_have_notification or should_ring }}" | |
| ``` | |
| This will force an add notification in some cases where it normally won't to force the ring sound. | |
| These are the available variables: | |
| ```yaml | |
| variables: | |
| # get battery of present and past | |
| battery_level_entity: !input level | |
| battery_level_value: "{{states(battery_level_entity)}}" | |
| battery_level_value_changed: "{{ trigger.id == 'battery_level_changed' }}" | |
| battery_level_value_was: "{{trigger.from_state.state | float if battery_level_value_changed else battery_level_value}}" | |
| # get charging of present and past | |
| charging_entity: !input charging | |
| is_charging: "{{ is_state(charging_entity, 'on') }}" | |
| charging_changed: "{{trigger.id == 'charging_changed'}}" | |
| was_charging: "{{ trigger.from_state.state == 'on' if charging_changed else is_charging }}" | |
| # battery values | |
| low_battery_value: !input low_battery | |
| high_battery_value: !input high_battery | |
| # battery ranges of past and present | |
| is_battery_low: "{{ battery_level_value <= low_battery_value }}" | |
| was_battery_low: "{{ battery_level_value_was <= low_battery_value }}" | |
| is_battery_high: "{{ battery_level_value >= high_battery_value }}" | |
| was_battery_high: "{{ battery_level_value_was >= high_battery_value }}" | |
| is_battery_ok: "{{not is_battery_low and not is_battery_high}}" | |
| was_battery_ok: "{{not was_battery_low and not was_battery_high}}" | |
| # notification of present | |
| should_have_low_battery_notification: "{{ is_battery_low and not is_charging }}" | |
| should_have_high_battery_notification: "{{ is_battery_high and is_charging }}" | |
| should_have_notification: "{{ should_have_low_battery_notification or should_have_high_battery_notification }}" | |
| # notification of past | |
| should_have_had_low_battery_notification: "{{ was_battery_low and not was_charging }}" | |
| should_have_had_high_battery_notification: "{{ was_battery_high and was_charging }}" | |
| should_have_had_notification: "{{ (was_battery_low and not was_charging) or (was_battery_high and was_charging) }}" | |
| # action decision | |
| is_removing_notification: "{{ should_have_had_notification and not should_have_notification }}" | |
| is_adding_notification: "{{ not should_have_had_notification and should_have_notification }}" | |
| ``` | |
| domain: automation | |
| author: "Renan Tomal Fernandes <renan@kauamanga.com.br>" | |
| homeassistant: | |
| min_version: "2024.6.0" | |
| input: | |
| sensors_section: | |
| name: Battery sensors | |
| description: Some battery sensors | |
| input: | |
| level: | |
| name: Battery level | |
| description: Numeric sensor of the battery level | |
| selector: | |
| entity: | |
| filter: | |
| - domain: sensor | |
| device_class: battery | |
| - domain: input_number | |
| charging: | |
| name: Charging sensor | |
| description: Binary sensor to detect if it is charging | |
| selector: | |
| entity: | |
| filter: | |
| - domain: binary_sensor | |
| - domain: input_boolean | |
| battery_section: | |
| name: Battery | |
| description: Set some configuration for battery | |
| input: | |
| low_battery: | |
| name: Low battery level | |
| description: How low the battery needs to fall to start the alerts? | |
| default: 30 | |
| selector: | |
| number: | |
| min: 1 | |
| max: 99 | |
| step: 1 | |
| unit_of_measurement: "%" | |
| mode: slider | |
| high_battery: | |
| name: High battery level | |
| description: How high the battery needs to go to start the alerts? | |
| default: 80 | |
| selector: | |
| number: | |
| min: 2 | |
| max: 100 | |
| step: 1 | |
| unit_of_measurement: "%" | |
| mode: slider | |
| extra_section: | |
| name: Extras | |
| description: Extra logic(optional) | |
| collapsed: true | |
| input: | |
| mode: | |
| name: Automation mode | |
| description: Which mode should the automation run on? | |
| default: queued | |
| selector: | |
| select: | |
| mode: dropdown | |
| options: | |
| - single | |
| - restart | |
| - queued | |
| - parallel | |
| extra_triggers: | |
| name: Triggers | |
| description: React to extra triggers | |
| default: null | |
| selector: | |
| trigger: {} | |
| pre_conditions_actions: | |
| name: Pre-conditions | |
| description: Run some actions before the conditions. Perfect for setting some variables | |
| default: null | |
| selector: | |
| action: | |
| default_actions: | |
| name: Actions | |
| description: Add default actions for when none of the actions match(see the conditions sections) | |
| default: null | |
| selector: | |
| action: {} | |
| actions_section: | |
| name: Actions | |
| description: The actions to execute when (un)notifying. | |
| input: | |
| add_actions: | |
| name: Add notify actions | |
| selector: | |
| action: {} | |
| remove_actions: | |
| name: Remove notify actions | |
| selector: | |
| action: {} | |
| variables: | |
| # get battery of present and past | |
| battery_level_entity: !input level | |
| battery_level_value: "{{states(battery_level_entity)}}" | |
| battery_level_value_changed: "{{ trigger.id == 'battery_level_changed' }}" | |
| battery_level_value_was: "{{trigger.from_state.state | float if battery_level_value_changed else battery_level_value}}" | |
| # get charging of present and past | |
| charging_entity: !input charging | |
| is_charging: "{{ is_state(charging_entity, 'on') }}" | |
| charging_changed: "{{trigger.id == 'charging_changed'}}" | |
| was_charging: "{{ trigger.from_state.state == 'on' if charging_changed else is_charging }}" | |
| # battery values | |
| low_battery_value: !input low_battery | |
| high_battery_value: !input high_battery | |
| # battery ranges of past and present | |
| is_battery_low: "{{ battery_level_value <= low_battery_value }}" | |
| was_battery_low: "{{ battery_level_value_was <= low_battery_value }}" | |
| is_battery_high: "{{ battery_level_value >= high_battery_value }}" | |
| was_battery_high: "{{ battery_level_value_was >= high_battery_value }}" | |
| is_battery_ok: "{{not is_battery_low and not is_battery_high}}" | |
| was_battery_ok: "{{not was_battery_low and not was_battery_high}}" | |
| # notification of present | |
| should_have_low_battery_notification: "{{ is_battery_low and not is_charging }}" | |
| should_have_high_battery_notification: "{{ is_battery_high and is_charging }}" | |
| should_have_notification: "{{ should_have_low_battery_notification or should_have_high_battery_notification }}" | |
| # notification of past | |
| should_have_had_low_battery_notification: "{{ was_battery_low and not was_charging }}" | |
| should_have_had_high_battery_notification: "{{ was_battery_high and was_charging }}" | |
| should_have_had_notification: "{{ (was_battery_low and not was_charging) or (was_battery_high and was_charging) }}" | |
| # action decision | |
| is_removing_notification: "{{ should_have_had_notification and not should_have_notification }}" | |
| is_adding_notification: "{{ not should_have_had_notification and should_have_notification }}" | |
| mode: !input mode | |
| trigger: | |
| - id: battery_level_changed | |
| entity_id: !input level | |
| trigger: state | |
| - id: charging_changed | |
| entity_id: !input charging | |
| trigger: state | |
| - triggers: !input extra_triggers | |
| actions: | |
| - choose: [] | |
| default: !input pre_conditions_actions | |
| - choose: | |
| - conditions: "{{ is_removing_notification }}" | |
| sequence: !input remove_actions | |
| - conditions: "{{ is_adding_notification }}" | |
| sequence: !input add_actions | |
| default: !input default_actions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment