![](/style/images/good.png)
![](/style/images/bad.png)
Home Assistant Blueprint: Low battery level detection & notification for all...
source link: https://gist.github.com/sbyx/1f6f434f0903b872b84c4302637d0890
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Does this work for the 433MHZ sensors..that work though the Sonoff RF Bridge ?
THese sensors sen3 3 codes - Open, Close & Low Batt Code. Can this template be adapted for the Low Batt Code ?
Author
sbyx commented on Jan 6, 2021
Is the low-battery state exposed in HA and if so, how?
the 433MHz sensor send out 3 codes. I have seens on the forums users making thoer own automation to alert when the "Low Batt" code is recived from the Sensor via the RF Bridge.
example
12F70A - open
12F70E - closed
12F707 - tamper
12F706 - low battery
Ref: https://community.home-assistant.io/t/sonoff-dw1-433mhz-door-window-sensor-low-battery-warning-capable/43073/8
platform: mqtt
topic: rfbridge_A12345/tele/RESULT
condition:
condition: template
value_template: ‘"{{ trigger.payload_json.RfReceived.Sync > 10200 }}"’
condition: and
conditions:
condition: template
value_template: ‘"{{ trigger.payload_json.RfReceived.Data == ‘‘9CEA29’’ }}"’
action:
data:
message: change battery because sync is high for device code 9CEA29
service: notify.notify
Author
sbyx commented on Jan 6, 2021
I see right now only actual sensor entities in HA are supported, i.e. ones you can find under Settings - Entities.
I used this on a system that uses 24-hour clock. I set the time option to 12:00 PM. The automation that was created had time value converted to 24:00:00. This did not work and broke the automation. Changing it to a valid value fixed it.
I don't know if it is a bug in this blueprint or in HA.
AseKarlsson commented on Jun 25, 2021 •
Great Blueprint.
Not sure what to add to the "Actions" part, I want to get a notification if any device have low battery.
Notification in HA Notifications area is good enough.
Any advice?
//Ase
colmbuckley commented on Jun 30, 2021 •
Great Blueprint.
Not sure what to add to the "Actions" part, I want to get a notification if any device have low battery.
Notification in HA Notifications area is good enough.
Action type: "Call Service"
Service: notify.notify
Fill in the message you want to be notified with.
(notify.persistent_notification to add a notification to the "notifications" section of the HAss app. notify.notify to send a push notification to your devices. you can also use something like notify.email to send emails.)
Great Blueprint.
To get all my 22 battery powered devices, including those that displays voltage instead of percent, I modified the sensors part with this code:
sensors: >-
{% set result = namespace(sensors=[]) %}
{% for state in states.sensor | selectattr('attributes.device_class', '==', 'battery') %}
{% if state.state | int < threshold and not state.state == 'unavailable' %}
{% set result.sensors = result.sensors + [state.name ~ ' (' ~ state.state ~ '%)'] %}
{% endif %}
{% endfor %}
{% for sensor in states.binary_sensor %}
{% if 'battery_level' in sensor.attributes %}
{% if ((state_attr(sensor.entity_id, 'battery_level')-2) |float/0.01)|round(1) | int < threshold and not sensor.state == 'unavailable' %}
{% set result.sensors = result.sensors + [sensor.name ~ ' (' ~ ((state_attr(sensor.entity_id, 'battery_level')-2)|float/0.01)|round(1) ~ '%)'] %}
{% endif %}
{% endif %}
{% endfor %}
{% for sensor in states.camera %}
{% if 'battery_level' in sensor.attributes %}
{% if state_attr(sensor.entity_id, 'battery_level') | int < threshold and not sensor.state == 'unavailable' %}
{% set result.sensors = result.sensors + [sensor.name ~ ' (' ~ state_attr(sensor.entity_id, 'battery_level')~ '%)'] %}
{% endif %}
{% endif %}
{% endfor %}
{{result.sensors|join('\n')}}
I also joined the result with '\n' instead of ', ' which displays one device per row when I do a persistent notification.
I have 2 actions:
service: persistent_notification.create
data:
title: Warning low battery level!
message: Low battery level{{ ':' }}{{ '\n' -}}{{sensors}}
service: notify.notify
data:
title: Warning low battery level!
message: 'Low battery level: {{sensors}}'
AseKarlsson commented on Jul 1, 2021 •
Thanks Guys for helping me out, now both HA and email notification in place. So obvious after seeing your answers.
Great Blueprint.
To get all my 22 battery powered devices, including those that displays voltage instead of percent, I modified the sensors part with this code:
sensors: >-
{% set result = namespace(sensors=[]) %}
{% for state in states.sensor | selectattr('attributes.device_class', '==', 'battery') %}
{% if state.state | int < threshold and not state.state == 'unavailable' %}
{% set result.sensors = result.sensors + [state.name ~ ' (' ~ state.state ~ '%)'] %}
{% endif %}
{% endfor %}
{% for sensor in states.binary_sensor %}
{% if 'battery_level' in sensor.attributes %}
{% if ((state_attr(sensor.entity_id, 'battery_level')-2) |float/0.01)|round(1) | int < threshold and not sensor.state == 'unavailable' %}
{% set result.sensors = result.sensors + [sensor.name ~ ' (' ~ ((state_attr(sensor.entity_id, 'battery_level')-2)|float/0.01)|round(1) ~ '%)'] %}
{% endif %}
{% endif %}
{% endfor %}
{% for sensor in states.camera %}
{% if 'battery_level' in sensor.attributes %}
{% if state_attr(sensor.entity_id, 'battery_level') | int < threshold and not sensor.state == 'unavailable' %}
{% set result.sensors = result.sensors + [sensor.name ~ ' (' ~ state_attr(sensor.entity_id, 'battery_level')~ '%)'] %}
{% endif %}
{% endif %}
{% endfor %}
{{result.sensors|join('\n')}}I also joined the result with '\n' instead of ', ' which displays one device per row when I do a persistent notification.
I have 2 actions:
service: persistent_notification.create
data:
title: Warning low battery level!
message: Low battery level{{ ':' }}{{ '\n' -}}{{sensors}}service: notify.notify
data:
title: Warning low battery level!
message: 'Low battery level: {{sensors}}'
Super helpful, thank you!
anarro commented on Aug 19, 2021 •
Great Blueprint.
To get all my 22 battery powered devices, including those that displays voltage instead of percent, I modified the sensors part with this code:
sensors: >-
{% set result = namespace(sensors=[]) %}
{% for state in states.sensor | selectattr('attributes.device_class', '==', 'battery') %}
{% if state.state | int < threshold and not state.state == 'unavailable' %}
{% set result.sensors = result.sensors + [state.name ~ ' (' ~ state.state ~ '%)'] %}
{% endif %}
{% endfor %}
{% for sensor in states.binary_sensor %}
{% if 'battery_level' in sensor.attributes %}
{% if ((state_attr(sensor.entity_id, 'battery_level')-2) |float/0.01)|round(1) | int < threshold and not sensor.state == 'unavailable' %}
{% set result.sensors = result.sensors + [sensor.name ~ ' (' ~ ((state_attr(sensor.entity_id, 'battery_level')-2)|float/0.01)|round(1) ~ '%)'] %}
{% endif %}
{% endif %}
{% endfor %}
{% for sensor in states.camera %}
{% if 'battery_level' in sensor.attributes %}
{% if state_attr(sensor.entity_id, 'battery_level') | int < threshold and not sensor.state == 'unavailable' %}
{% set result.sensors = result.sensors + [sensor.name ~ ' (' ~ state_attr(sensor.entity_id, 'battery_level')~ '%)'] %}
{% endif %}
{% endif %}
{% endfor %}
{{result.sensors|join('\n')}}I also joined the result with '\n' instead of ', ' which displays one device per row when I do a persistent notification.
I have 2 actions:
service: persistent_notification.create
data:
title: Warning low battery level!
message: Low battery level{{ ':' }}{{ '\n' -}}{{sensors}}service: notify.notify
data:
title: Warning low battery level!
message: 'Low battery level: {{sensors}}'
I made the modifications in a blueprint but when I receive the notification (Telegram) it shows me in a single line, how can I see it in two rows?
It's possible?
Thank you.
anarro commented on Aug 20, 2021 •
Great Blueprint.
To get all my 22 battery powered devices, including those that displays voltage instead of percent, I modified the sensors part with this code:
sensors: >-
{% set result = namespace(sensors=[]) %}
{% for state in states.sensor | selectattr('attributes.device_class', '==', 'battery') %}
{% if state.state | int < threshold and not state.state == 'unavailable' %}
{% set result.sensors = result.sensors + [state.name ~ ' (' ~ state.state ~ '%)'] %}
{% endif %}
{% endfor %}
{% for sensor in states.binary_sensor %}
{% if 'battery_level' in sensor.attributes %}
{% if ((state_attr(sensor.entity_id, 'battery_level')-2) |float/0.01)|round(1) | int < threshold and not sensor.state == 'unavailable' %}
{% set result.sensors = result.sensors + [sensor.name ~ ' (' ~ ((state_attr(sensor.entity_id, 'battery_level')-2)|float/0.01)|round(1) ~ '%)'] %}
{% endif %}
{% endif %}
{% endfor %}
{% for sensor in states.camera %}
{% if 'battery_level' in sensor.attributes %}
{% if state_attr(sensor.entity_id, 'battery_level') | int < threshold and not sensor.state == 'unavailable' %}
{% set result.sensors = result.sensors + [sensor.name ~ ' (' ~ state_attr(sensor.entity_id, 'battery_level')~ '%)'] %}
{% endif %}
{% endif %}
{% endfor %}
{{result.sensors|join('\n')}}
I also joined the result with '\n' instead of ', ' which displays one device per row when I do a persistent notification.
I have 2 actions:
service: persistent_notification.create
data:
title: Warning low battery level!
message: Low battery level{{ ':' }}{{ '\n' -}}{{sensors}}
service: notify.notify
data:
title: Warning low battery level!
message: 'Low battery level: {{sensors}}'I made the modifications in a blueprint but when I receive the notification (Telegram) it shows me in a single line, how can I see it in two rows?
It's possible?
Thank you.
I can get it with:
I don't use Telegram for notifications, but the screenshot you shared looks very much as though you had written '/n' instead of '\n' in your join(). Are you sure the new version is the one which is being used?
the 433MHz sensor send out 3 codes. I have seens on the forums users making thoer own automation to alert when the "Low Batt" code is recived from the Sensor via the RF Bridge.
example
12F70A - open
12F70E - closed
12F707 - tamper
12F706 - low battery
Ref: https://community.home-assistant.io/t/sonoff-dw1-433mhz-door-window-sensor-low-battery-warning-capable/43073/8
platform: mqtt
topic: rfbridge_A12345/tele/RESULT
condition:
condition: template
value_template: ‘"{{ trigger.payload_json.RfReceived.Sync > 10200 }}"’
condition: and
conditions:
condition: template
value_template: ‘"{{ trigger.payload_json.RfReceived.Data == ‘‘9CEA29’’ }}"’
action:
data:
message: change battery because sync is high for device code 9CEA29
service: notify.notify
Not sure if you figured this out, but you need to create a binary_sensor for these mqtt style battery high/low sensors. This is what one will look like:
- platform: mqtt
name: family_motion_battery
state_topic: 'rtl_433/9b13b3f4-rtl433/devices/Interlogix-Security/motion/4cf72a/battery_ok'
payload_off: "1"
payload_on: "0"
device_class: battery
12F706
you have 433MHz sensor working via Sonoff RF Bridge ? and this binary_sensor config is working for you ?..On my RF bridge......the code it sends out for low batt is XXXX06 (XXXX is unique to a sensor, XXXX0A for Open/On & XXXX0E for closed/Off)..if you say its working for you then i will giv e it a try..but i dont see this topic sent out by my Tasmotized Sonoff RF Bridge "rtl_433/9b13b3f4-rtl433/devices/Interlogix-Security/motion/4cf72a/battery_ok"
Ho to remove that blueprint. It don't work and after I delete it from schema tab and automation tab every restart I get notification:
Invalid config
The following integrations and platforms could not be set up:
automation
Please check your config and logs.
Logs:
Logger: homeassistant.config
Source: components/blueprint/models.py:211
First occurred: 12:23:08 (1 occurrences)
Last logged: 12:23:08
Invalid config for [automation]: Failed to load blueprint: Unable to find sbyx/low-battery-level-detection-notification-for-all-battery-sensors.yaml (See /mnt/dietpi_userdata/homeassistant/configuration.yaml, line 10).
Traceback (most recent call last):
File "/home/homeassistant/.pyenv/versions/3.9.7/lib/python3.9/site-packages/homeassistant/components/blueprint/models.py", line 209, in _load_blueprint
blueprint_data = yaml.load_yaml(self.blueprint_folder / blueprint_path)
File "/home/homeassistant/.pyenv/versions/3.9.7/lib/python3.9/site-packages/homeassistant/util/yaml/loader.py", line 110, in load_yaml
with open(fname, encoding="utf-8") as conf_file:
FileNotFoundError: [Errno 2] No such file or directory: '/mnt/dietpi_userdata/homeassistant/blueprints/automation/sbyx/low-battery-level-detection-notification-for-all-battery-sensors.yaml'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/homeassistant/.pyenv/versions/3.9.7/lib/python3.9/site-packages/homeassistant/components/automation/config.py", line 106, in _try_async_validate_config_item
config = await async_validate_config_item(hass, config, full_config)
File "/home/homeassistant/.pyenv/versions/3.9.7/lib/python3.9/site-packages/homeassistant/components/automation/config.py", line 70, in async_validate_config_item
return await blueprints.async_inputs_from_config(config)
File "/home/homeassistant/.pyenv/versions/3.9.7/lib/python3.9/site-packages/homeassistant/components/blueprint/models.py", line 297, in async_inputs_from_config
blueprint = await self.async_get_blueprint(bp_conf[CONF_PATH])
File "/home/homeassistant/.pyenv/versions/3.9.7/lib/python3.9/site-packages/homeassistant/components/blueprint/models.py", line 275, in async_get_blueprint
blueprint = await self.hass.async_add_executor_job(
File "/home/homeassistant/.pyenv/versions/3.9.7/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/homeassistant/.pyenv/versions/3.9.7/lib/python3.9/site-packages/homeassistant/components/blueprint/models.py", line 211, in _load_blueprint
raise FailedToLoad(
homeassistant.components.blueprint.errors.FailedToLoad: Failed to load blueprint: Unable to find sbyx/low-battery-level-detection-notification-for-all-battery-sensors.yaml
How to delete this blueprint?
Regards.
How to delete this blueprint?
You must still have an automation which uses it. Look through your automations for instances of this blueprint and remove any you find.
Given that the blueprint file is deleted, the automations will be disabled, but you need to remove them completely for this error to be resolved.
Colm
OK, thanks. I remove lines from automations.yaml
file.
Regards.
Was using but it suddenly stopped working. Tried to reinstall after deleting automation and blueprint and when I try to reinstall and configure I get an error “Message malformed: Missing input actions”
Help please
I've been using this for awhile and just recently added a device thats reports battery as a voltage (two AA batteries reporting at 3.14v at the moment) I know I could just exclude this device, but wondering if there would be a way to only look at devices that have a unit of measure of %? (unit in my case is v)
leonardus1973 commented on Apr 24 •
{{ '\n' -}}
Is possible to use {{ '\n' -}} in telegram message? I have tried but nothing happen. thank you.
Another question:
Test is run at configured time either everyday (0) or on a given weekday (1: Monday ... 7: Sunday)
Value 0 for every day is not accepted (min is 1). why? Thank you.
JackPo commented 18 days ago
Is there a way to only get fire the action when {{sensors}} is not empty?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK