Combine these automations into one?

Have a wall display and Id like to limit the charging cycles between on@<25% and off@>80% battery level.
Currently I have two automation (one for turning on charger, second for turning off) because wait for does not survive a HA reboot. Is there a better way??

Still green and I’d appreciate any help or advice. Thanks for your time!

On Automation

alias: 5v Power Kitchen Display - ON
description: Turns on charger on at <25% battery
trigger:
  - platform: numeric_state
    entity_id: sensor.kitchen_display_battery_level
    below: '25'
    attribute: ''
condition:
  - condition: device
    type: is_off
    device_id: 5c9a9f95cde6d211c23f97b4f40b54f3
    entity_id: switch.5vpower_kitchen_display
    domain: switch
action:
  - service: switch.turn_on
    data: {}
    target:
      device_id: 5c9a9f95cde6d211c23f97b4f40b54f3
mode: single

Off Automation

alias: 5v Power Kitchen Display - OFF
description: Turns off charger at >80% battery
trigger:
  - platform: numeric_state
    entity_id: sensor.kitchen_display_battery_level
    attribute: ''
    above: '80'
condition:
  - condition: device
    type: is_on
    device_id: 5c9a9f95cde6d211c23f97b4f40b54f3
    entity_id: switch.5vpower_kitchen_display
    domain: switch
action:
  - service: switch.turn_off
    data: {}
    target:
      device_id: 5c9a9f95cde6d211c23f97b4f40b54f3
mode: single

The most compact method is to use a template, but another option would be to use an If/then or Choose action.

Using templating:

alias: "5v Power Kitchen Display - ON/OFF"
description: "Turns on charger on at <25% battery and off at >80%"
trigger:
  - platform: numeric_state
    entity_id: sensor.kitchen_display_battery_level
    below: '25'
    id: 'on'
  - platform: numeric_state
    entity_id: sensor.kitchen_display_battery_level
    above: '80'
    id: 'off'
condition: []
action:
  - service: switch.turn_{{trigger.id}}
    data: {}
    target:
      device_id: 5c9a9f95cde6d211c23f97b4f40b54f3
mode: single

Using If/Then:

alias: "5v Power Kitchen Display - ON/OFF"
description: "Turns on charger on at <25% battery and off at >80%"
trigger:
  - platform: numeric_state
    entity_id: sensor.kitchen_display_battery_level
    below: '25'
    id: 'on'
  - platform: numeric_state
    entity_id: sensor.kitchen_display_battery_level
    above: '80'
    id: 'off'
condition: []
action:
  - if:
      - condition: trigger
        id: 'on'
    then:
      - service: switch.turn_on
        data: {}
        target:
          device_id: 5c9a9f95cde6d211c23f97b4f40b54f3
    else:
      - service: switch.turn_off
        data: {}
        target:
          device_id: 5c9a9f95cde6d211c23f97b4f40b54f3
mode: single
1 Like

Untested but I believe it will work.

alias: 5v Power Kitchen Display 
description: Turns on/off charger on at <25% or >80% battery
trigger:
  - platform: numeric_state
    entity_id: sensor.kitchen_display_battery_level
    below: '25'
    attribute: ''
    id: turn_on

  - platform: numeric_state
    entity_id: sensor.kitchen_display_battery_level
    above: '80'
    attribute: ''
    id: turn_off
condition:

action:
  - service: "switch.{{ trigger.id }}"
    data: {}
    target:
      device_id: 5c9a9f95cde6d211c23f97b4f40b54f3
mode: single
1 Like

Sorry slow reply, thanks for your help!
I’ve avoided learning templates, but it looks like I cant avoid it any longer…

Templates… aghhh :exploding_head: