đŸȘ« Low Battery Notifications & Actions

Love the blueprint, thank you!

Two FRs:

  • Is there any chance labels could be added for exclude support? I have a bunch of extra entities and it would be nice to have one way to mark them as excluded
  • Notification Groups: I try to use groups as a layer of indirection between automations and devices. Otherwise when anyone in my family upgrades phones I have to go and find/find every automation that sends notifications to use the new device.

@Master_Nick

Hi Nick, can you provide me a snap shot of your batteries entities in developer tools. Below is an example of my fridge battery.

Blacky :smiley:

@EricD183

I am going to look into labels. I don’t really use them as it just looked like more work to me. Example if I needed to see what is excluded I have to go and edit the labels when I can just do it directly in the automation.

This is similar to labels as I don’t use groups. I just like to see who is getting notified in the automation.

I will however put them onto the list of suggestions. Thanks for reaching out.

Blacky :smiley:

1 Like

@Blacky thanks for the reply :slight_smile:

My would be:

@Master_Nick

All of your batteries have a “device_class: battery” with the exception of 2. So it should find most of them.

The default “Battery Low Warning Level” is 20% and “Low”. All you batteries are above 20% so try setting your “Battery Low Warning Level” to 100% and all your batteries should be shown. Then adjust it back to the % you would like.

The other 2 that show a state of OK may not be shown. If you click on the green “choose entity” it should show you all the batteries is will find. See if the 2 batteries are shown in the list when you click the green “choose entity”.

If your still having problems and need help then could you please provide us your YAML of the automation? This YAML code are the settings you have selected in the automation so I can help. 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:

Hey :wink:

I tried exactly that for testing and set the warning level to 97% :smiley: So that each and every battery should be included. It just keeps saying no battteries found.

Thanks for time and work in advance :slight_smile:

alias: Low Battery Notifications & Actions
description: ""
use_blueprint:
  path: Blackshome/low-battery-notifications-and-actions.yaml
  input:
    include_button: enable_button_trigger
    include_time: time_enabled
    time: "13:00:00"
    weekday_options:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
    battery_level: 98
    notify_device:
      - 89d1557689d6a388fb8190b97c2d29fd
    button_entity: input_button.batterycheck
    custom_group_battery_level: 20

From Traces after pushin the helper button:

choose:
  - alias: Use the easy notify options
    conditions:
      - condition: template
        value_template: >-
          {{ (include_easy_notify == 'enable_easy_notify') or
          (include_easy_notify == 'enable_easy_okay_notify') }}
      - condition: template
        value_template: '{{ notify_device | length > 0 }}'
    sequence:
      - alias: Send a notification to each device
        repeat:
          for_each:
            - 89d1557689d6a388fb8190b97c2d29fd
          sequence:
            - choose:
                - alias: Sensors have been found
                  conditions:
                    - '{{ easy_notify_message != '''' }}'
                  sequence:
                    - choose:
                        - alias: Easy notify with no action button
                          conditions:
                            - >-
                              {{ notify_action_buttons ==
                              'disabled_notify_action_buttons' }}
                          sequence:
                            - service: >-
                                notify.mobile_app_{{ device_attr(repeat.item,
                                'name') | slugify }}
                              data:
                                title: Low Battery Notification
                                message: '{{easy_notify_message}}'
                                data:
                                  sticky: 'true'
                        - alias: Easy notify with action button
                          conditions:
                            - >-
                              {{ notify_action_buttons !=
                              'disabled_notify_action_buttons' }}
                          sequence:
                            - service: >-
                                notify.mobile_app_{{ device_attr(repeat.item,
                                'name') | slugify }}
                              data:
                                title: Low Battery Notification
                                message: '{{easy_notify_message}}'
                                data:
                                  sticky: 'true'
                                  actions:
                                    - action: '{{ action_button_to_do }}'
                                      title: Add To To-Do List!
                                    - action: '{{ action_button_cancel }}'
                                      title: Cancel
                - alias: No sensors have been found
                  conditions:
                    - '{{ easy_notify_message == '''' }}'
                    - '{{ include_easy_notify == ''enable_easy_okay_notify'' }}'
                  sequence:
                    - service: >-
                        notify.mobile_app_{{ device_attr(repeat.item, 'name') |
                        slugify }}
                      data:
                        title: Low Battery Notification
                        message: YES! All batteries are okay :)
                        data:
                          sticky: 'true'

@Master_Nick

Thanks Nick

Please enable the device so you will get notified. Below shows a red arrow. This will allow a confirmation message. The option above will not send the confirmation message. A confirmation message is when all your batteries are OK and it just lets you know that.

The green box option is if you would also like to receive a UI notification. Play around with it and see how it works.

Let us know how you go.

Blacky :smiley:

Hi @Blacky,

Thanks for sharing and maintaining this blueprint, very useful.

I have problems with getting notifications for unavailable sensors. I am using the custom actions to send an email with the smtp notification. In the email body I am using the variable {{unavailable_sensors_names}}. The difference in my situation is that my battery sensors all are binary_sensor and not just sensor, this apparently affects the outcome.

I was troubleshooting and had a look at the code in the blueprint, at /config/blueprints/automation/Blackshome/low-battery-notifications-and-actions.yaml

I fiddled around with below templating code for "unavailable_sensors_names:" in the Developer tools template editor

    unavailable_sensors_names: "{% set low_battery = namespace(sensors=[]) %} {% for
    state in states.sensor | rejectattr('attributes.device_class', 'undefined') |
    selectattr('attributes.device_class', '==', 'battery') %}\n  {% if \"unavailable\"
    in state | string and not state.entity_id in exclude_sensors.entity_id %}\n    {%
    set low_battery.sensors = low_battery.sensors + [state.name] %}\n  {% endif %}\n{%
    endfor %} {{low_battery.sensors |sort(attribute='battery_level') | join(', ')}}"

I noticed that when I change states.sensor in states.binary_sensor in the blueprint yaml for unavailable_sensors_names I had success and the email contained the unavailable sensors. So I noticed that for binary sensors with state unavailable it won’t work as I expected. When the binary sensor is available it does work.

Maybe it’s unusual to have binary sensors for batteries instead of sensors?

@Johanf

Thanks for reaching out. It looks like it was an oversight on my part. I needed to create a binary_sensor for testing, as all my current ones are sensors, and I must have forgotten to test the unavailable state for binary_sensor. My bad :pensive:

I appreciate you letting me know! :+1:

I will update the blueprint soon to fix all sensors. I will test it on my end, but if you could be so kind to let me know if it is working correctly in a real live test, I would greatly appreciate it.

Blacky :smiley:

1 Like

New Update 2.4

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

Bugs Fixes :bug:

  • Fixed bug that binary_sensor would not report an unavailable state.

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

I updated to version 2.4 and it now works correctly for me. Thanks for the quick reply and great that you already modified it.

@Johanf

Thanks for testing it and letting us know :+1:

Enjoy

Blacky :smiley:

Hello Blacky.

Thanks for you low battery automation, and could you help me understand a message that I am receiving as a notification:

Low Battery Notification
Battery is unavailable!

image

Does this mean that a device that has a battery is now not available or that a device that once had a battery entity no longer has a battery entity? Is there a way to find out which device/entity is this message relates to so that I can possibly put it into the excluded group?

Thanks,
Rex

@rexmundi

Welcome to the community.

When an entity becomes unavailable it means that HA has seen it before and now it cant see it. It could be the battery is flat and it is not working or you don’t use it anymore but HA still is looking for it.

Go to settings > devices and services > entities tab at top > in the search type “battery” as that is the name of your entity. You will see it and then you can decide what to do with it. If you are going to keep it, maybe use a better friendly name for your entity.

PS: Better to decide what you want to do with the entity rather than just excluding it as you will keep your HA clean.

Blacky :smiley:

1 Like

Thanks a heap for your guidance Blacky. I am still coming to terms with HASS Device/Entity structure and naming, but your suggestion lead me straight to the ‘Battery’.

@rexmundi

No problem at all, your welcome. The more you use it the easier it will be.

To change the friendly name once you find the entity click on it then click on the cog wheel and you will see “Name” this is were you can change the friendly name. Click Here for the FAQ on it.

Enjoy

Blacky :smiley:

Aaaand it works :smiley:
:sweat_smile: :sweat_smile:

THANK YOU for your help!

1 Like

I have been using this Blueprint for a few weeks. I did not notice this before. But after upgrading to 2024.7 I ran Watchman. It says I am missing two services mentioned by this Blueprint. One is notify.mobile_app_ and the other is todo.add_item. Is there something I need to do to make sure these services are installed? Thanks. Great Blueprint.

@michaelwacey

I haven’t updated to the new version of HA yet.

Could you please provide us your YAML of the automation? This YAML code are the settings you have selected in the automation so I can try and recreate what is happening. 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:

Here you go. Thanks again for a great Blueprint.

alias: Low Battery Notifications & Actions
description: ""
use_blueprint:
  path: Blackshome/low-battery-notifications-and-actions.yaml
  input:
    include_time: time_enabled
    include_easy_notify: enable_easy_notify
    notify_device:
      - a4eef1061318fce03e718bc98a00bb8f
    exclude_sensors:
      entity_id:
        - sensor.basement_sensor_battery
    include_persistent_notification: enable_persistent_notification