Help with Sensor Low Battery Notification

Has anybody had any luck creating low battery notifications for these Wyze sensors? I’m new to the automations side of Home Assistant, but everything looks OK to me. Would appreciate any help I can get with this.

sensor.yaml

- platform: template
  sensors:
    wy_back_door:
      friendly_name: 'Back Door'
      value_template: "{{ state_attr('binary_sensor.wyzesense_777ea166', 'battery_level') }}"
      unit_of_measurement: '%'
      device_class: battery

automations.yaml

  - alias: Back Door Battery Low
    trigger:
      platform: numeric_state
      entity_id: sensor.wy_back_door
      below: 98
    action:
      service: notify.ios_justiniphone
      data:
        title: "Back Door Battery Low"
        message: "Back Door Sensor has > 5% Battery"

Sensor Information

1 Like

If the value was already below 98 before you started the automation it wont trigger. It will only trigger when going from above 98 to below.

Not really answering the question that you asked but there is another solution.

Another user came up with system that works really well to create sensirscautomatically for all entities that have a battery attribute. And it can be set to send a notification when any battery gets below a selected setpoint.

Here is the repo for it:

It actually works slightly differently than that.

It’s true that at startup, even if the condition is met, it won’t trigger. But that’s not why it won’t trigger. It won’t trigger until the entity’s state changes. When the entity’s state first changes, if the condition is then met, it will trigger, even if it did not change from above the threshold to below it.

However, once it has triggered, then it will not trigger again until the condition is no longer met (in this case changes to a value greater than or equal to 98), and then is met again (changes to a value less than 98.)

If you want this automation to trigger at startup if the sensor has a value less than 98, then you could do that by adding another trigger and a condition:

  - alias: Back Door Battery Low
    trigger:
    - platform: numeric_state
      entity_id: sensor.wy_back_door
      below: 98
    - platform: homeassistant
      event: start
    condition:
      condition: numeric_state
      entity_id: sensor.wy_back_door
      below: 98
    action:
      service: notify.ios_justiniphone
      data:
        title: "Back Door Battery Low"
        message: "Back Door Sensor has > 5% Battery"

Note, however, if that first state change results in another value below 98 it will trigger again. I.e., if at startup it’s, say 97. This will cause the automation to trigger (via the second trigger.) Now say it drops to 96. This will cause it to trigger again (this time via the first, original trigger.) Now it won’t trigger again until it rises to 98 or above, and then either drops below 98, or HA restarts while it’s less than 98.