Forked from sbyx/low-battery-level-detection-notification-for-all-battery-sensors.yaml
Last active
January 4, 2025 15:04
-
-
Save peltsippi/cb9c1b1da1c7d14432ec0ec0c222d889 to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Low battery level detection & notification for ruuvitags
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 battery level detection & notification for ruuvitags. | |
description: Regularly test all ruuvitags for crossing | |
a certain battery level threshold and if so execute an action. | |
Ruuvitag says that 1800mV tag should still function but it depends on temperature etc. | |
1900 mV during -10C seems to be too low for my units but YMMV | |
domain: automation | |
input: | |
threshold: | |
name: Battery warning level threshold | |
description: Battery sensors below threshold are assumed to be low-battery | |
default: 2100 | |
selector: | |
number: | |
min: 1800.0 | |
max: 3000.0 | |
unit_of_measurement: 'mV' | |
mode: slider | |
step: 50.0 | |
time: | |
name: Time to test on | |
description: Test is run at configured time | |
default: '10:00:00' | |
selector: | |
time: {} | |
day: | |
name: Weekday to test on | |
description: 'Test is run at configured time either everyday (0) or on a given | |
weekday (1: Monday ... 7: Sunday)' | |
default: 0 | |
selector: | |
number: | |
min: 0.0 | |
max: 7.0 | |
mode: slider | |
step: 1.0 | |
excluded: | |
name: Excluded sensors | |
description: "Remove all sensor you want to ignore (other sensors that have _Voltage ending or similar)" | |
default: {entity_id: []} | |
selector: | |
entity: | |
multiple: true | |
filter: | |
- domain: sensor | |
integration: ruuvitag_ble | |
actions: | |
name: Actions | |
description: Notifications or similar to be run. {{sensors}} is replaced with | |
the names of sensors being low on battery. | |
selector: | |
action: {} | |
source_url: https://gist.github.com/peltsippi/cb9c1b1da1c7d14432ec0ec0c222d889 | |
variables: | |
day: !input 'day' | |
threshold: !input 'threshold' | |
exclude: !input 'excluded' | |
sensors: >- | |
{% set result = namespace(sensors=[]) %} | |
{% for state in states.sensor | selectattr('entity_id', 'search', '_voltage') %} | |
{% if 0 <= state.state | int(-1) < threshold | int and not state.entity_id in exclude.entity_id %} | |
{% set result.sensors = result.sensors + [state.name ~ ' (' ~ state.state ~ ' mV)'] %} | |
{% endif %} | |
{% endfor %} | |
{{result.sensors|join(', ')}} | |
trigger: | |
- platform: time | |
at: !input 'time' | |
condition: | |
- '{{ sensors != '''' and (day | int == 0 or day | int == now().isoweekday()) }}' | |
action: | |
- choose: [] | |
default: !input 'actions' | |
mode: single |
works but not that functional when trying to exclude any sensors
Not working, trying to get exclude device filtering working
Good enough. Selector - entity - cannot use include list from scripts and I don't know any better way than this. All other ruuvitag sensors pop out to exclude list.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not working yet