Battery notify automation trigger

Hi!
I have some aqara devices on batteries and have this automation:

- id: '1259372459853'
  alias: Low battery notification_2
  initial_state: 'on'
  trigger:
  - platform: numeric_state
    entity_id:
    - sensor.xi_main_door_battery
    - sensor.xi_pir_hall_battery
    - sensor.xi_pir_wc_battery
    - sensor.xi_smoke_battery
    - sensor.xi_temp1_battery
    - sensor.xi_temp2_battery
    - sensor.xi_water_battery
    - sensor.xi_wc_door_battery
    - sensor.xi_window_battery
    - sensor.xi_pir_master_battery
    below: 36
  action:
  - service: persistent_notification.create
    data_template:
      title: Низкий уровень заряда
      message: Ваш {{ trigger.to_state.name|default("unknown") }} разрядился до 35%
  - service: notify.ios_argo
    data_template:
      title: Низкий уровень заряда
      message: Ваш {{ trigger.to_state.name|default("unknown") }} разрядился до 35%

But battery state can do this

16

Which will trigger automation a number of times. And I do not need that. How can I handle this?

And second question about platform: numeric_state, below:

I was testing my UPS and it went from 25% to 9%. Automation was nat triggered (below 21%). How does “below” work? Should it go exactly from 21% to 20%, or from 21% to lower number? I thought that it should work even if 25% goes to 9%.
If not - all my batteries automation seems to be useless.

According to the documentation for numeric_state trigger, you can use a for to specify a time duration. I believe you can use this to indicate you want the numeric-state to be below 36 for at least 15 minutes before it, qualifies as a valid trigger event.

    for:
      minutes: 15

In other words, the automation will not be triggered the moment the battery level drops below 36%. The level must fall below 36 and stay below that level for at least 15 minutes before it triggers the automation. Full disclosure: I have not tried for with below so I can’t confirm if it works.

1 Like

It’s worked for me where I’ve used it.

Thanks. Actually, I know about that. But I will need not 10-15 mins. It should be like couple of hours. Isn’t it a bit “bad code”? Will it work fine if I will set 2-3 hours?
May be I am asking silly questions, just wanna be sure that it will not make any harm to system stability.
I know that there are issues with “delay”. That is why I am a bit worried.

Hours? A device whose battery status measurement is so unreliable that it must persist for hours before it can be considered to be valid?

If this was happening to me I’d conclude the device is either defective or its battery-status reporting is unusable.

I do not know about all xiaomi sensors, but two of them can fluctuate

Can anyone help with second question about platform: numeric_state, below:

I was testing my UPS and it went from 25% to 9%. Automation was nat triggered (below 21%). How does “below” work? Should it go exactly from 21% to 20%, or from 21% to lower number? I thought that it should work even if 25% goes to 9%.
If not - all my batteries automation seems to be useless.

Hi. I had strangly triggered automation.


Automation was triggered:

- id: '1259372459853'
  alias: Low battery notification_2
  initial_state: 'on'
  trigger:
  - platform: numeric_state
    entity_id:
    - sensor.xi_main_door_battery
    - sensor.xi_pir_hall_battery
    - sensor.xi_pir_wc_battery
    - sensor.xi_smoke_battery
    - sensor.xi_temp1_battery
    - sensor.xi_temp2_battery
    - sensor.xi_water_battery
    - sensor.xi_wc_door_battery
    - sensor.xi_window_battery
    - sensor.xi_pir_master_battery
    below: 36
    for:
      minutes: 15
  action:
  - service: persistent_notification.create
    data_template:
      title: Низкий уровень заряда
      message: Ваш {{ trigger.to_state.name|default("unknown") }} разрядился до 35%
  - service: notify.ios_argo
    data_template:
      title: Низкий уровень заряда
      message: Ваш {{ trigger.to_state.name|default("unknown") }} разрядился до 35%

But it should not… As you can see, Home Assistant is waiting for getting battery below 36. But it was 29-27. Why should it trigger?