In a previous post I outlined how I used Node-RED to automate my phone to stop charging at 80% to protect it’s battery.

Since then I have implemented the same task using Home Assistant Automations out of curiosity. I was able to configure it all from the UI editor. I needed to create 2 separate automations to complete the task, one to stop charging at 80% and one to start charging at 60% or lower. If I edited the yaml code directly I would be able to complete in one automation but for something this simple I didn’t see the need.

Below are the auto generated entries added to automations.yaml by the UI:

- id: '1596807'
  alias: Phone Charger - On
  description: ''
  trigger:
  - above: '0'
    below: '60'
    entity_id: sensor.sm_g970f_battery_level
    for: 00:00:01
    platform: numeric_state
  condition: []
  action:
  - data: {}
    entity_id: switch.sonoff_100065d446
    service: switch.turn_on
  mode: single
- id: '1596808'
  alias: Phone Charger - Off
  description: ''
  trigger:
  - above: '80'
    below: '100'
    entity_id: sensor.sm_g970f_battery_level
    for: 00:00:01
    platform: numeric_state
  condition: []
  action:
  - data: {}
    entity_id: switch.sonoff_100065d446
    service: switch.turn_off
  mode: single