Low battery level detection & notification for all battery sensors

Thanks for this, it really helps new users.

I’ve probably done something obvious wrong as I’m new to all this but I’m seeing this in the logs:

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:517
Integration: Automation ([documentation](https://www.home-assistant.io/integrations/automation), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+automation%22))
First occurred: January 17, 2021, 4:50:53 PM (26 occurrences)
Last logged: 4:21:09 PM

* Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([('day', '0'), ('actions', [OrderedDict([('service', 'Not'), ('data', OrderedDict([('Message', 'Battery low {{sensor}}')]))])])]): Service Not does not match format <domain>.<name> for dictionary value @ data['action'][0]['default'][0]['service']. Got None
* Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([('day', '0'), ('actions', [OrderedDict([('service', 'Not'), ('data', OrderedDict([('message', 'Battery low Now')]))])])]): Service Not does not match format <domain>.<name> for dictionary value @ data['action'][0]['default'][0]['service']. Got None

the yaml looks like:

alias: Low battery level detection & notification for all battery sensors
description: ''
use_blueprint:
  path: Sbyx/low-battery-level-detection-notification-for-all-battery-sensors.yaml
  input:
    day: '0'
    exclude:
      entity_id: []
      device_id: 865e12ec12f811eb87d51db7995879b6
    actions:
      - service: notify.mypushover
        data:
          message: 'Low battery {{sensors}}'
    threshold: '20'

I can execute the automation and I get my pushover alert so presume it’s not that part?

Thanks!

EDIT: I went through my whole automations file and found out there were two other entries for this automation!? So I deleted those and now all is OK. I only normally use the UI so hadn’t noticed them.

1 Like

Hello everyone. It would be interesting if you do not use time as a trigger, but use the lowest battery level of possible sensors. So that the notification does not come every day at the specified time or on certain days of the week, but only when the battery level on the sensors reaches a critical

1 Like

I give an example of the sensor “Lowest battery level”

  - platform: template
    sensors:
        sensors_lowest_battery_level:
          friendly_name: 'battery_alert'
          device_class: battery
          unit_of_measurement: '%'
          value_template: >
                {% set domains = ['sensor'] %}
                {% set ns = namespace(min_batt=100, entities=[]) %}
                {%- set exclude_sensors = ['device_tracker.apple_watch','sensor.iphone_battery_level'] -%}
                {% for domain in domains %}
                  {% set ns.entities = states[domain] %}
                  {% for sensor in exclude_sensors %}
                    {% set ns.entities = ns.entities | rejectattr('entity_id', 'equalto', sensor) %}
                  {% endfor %}
                  {% set batt_sensors = ns.entities | selectattr('attributes.device_class','equalto','battery') | map(attribute='state') | reject('equalto', 'unknown') | reject('equalto', 'None') | map('int') | reject('equalto', 0) | list %}
                  {% set batt_attrs = ns.entities | selectattr('attributes.battery','defined') | map(attribute='attributes.battery') | reject('equalto', 'unknown') | reject('equalto', 'None') | map('int') | reject('equalto', 0) | list %}
                  {% set batt_lvls = batt_sensors + batt_attrs %}
                  {% if batt_lvls|length > 0 %}
                    {% set _min = batt_lvls|min %}
                    {% if _min < ns.min_batt %}
                      {% set ns.min_batt = _min %}
                    {% endif %}
                  {% endif %}
                {% endfor %}
                {{ ns.min_batt }}

Strange behavior:

I have all smartphones on the excluded list but did receive a low battery alert. Where‘s the bug?

@e-raser that’s why it says only entities are supported (green) and you added devices (blue). You need to expand the devices to entities using the <> button.

1 Like

Thanks, I missed that. Not easy to aim on the mobile too but „fixed“ it now :slight_smile:

Thanks! works great!

Nice Blueprint! Just wondering if it’s possible to add Chrome/Windows notification? Thanks

Good morning,

perfect Blueprint - I’ve been using it for a long time and am very happy with it.

Many thanks for this

My question is if it would take much work to change the template to check the last update of sensors.

So reporting back all sensors that have not sent for more than 24 hours. I think we have all sensors that lose contact once?

Unfortunately my skills are not sufficient for this

hi Sbyx

i am trying to use your blueprint for batteries to satisfy my use case of multiple thermostats that control the water flowing to the radiators. the pump that sends water to the radiators is currently managed by a central thermostat not connected to a radiator,

i want to measure the heating level of each thermostat. if any heating level is above a threshold the pump should be on. if all the heating levels are below the threshold, the pump should be off.

i will control the heating level of each thermostat separately, including open window detection.

clearly this is similar to the battery detection blueprint you put together. i have used you blueprint to create automation to warn me when the radiator batteries are low.

i’d really appreciate any guidance you can offer.

During home assistant restart:

Mar 05 07:48:17 HA hass[16712]: 2021-03-05 07:48:17 ERROR (MainThread) [homeassistant.components.automation] Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([(‘time’, ‘10:00:00’), (‘threshold’, 45), (‘exclude’, OrderedDict([('entity_id
Mar 05 07:48:17 HA hass[16712]: 2021-03-05 07:48:17 ERROR (MainThread) [homeassistant.components.automation] Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([(‘time’, ‘10:00:00’), (‘threshold’, 45), (‘actions’, [OrderedDict([('device_i
Mar 05 07:48:17 HA hass[16712]: 2021-03-05 07:48:17 ERROR (MainThread) [homeassistant.components.automation] Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([(‘time’, ‘10:00:00’), (‘threshold’, 45), (‘exclude’, OrderedDict([('entity_id

1 Like

So I don’t know if there is a bug somewhere or I’m just incompetent (the latter is most likely) but I cannot make this work. Every time I try to create an automation it just does…nothing. I fill in the time/action/etc then hit save. It seems to accept all my inputs but then doesn’t show up on the automations tab and doesn’t actually fire. I’m sure I’m missing something stupid but don’t even know where to start since this is the first blueprint I’ve tried to use. I haven’t a clue where to even start figuring out what the issue is. Any assistance would be appreciated, thanks!

I experienced the same thing.
I had to restart HA after adding the blueprint in. Then it would show up.

@WedHumpDay - Thanks, but I’ve done that a number of times and still have the same result.

Bummer… Also, the author has not responded within at least a week on the error HA is generating on this Blueprint.

IMHO - Blueprints need to be proofed out before posting. And when posted, maintain their blueprints as HA does make enhancements breaking some settings, which is called out during release.

@sybx

Blueprint is working fine here (just got a notification yesterday) and I am regularly updating HA to the latest version. I just did the 2021.3.4 update and created a new automation with the blueprint. No log entries and triggering manually works fine.

If you see an issue like blueprint “generated invalid automation” it could be something in your actions could be wrong.

In the past there seemed to be some HA related issue wher HA put broken blueprint related sections in automations.yaml I would check your file and maybe remove all automation section related to the blueprint and then try again.

Hello @Sbyx !
Nice Blueprint, this is my first one. Added the Telegram notify and it works great.
I’ve a Feature Request, which should not be so difficult:
This automation is based on a periodic check (once a week or once a day) looking for the battery device_class.
Would be possible to implement the same check, with a faster frequence (i.e. every two hours) for check the devices which has a linkquality attribute? Maybe it works on battery as well. My goal is to check if those devices are working or not. I’ve different ZigBee devices and the problem is, they could not be paired correctly and so I’ve no idea if they are working or not. So looking for the last_update status could trigger a notification.
Possible to implement?
Thanks!
Simon

I really like the design of this blueprint. Unfortunately just like @WedHumpDay I was getting errors when trying to actually generate the automation (same errors in fact).

Not to step on the toes of @Sbyx but I went and basically forked it over to https://github.com/tykeal/homeassistant-blueprints

While I did that I did some formatting cleanup and then ran it through yamllint which highlighted some problems with the code. Applying fixes has given me a cleanly installing and working automation.

Direct install of this version is at:

9 Likes

Outstanding @tykeal !!!
Just tested and works perfectly, no error messages.

The only downside I see with all alerting systems, if there are 2+ sensors then the alert messages places them one behind the other. Ideally, each device should be on it’s own line. Not complaining, this is working, so kudos. If more than one sensor goes off its easy enough to check the Battery tab…

Customized my own message and all is working.

device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
domain: mobile_app
type: notify
title: Low Battery
message: '{{sensors}}'

Is there any way to get a notification each time you update (modify, improve or bug-fix) this Blueprint?