🪫 Low Battery Notifications & Actions

@Matthew_Budraitis

Thanks, I just use the Button Helper Trigger for this and have the button on a dashboard. Once I replace the battery I just push the button helper and it rechecks them.

Blacky :smiley:

With the latest HA release, I’m getting the following error. How is best to resolve it?


While floating around, Spook crossed path with the following automation:

Low Battery Notifications & Actions (automation.low_battery_notifications_actions_3)

This automation references the following actions, which are unknown to Home Assistant:

    todo.add_item

@PedroKTFC

See this FAQ click here

Blacky :smiley:

Doh! I deleted the integration as I don’t use it and completely forgot about that. Thanks.

1 Like

Hi @Blacky,

thanks for this blueprint — using it for whole-house battery monitoring and it’s been great.

One thing that would help a lot: the battery_sensor_report_fields option lets me add the floor as an inline tag per sensor (Sensor Name {Basement}), but the list itself stays flat and unsorted.
For a house with many battery sensors across multiple floors, it’d be much easier to scan if the report were grouped/sorted by floor instead, e.g.:

Basement:
• Utility Room Climate @ 14%
• Sauna Climate @ 4%

Ground Floor:
• Living Room Climate @ 16%

Other:
• Tablet Battery is unavailable!

Would it be possible to add a “group by floor” option (maybe as an additional toggle alongside the existing report-field selector), using HA’s floor registry for ordering (basement → ground → upper floors)? Happy to test if you’re open to it.

Thanks again for maintaining this!

@andre68723

Thanks for your suggestion. I think that is a really good idea as it can be cleaner to look at and reduce the text in the notification. I add it to the list to do.

Blacky :smiley:

@Blacky

all_sensors is undefined when Custom Actions are disabled

Description

The Low Battery Notifications & Actions blueprint generates the following Home Assistant template warning when custom_actions contains a template using all_sensors, but Custom Actions are disabled:

Logger: homeassistant.helpers.template
Source: helpers/template/__init__.py:648

Template variable warning: 'all_sensors' is undefined when rendering '• {{all_sensors|replace(", ", " • ")}}'

It appears that Home Assistant/the blueprint is rendering the template contained within custom_actions even though:

include_custom_actions: disabled_custom_actions

is configured.

Blueprint configuration

The automation uses:

use_blueprint:
  path: Blackshome/low-battery-notifications-and-actions.yaml

Custom Actions contains:

custom_actions:
  - metadata: {}
    data:
      title: "🪫Low Battery Notification"
      message: '• {{all_sensors|replace(", ", "
        • ")}}'
    action: notify.persistent_notification

However, Custom Actions are explicitly disabled:

include_custom_actions: disabled_custom_actions

The blueprint’s normal persistent notification is enabled separately:

include_persistent_notification: enable_persistent_notification

Expected behaviour

Because:

include_custom_actions: disabled_custom_actions

I would expect custom_actions not to be evaluated/rendered at all.

Alternatively, if the action is rendered before the enabled/disabled condition is evaluated, variables documented for Custom Actions such as all_sensors should still be available during template rendering.

Actual behaviour

Home Assistant logs:

Template variable warning: 'all_sensors' is undefined when rendering '• {{all_sensors|replace(", ", " • ")}}'

The warning occurs even though Custom Actions are disabled.

Workaround

Removing the unused custom_actions: configuration from the automation stops the warning.

For example, removing:

custom_actions:
  - metadata: {}
    data:
      title: "🪫Low Battery Notification"
      message: '• {{all_sensors|replace(", ", "
        • ")}}'
    action: notify.persistent_notification

while retaining:

include_custom_actions: disabled_custom_actions

avoids the issue.

Possible cause

It looks like the custom_actions templates may be getting rendered/evaluated before the blueprint has established the variables used by Custom Actions, or before include_custom_actions prevents the action from being processed.

The blueprint itself defines/uses all_sensors, so the problem appears specifically related to the variable’s availability when rendering the configured Custom Action.

Additional information

The exact warning generated by Home Assistant is:

Logger: homeassistant.helpers.template
Source: helpers/template/__init__.py:648
First occurred: 08:45:00 (1 occurrence)
Last logged: 08:45:00

Template variable warning: 'all_sensors' is undefined when rendering '• {{all_sensors|replace(", ", " • ")}}'

@andyblac

AI can through you a curve ball and I rather just look at the problem myself.

Could you please provide us your YAML of the automation that is providing this error? This way I can replicate the settings you have selected in the automation so I can test it. To do this go into your automation, top right 3 dots, Edit in YAML, copy all the code, come back to the forum and in your reply at the top tool bar click on “</>” and paste code in there.

Blacky :smiley:

sure thing..

  alias: Low Battery Notifications
  description: ''
  use_blueprint:
    path: Blackshome/low-battery-notifications-and-actions.yaml
    input:
      include_time: time_enabled
      time: 08:45:00
      exclude_sensors:
        entity_id:
        - sensor.kitchen_neff_freezer_sensor_battery
        - sensor.kitchen_neff_refrigerator_sensor_battery
      include_easy_notify: disabled_easy_notify
      notify_device: []
      notify_title: Low Battery
      notify_message: sensors
      battery_level: 11
      custom_actions:
      - metadata: {}
        data:
          title: "\U0001FAABLow Battery Notification"
          message: '• {{all_sensors|replace(", ", "

            • ")}}'
        action: notify.persistent_notification
      include_custom_actions: disabled_custom_actions
      custom_group_battery_level: 21
      include_persistent_notification: enable_persistent_notification
      sensor_selection: enable_all_and_custom_group_sensors
      include_button: disable_button_trigger
      custom_group:
        entity_id:
        - sensor.andys_bedroom_thermostat_battery_plus
        - sensor.andys_bedroom_itrv_battery_plus
        - sensor.spare_bedroom_thermostat_battery_plus
        - sensor.spare_bedroom_itrv_battery_plus
        - sensor.lounge_thermostat_battery_plus
        - sensor.lounge_itrv_small_battery_plus
        - sensor.lounge_itrv_large_battery_plus
        - sensor.media_room_thermostat_battery_plus
        - sensor.media_room_itrv_battery_plus
        - sensor.office_thermostat_battery_plus
        - sensor.office_itrv_battery_plus
      exclude_hidden_entities: hidden_enabled
      persistent_notify_message: sensors
      persistent_sensor_selection: enable_all_and_custom_group_sensors

I don’t remember adding the custom action myself, maybe it left over from an older version, as creating a new automation does not create it. I’ll remove to from my automation that should fix my error in the log…

@andyblac

Okay, I see the problem. I’m not sure if it was always there or if it was introduced when HA updated how templates are handled. Either way, we’ll now need to set a default, as it looks like the settings are rendering the template variable before it is available. Setting a default will prevent the warning.

See your code below and I will have to update the descriptions and FAQ’s when I get some time.

Thanks for letting me know Andy :+1:

alias: Low Battery Notifications
description: ''
use_blueprint:
  path: Blackshome/low-battery-notifications-and-actions.yaml
  input:
    include_time: time_enabled
    time: 08:45:00
    exclude_sensors:
      entity_id:
      - sensor.kitchen_neff_freezer_sensor_battery
      - sensor.kitchen_neff_refrigerator_sensor_battery
    include_easy_notify: disabled_easy_notify
    notify_device: []
    notify_title: Low Battery
    notify_message: sensors
    battery_level: 11
    custom_actions:
      - metadata: {}
        data:
          title: 🪫Low Battery Notification
          message: • {{ all_sensors | default("") | replace(", ", "\n• ") }}
        action: notify.persistent_notification
    include_custom_actions: disabled_custom_actions
    custom_group_battery_level: 21
    include_persistent_notification: enable_persistent_notification
    sensor_selection: enable_all_and_custom_group_sensors
    include_button: disable_button_trigger
    custom_group:
      entity_id:
      - sensor.andys_bedroom_thermostat_battery_plus
      - sensor.andys_bedroom_itrv_battery_plus
      - sensor.spare_bedroom_thermostat_battery_plus
      - sensor.spare_bedroom_itrv_battery_plus
      - sensor.lounge_thermostat_battery_plus
      - sensor.lounge_itrv_small_battery_plus
      - sensor.lounge_itrv_large_battery_plus
      - sensor.media_room_thermostat_battery_plus
      - sensor.media_room_itrv_battery_plus
      - sensor.office_thermostat_battery_plus
      - sensor.office_itrv_battery_plus
    exclude_hidden_entities: hidden_enabled
    persistent_notify_message: sensors
    persistent_sensor_selection: enable_all_and_custom_group_sensorstype or paste code here

1 Like

New Update 3.5

Stay Charged, Stay Smart! Customize it your way and let’s automate your battery maintenance! :battery::zap:

:toolbox: Maintenance

Updated the Custom Actions descriptions to recommend using a default value when referencing template variables, preventing template warnings when variables are not yet available.


If you like this blueprint? Consider hitting the :heart: button in the top post :+1:

If you like my blueprints, and would like to show your support or just say thank you? Click Here :smiling_face_with_three_hearts:

Enjoy

Blacky :grinning:

1 Like

Thanks for your work and this great blueprint.

There is just a little thing that bothers me - the length of the UI text, which usually clips information for me. I understand that the limitations are coming from the text helper itself. However in Ltek’s post the output looks much longer than 255 characters. How would be a proper way to achieve this?

Thanks,
Jens

@Jens_82

If your using Easy Notify - Dashboard or Easy Notify - Device then you are limited. In the Easy Notify - UI you can have more and this is what you are seeing.

Easy Notify - Dashboard uses a text helper and that is 255 character limit.
Easy Notify - Device is set by iPhone or android.
Easy Notify - UI is set by Home Assistant no 255 character limit; can contain substantially more text.

Blacky :smiley: