🪫 Low Battery Notifications & Actions

@Ks2

I can see your entity has a device class battery. What state does it show?

Normally these binary_sensors will report low or OK or ON = low battery, OFF = battery OK. When your battery becomes ON or low it will be shown in the automation report. If you go into developer tools → states and search for your binary_sensor.driveway_battery you will see the state. If you click on it, it will then show you the current state. You can then change the state to on or low (lower case) and click Set State. Then trigger the automation again. You will then see it show up in your report.

Blacky :grinning:

Is it just me or does Custom Actions still get triggered even when there are no low batteries? I have mine set to send an email with the following message. How do I disable this action if there are no low batteries?

{{all_sensors|replace('@ ', '(')|replace('is ', '(')|replace(', ', ')\n')}}

@Sireone

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 :grinning:

Sure thing. Here ya go…

alias: Low Battery Notifications & Actions
description: ""
use_blueprint:
  path: Blackshome/low-battery-notifications-and-actions.yaml
  input:
    include_button: enable_button_trigger
    time: "06:30:00"
    include_time: time_enabled
    exclude_sensors:
      entity_id:
        - sensor.carlyle_hr_1974_battery_level
        - sensor.pixel_7_battery_level
        - sensor.pixel_8_pro_battery_level
        - binary_sensor.front_door_lock_replace_battery_now
    exclude_hidden_entities: hidden_enabled
    include_easy_notify: enable_easy_notify
    notify_device:
      - 21d548611ede61ddbec1db4b179fcb1b
    button_entity: input_button.battery_status
    include_custom_actions: enable_custom_actions
    custom_actions:
      - action: notify.email
        metadata: {}
        data:
          message: >-
            {{all_sensors|replace('@ ', '(')|replace('is ', '(')|replace(', ',
            ')\n')}}
          title: Home Assistant - Low Battery

@Sireone

Thanks for your YAML.

It will trigger even though there are no batteries to report. What you need to do is within your custom end action you need to build a if , then action. So if there are batteries to report then send email if none then do nothing and skip.

Point 7 in this FAQ will show you how to do it, click here

Blacky :grinning:

That worked! Thanks much!

1 Like

If I have multiple actions, do they get executed sequentially? I’m trying to get an AI response into a variable and then use that in the notification,

Here’s the config I’m using:

alias: Low battery Notification
description: ""
use_blueprint:
  path: Blackshome/low-battery-notifications-and-actions.yaml
  input:
    include_time: time_disabled
    time: "10:45:00"
    weekday_options:
      - mon
      - tue
      - wed
      - thu
      - fri
    include_easy_notify: disabled_easy_notify
    custom_actions:
      - action: ai_task.generate_data
        metadata: {}
        data:
          instructions: >-
            You are Alfred Pennyworth (Michael Caine version, from the Nolan
            Batman trilogy). Give me a one-sentence notification for Master
            Grimshaw that there are batteries that need replacing. Be wise, a
            bit dry, and stay in character.
          task_name: Generate notification
        response_variable: alfred_response
      - action: assist_satellite.announce
        metadata: {}
        data:
          message: "{{ alfred_response.data }}"
          preannounce: true
    include_button: enable_button_trigger
    button_entity: input_button.check_low_battery

but in the logs I’m getting an error:

Logger: homeassistant.components.automation.low_battery_notification
Source: components/automation/__init__.py:724
integration: Automation (documentation, issues)
First occurred: 10:45:00 (3 occurrences)
Last logged: 10:59:42

Error rendering variables: UndefinedError: 'alfred_response' is undefined

Is it trying to render the response too early?

Hello! Please help, how send notification to telegram bot? thanks.

@Stubbs

So the message is undefined when the blueprint runs. I don’t use AI so that is my disclaimer if it not right but try this…

alias: Low battery Notification
description: ""
use_blueprint:
  path: Blackshome/low-battery-notifications-and-actions.yaml
  input:
    include_time: time_disabled
    time: "10:45:00"
    weekday_options:
      - mon
      - tue
      - wed
      - thu
      - fri
    include_easy_notify: disabled_easy_notify
    custom_actions:
      - action: ai_task.generate_data
        data:
          instructions: >
            You are Alfred Pennyworth (Michael Caine version, from the Nolan
            Batman trilogy). Give me a one-sentence notification for Master
            Grimshaw that there are batteries that need replacing. Be wise, a
            bit dry, and stay in character.
          task_name: Generate notification
        response_variable: alfred_response
      - variables:
          alfred_message: "{{ alfred_response.response.text | default('Batteries require attention, sir.') }}"
      - action: assist_satellite.announce
        data:
          message: "{{ alfred_message }}"
          preannounce: true
    include_button: enable_button_trigger
    button_entity: input_button.check_low_battery

Blacky :grinning:

@fishboooone

By using the custom actions.

Blacky :grinning:

Unfortunately not, I get the same error, I suspect when it’s trying to evaluate it in the variables section.

@Stubbs

Maybe I should of read the Home Assistant documentation first, click here. Again I don’t use AI so that is my disclaimer if it not right but try this…

      - action: ai_task.generate_data
        data:
          task_name: "Generate notification"
          instructions: >-
            You are Alfred Pennyworth (Michael Caine version, from the Nolan
            Batman trilogy). Give me a one-sentence notification for Master
            Grimshaw that there are batteries that need replacing. Be wise, a
            bit dry, and stay in character.
        response_variable: alfred_response
      - variables:
          alfred_message: >-
            {{ alfred_response.data if alfred_response is defined else
            'Batteries require attention, sir.' }}
      - action: assist_satellite.announce
        data:
          message: "{{ alfred_message }}"
          preannounce: true

Blacky :grinning:

Took me awhile to find this and learn how to use the ā€œhiddenā€ option. I think it would be helpful to add it to the FAQ or other documentation in that first post.

@mlindstrom

Yea I know, Home Assistant has so many options. Thanks for your suggestion.

Blacky :grinning:

FAQ - How to hide a battery

Go into settings / devices & services / click on the entities tab at the top and search for your batteries. Click on the entity you would like to hide and then select the cog wheel

Deselect the visible option and update it. Your battery will now be hidden.

Enjoy

Blacky :grinning:

Back to FAQ: Click Here

1 Like

This Blueprint is a real time saver! Nicely done! Curious if notify groups are under consideration? I know you’ve said you don’t use them previously, so it makes sense they aren’t in there :slight_smile: My use case is like others have mentioned. I bounce around phones quite a bit so I don’t want to use a generic entity for my phone. Using a group makes it super easy to only have to make one change when I swap phones and everything keeps on working. Thanks for considering, thanks for the cool-ass tools you provide!

@RVoodoo

I would do it if HA made a group helper. When I try to make this helper group I can never select an entity to notify.

How do you make a group… the old way in YAML?

Blacky :grinning:

I’m seeing the same thing, everything works and reports OK. It’s more of a nuisance log than anything. Did you ever find a cause/remedy?

nothing is working when i run this blueprint. i’m using device notification to phones and conversation process for tts

alias: Low Batteries
description: ""
use_blueprint:
  path: Blackshome/low-battery-notifications-and-actions.yaml
  input:
    weekday_options:
      - wed
      - mon
      - fri
      - sun
      - sat
    time: "19:10:00"
    include_time: time_enabled
    custom_group:
      entity_id:
        - sensor.front_door_battery_level
        - sensor.fold_7_battery_level
        - sensor.node_19_battery_level
        - sensor.foyer_smoke_battery_level
        - sensor.galaxy_watch_ultra_battery_level
        - sensor.guest_smoke_battery_level
        - sensor.guest_window_battery_level
        - sensor.zcombo_g_smoke_co_alarm_battery_level
        - sensor.keypad_v2_battery_level
        - sensor.kitchen_door_battery_level
        - sensor.kitchen_window_battery_level
        - sensor.laura_s_iphone_battery_level
        - sensor.left_master_battery_level
        - sensor.master_smoke_battery_level
        - sensor.right_master_battery_level_2
        - sensor.left_office_battery_level
        - sensor.middle_office_battery_level
        - sensor.office_smoke_battery_level
        - sensor.right_office_battery_level
        - sensor.barn_door_battery_level
        - sensor.left_window_battery_level
        - sensor.middle_window_battery_level
        - sensor.right_window_battery_level
        - sensor.open_close_xs_sensor_battery_level_5
        - sensor.ac_drain_battery
        - sensor.hue_motion_sensor_1_battery
        - sensor.hue_dimmer_switch_1_battery
        - sensor.guest_bathroom_sink_battery
        - sensor.guest_bathroom_toilet_battery
        - sensor.blind_tilt_5a0e_battery
        - sensor.curtain_3_52b1_battery
        - sensor.curtain_3_216e_battery
        - sensor.dishwasher_battery
        - sensor.kitchen_sink_battery
        - sensor.refrigerator_battery
        - sensor.washing_machine_battery
        - sensor.master_bath_sink_battery
        - sensor.master_bath_toilet_battery
        - sensor.blind_tilt_53c1_battery
        - sensor.blind_tilt_bda4_battery
        - sensor.hue_dimmer_switch_2_battery
        - sensor.master_bedroom_battery
        - sensor.office_battery
        - sensor.cutoff_valve_battery
        - sensor.drain_down_valve_battery
        - sensor.laura_s_iphone_watch_battery_level
    include_easy_notify: enable_easy_notify
    sensor_selection: enable_battery_sensors_custom_group
    notify_device:
      - 3227ffd8fc39183b377ab061201ddf5a
      - afc0e402a7f50b4d3aea6f7fa1fe9c44
    notify_message: sensors
    notify_interruption_level: critical
    notify_data:
      - high_priority
    include_custom_actions: enable_custom_actions
    custom_actions:
      - if:
          - condition: template
            value_template: "{{ not all_sensors == '' }}"
        then:
          - action: media_player.volume_mute
            metadata: {}
            target:
              entity_id: media_player.arc_ultra
            data:
              is_volume_muted: true
          - action: conversation.process
            metadata: {}
            data:
              text: >-
                You seem to have low batteries, here they are "{{sensors_names_custom_group}}"
              agent_id: conversation.ollama_conversation_2
            response_variable: response1
          - action: assist_satellite.announce
            metadata: {}
            target:
              entity_id: assist_satellite.voice_pe_assist_satellite
            data:
              message: "{{ response1.response.speech.plain.speech}}"
              preannounce: false
      - if:
          - condition: template
            value_template: "{{ all_sensors == '' }}"
        then:
          - action: media_player.volume_mute
            metadata: {}
            target:
              entity_id: media_player.arc_ultra
            data:
              is_volume_muted: true
          - action: conversation.process
            metadata: {}
            data:
              text: Im not seeing any low batteries, your all good to go
              agent_id: conversation.ollama_conversation_2
            response_variable: response2
          - action: assist_satellite.announce
            metadata: {}
            target:
              entity_id: assist_satellite.voice_pe_assist_satellite
            data:
              message: "{{ response2.response.speech.plain.speech}}"
              preannounce: false

i get this error in the logs. not even a phone notification comes though

Logger: homeassistant.helpers.template
Source: helpers/template/init.py:1757
First occurred: 6:51:00 PM (6 occurrences)
Last logged: 7:10:00 PM

  • Template variable warning: ā€˜sensors_names_custom_group’ is undefined when rendering ā€˜You seem to have low batteries, here they are {{sensors_names_custom_group}}’
  • Template variable error: ā€˜response’ is undefined when rendering ā€˜{{ response1.response.speech.plain.speech}}’
  • Template variable warning: ā€˜sensors_names_custom_group’ is undefined when rendering 'You seem to have low batteries, here they are "{{sensors_names_custom_group}}

After completely DELETING the custom actions entirely and leaving only the phone notifications, the blueprint would run fine without issue. something is broke here. doesn’t matter if you use conversation.process, ai task, any form of it in the custom actions that pulls the sensor information breaks it. Yea i’ve been doing testing. the blueprint is not passing any sensor information to the custom actions at all if it uses any form of ai to process. I wonder if this is somehow a limitation in the blueprint structure itself. i have noticed this same issue in your calender blueprint aswell as i was forced to use normal tts.