Low battery level detection & notification for all battery sensors

Thank you for this Blueprint! I am using it for a long time but unfortunately i am getting now an error


Logger: homeassistant.components.automation
Source: components/automation/__init__.py:280 
Integration: Automation (documentation, issues) 
First occurred: 9:00:30 PM (1 occurrences) 
Last logged: 9:00:30 PM

Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([('actions', [OrderedDict([('service', 'notify.mobile_app_udos-iphone'), ('data', OrderedDict([('title', 'Batteriewarnung'), ('message', 'Batterie wechseln {{sensors}}')])), ('enabled', False)]), OrderedDict([('service', 'notify.mobile_app_iphone'), ('data', OrderedDict([('title', 'Batteriewarnung'), ('message', 'Batterie wechseln {{sensors}}')]))])]), ('threshold', 25), ('exclude', OrderedDict([('entity_id', []), ('device_id', ['7b1937be2af35330bb7bd5551f168d6f', 'e238a8d48af5ade63aafd3c35993ecf3', 'a50ada28f8492c65436a1c1053c040c9', 'a06d2a3af413351771953b0e9df15b95'])]))]): Service notify.mobile_app_udos-iphone does not match format <domain>.<name> for dictionary value @ data['action'][0]['default'][0]['service']. Got None

This is my configuration:


alias: Batteriewarnung
description: ""
use_blueprint:
  path: sbyx/low-battery-level-detection-notification-for-all-battery-sensors.yaml
  input:
    actions:
      - service: notify.mobile_app_udos_iphone
        data:
          title: Batteriewarnung
          message: Batterie laden {{sensors}}
    exclude:
      entity_id:
        - sensor.ui11pro_battery_level
        - sensor.nitis_iphone_battery_level
        - sensor.udos_ipad_battery_level

Is there something wrong?

You used a dash instead of an underscore?

Iā€™ve corrected the service call

Bildschirmfoto 2022-10-14 um 08.07.25

But each time i am saving the automation again the error appears again

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:280
Integration: Automation (documentation, issues)
First occurred: 7:39:26 AM (1 occurrences)
Last logged: 7:39:26 AM

Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([('actions', [OrderedDict([('service', 'notify.mobile_app_udos-iphone'), ('data', OrderedDict([('title', 'Batteriewarnung'), ('message', 'Batterie wechseln {{sensors}}')])), ('enabled', False)]), OrderedDict([('service', 'notify.mobile_app_iphone'), ('data', OrderedDict([('title', 'Batteriewarnung'), ('message', 'Batterie wechseln {{sensors}}')]))])]), ('threshold', 25), ('exclude', OrderedDict([('entity_id', []), ('device_id', ['7b1937be2af35330bb7bd5551f168d6f', 'e238a8d48af5ade63aafd3c35993ecf3', 'a50ada28f8492c65436a1c1053c040c9', 'a06d2a3af413351771953b0e9df15b95'])]))]): Service notify.mobile_app_udos-iphone does not match format <domain>.<name> for dictionary value @ data['action'][0]['default'][0]['service']. Got None

The error still mentions the dash. I would try:
1 delete the automation step ( only this step)
2 add the step
3 fill with ui the notify service
4 full message without template
5 save

If works
6 add template message

I noticed if i change anything on my automations and hit save the error message appears.
Next i found out that there was an old entry in my automation.yaml. Iā€˜ve removed that old entry and finally the error disappear!

Thanks for all your help!

Any chance the blueprint (will) support(s) ā€œlow levelā€ battery entities of state either ā€œonā€ / ā€œtrueā€ or ā€œoffā€ / ā€œfalseā€?

Iā€™m trying to get the notification on my phone. I get a notification but not with any sensors, and I tried a 70% to test. Hereā€™s the code - I get a notice with everything up to the low: bit, no sensors. What am I doing wrong?

service: notify.mobile_app_roberts_iphone
data:
  message: "The sensor batterie(s) are low: {{sensors}}"

It alerts when below the threshold set. Not sure what you mean by baseline here. If itā€™s set to 20%, itā€™ll alert at 19% or lower.

It already supports battery binary sensors!

Not sure, is there anything in your HA log to indicate an error? Mine looks like this and works (in the Yaml editor in the HA automation edit interface for the action):


service: notify.slack
data:
  message: |-
    *Low battery:*
    {{ sensors }}

But how? The description does not indicate that. Binary sensors donā€™t have a percentage value and thatā€™s what this blueprint is about, right?

For now I created a separate automation on my own using a group of all battery sensors with low level indication (binary_sensor). Huge advantage: I donā€™t have to exclude stuff.

Feature request: let us INCLUDE sensors instead of only being able to EXCLUDE sensors. That would be really awesome.

Of course only the names of the binary sensors will be displayed if they are on.

The description for the battery threshold setting says this:

Battery sensors below threshold are assumed to be low-battery (as well as binary battery sensors with value ā€˜onā€™).

So the blueprint is not just about percentage values. It includes binary sensors with the battery device class.

The blueprint is also exclusion-only because it saves you from having to enter every new battery entity to it manually. Otherwise every time a new battery entity is added to the system, youā€™d have to update your automation. Much better to exclude the ones you donā€™t care about ad hoc than to miss the ones you will eventually almost certainly forget to add.

Thatā€™s exactly what I have to do now. Because I have two automations using this blueprint, as some devices need a different warning treshold (every Aqara user knows most sensors are near to dead with 70 %).

So today I have

  • automation no 1: for monitoring Aqara devices
  • automation no 2: for monitoring all other devices

Both automations need to exclude the opposite devices. Therefore it would be much more intuitive to include sensors, best to use groups which are simply expanded.

Interesting use case. Having the blueprint be able to only apply to certain groups would be a good addition.

1 Like

I would love to see that!

Cause I maintain all my battery sensor entities in separate groups anyway. Currently a manual job, can maybe be automated with some template magic on ā€židentify all battery sensor entities of Aqara devicesā€œ.

Anyway, if the blueprint would support groups and expand them (so the rest is working as currently with a list of affected sensors in the notification etc.), that would save me from editing all blueprint based automations too in addition to the group change).

Sidenote: expanding groups to list the names of their entities in a certain state:

{{ expand('group.batterystate_lowlevel')|selectattr('state','eq','on')|map(attribute='name')|join(',') }}

@Sbyx so how are chances this include filter will get implemented?

I love this, thanks Dave!

  • The persistent notification is exactly what I was looking for.
  • One device per line
  • Being able to pick the notification device from a dropdown list was handy, particularly because it didnā€™t require having to edit the notification in YAML.

@Sbyx it would be awesome to add these features here, so we end up with one butt-kicking blueprint.

IMHO this blueprint should be included as standard in Home Assistant.

Must the message not be in " " or ā€™ '?

Its how the config in yaml looks like. I have deleted the automation and created again and error is gone.

1 Like