Do I need a value template to create a low battery automation?

I would like to create automations to alert me when the battery level of certain devices falls below a specified level. I have put together the following:

alias: Battery Low - front door sensor
description: ''
trigger:
  - platform: state
    entity_id: sensor.ewelink_ds01_a670ff22_power
    to: <10
    for: '500'
condition: []
action:
  - service: notify.mobile_app_moto_g_5g_plus
    data:
      title: Alarm sensor battery low
      message: Front Door sensor battery is low
mode: single

…but when I search for examples of battery level alerts I usually see value templates used. Since I don’t know anything about value templates I’d prefer to keep things simple (like the above).
Could anyone advise:

  • would my code above work OK?
  • why I might consider using a value template?

No, it won’t work. Instead, use Numeric State Trigger-

trigger:
  - platform: numeric_state
    entity_id: sensor.ewelink_ds01_a670ff22_power
    below: '10'
    for: '00:08:20'

You can find many battery alert solutions on the forums and these often work without the need to define templates or triggers for every battery sensor meaning that any new sensors you add get included automatically.

This is the one I have been using:

Thanks for the example. I have 2 questions:

  1. Will the numeric state trigger work if the value is a string (which it appears to be)
  2. Was a particular reason for choosing ‘00:08:20’ for the “for” value?

Yes it will. Follow the example in the documentation on how to write it properly.

It simply converts your 500 seconds to minutes and seconds.