Tips on how to combine automations

Greetings
I realise I still have issues with how to do advanced stuff with Home Automation and need som pointers. I have two automations set to turn on and off a switch, switch.aux1, based on the state of a drop-down helper input_select.leakomatic which can be either Home or Away. I know I’ve passed this subject when googling or maybe I’m just tired but I suspect these two automations can be “made” into one using templating or something like that. I just don’t know how.

  alias: Leakomatic Away
  trigger:
  - platform: state
    entity_id: input_select.leakomatic
    to: Away
  action:
  - service: switch.turn_on
    target:
      entity_id: switch.aux1


  alias: Leakomatic Home
  trigger:
  - platform: state
    entity_id: input_select.leakomatic
    to: Home
  action:
  - service: switch.turn_off
    target:
      entity_id: switch.aux1

Regards
Fredrik

Can you try this? Using choose option as well as trigger id and trigger condition - which the latter two are only available if you are on 2021.7+

alias: New Automation
description: ''
mode: single
trigger:
  - platform: state
    entity_id: input_select.leakomatic
    to: Home
    id: Home
  - platform: state
    entity_id: input_select.leakomatic
    to: Away
    id: Away
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Home
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.aux1
      - conditions:
          - condition: trigger
            id: Away
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.aux1
    default: []

OR

alias: New Automation
description: ''
mode: single
trigger:
  - platform: state
    entity_id: input_select.leakomatic
condition: []
action:
  - service: >-
      switch.turn_{{'on' if trigger.to_state.state == 'Away' else 'off'}}
    target:
      entity_id: switch.aux1

Edit: too slow :frowning:

  alias: Leakomatic
  trigger:
  - platform: state
    entity_id: input_select.leakomatic
  action:
  - service: "switch.turn_{{ 'on' if trigger.to_state.state == 'Away' else 'off' }}"
    target:
      entity_id: switch.aux1