Phone battery detector

Hi, I want to create an automation that HomeAssistant is able to detect and run a script when the battery drops below 20%, does anyone know how to help me?

For now my automation is like this

- id: '1645801954360'
  alias: test
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.sm_g965f_livello_della_batteria
    attribute: state_class
    from: 20%
  condition: []
  action:
  - service: script.batteria_cellulare_scarica_flash
    data: {}
  mode: single

In the trigger use “numeric_state” instead of “state” and “Below 20”.

1 Like

On a larger scale …
In HACS there is something ‘battery state card’
And there is also a blueprint: “Blueprint to use Low battery level detection & notification for all battery sensors”…this one you could adapt easily as well

- id: '1645801954360'
  alias: test
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.sm_g965f_livello_della_batteria
    below: 20
  condition: []
  action:
  - service: script.batteria_cellulare_scarica_flash
    data: {}
  mode: single