Battery Level Persistent Notification Help

I am trying to create an automation that will fire a Persistent Notification when our phones or my watch drop below 20% battery level remaining. I have created the following but it doesn’t work. Any help would be appreciated.

automation:
  - alias: 'Battery Warnings'
    initial_state: 'on'
    trigger:
      platform: numeric_state
      entity_id:
        - sensor.ring_front_door_battery
        - sensor.wear_pixel_xl_ariela_battery_sensor
        - sensor.pixel_xl_ariela_battery_sensor
        - sensor.iphone_battery_level
        - sensor.emmys_galaxys7
        - sensor.lolas_lgstylo3plus
      below: 20
    action:
      - service: persistent_notification.create
        data_template:
          message: >
            {{ state_attr(trigger.event.data.entity_id, 'friendly_name') }} is below 20%
    initial_state: true

Also, try this if the message is not formatting correctly.

          message: >
            {{trigger.to_state.attributes.friendly_name}} is below 20%

I’m not getting any kind of notification from the automation and the “switch” was showing “on” for it.

image

The automation may be on but initial state was still configured incorrectly.

You battery levels have to drop below 20 to trigger. If they are already below 20 the automation won’t trigger.

I let my watch drop below the threshold but no automation when it hit 19

Weird. I have a very similar automation that works as intended:

- id: fridge_compressor_alert
  alias: 'Fridge Compressor Alert'
  initial_state: true
  trigger:
    platform: numeric_state
    entity_id:
      - sensor.bar_fridge_power
      - sensor.fridge_power
    below: 50
    for:
      hours: 2
  action:
  - service: notify.telegram_system
    data_template:
      title: '*ALERT*'
      message: "The {{trigger.to_state.attributes.friendly_name}} compressor has not turned on in the last 2 hours."
  - service: persistent_notification.create
    data_template:
      message: "{{ now().strftime('%H:%M %A %d %B %Y') }} - The {{trigger.to_state.attributes.friendly_name}} compressor has not turned on in the last 2 hours."
      title: "ALERT"

Have a look in the dev tools states menu. Are the battery levels actually numbers?

Or are they strings like, ‘30%’

Numbers, no % signs or anything else. I’ll play with it some more.

Do you get the notification if you trigger the automation from the developer tools services menu (service = automation trigger or something like that)?

I believe it may be working now. I may a few changes to make it more like yours and when I rebooted I had a notification that the only device currently below 20% was below 20%. We’ll see what happens when one of the others moves below 20.

1 Like

That statement is not correct.

‘on’ is a valid option for “initial_state:”. I use it exclusively.

2 Likes