Can't figure out how to use an ELSE statement to simplify automations

I believe this should work:

trigger:
  - platform: state
    entity_id:
      - person.user1
    to: home
    for:
      hours: 0
      minutes: 5
      seconds: 0
    id: home
  - platform: state
    entity_id:
      - person.user1
    to: not_home
    for:
      hours: 0
      minutes: 5
      seconds: 0
    id: not_home
  - platform: time
    at: "23:00:00"
    id: time_off
  - platform: time
    at: "06:00:00"
    id: time_on
condition: []
action:
  - if:
      - condition: state
        entity_id: person.user1
        state: home
      - condition: time
        after: "06:00:00"
        before: "23:00:00"
      - condition: or
          - conditions:
            - condition: trigger
              id: time_on
            - condition: trigger
              id: home
	then:
      - service: switch.turn_on
        data: {}
        target:
          entity_id: switch.bad_light
    else:
      - service: switch.turn_off
        data: {}
        target:
          entity_id: switch.bad_light
mode: single
1 Like