Simple time-based Switch On, Switch Off with built in (non-YAML) automation

Hello, I am migrating from ISY. I looked in the Community and all I find are YAML solutions. Is there a simple way, using the built in automations, to say:
From Time X to Time Y, turn on.
Else, turn off
Thanks.

That’s because it’s efficient, editable, and portable… you can literally copy it from here and paste it into the Automation Editor.

Unlike some other systems, automations in HA are event-driven. Just “being” between two times is not an event, so there’s no single trigger that covers “From Time X to Time Y”. You have to break it down and set triggers to cover all the events.

Here is one option on how to do that:

triggers:
  - id: 'on'
    trigger: time
    at: "08:00:00"
  - id: 'off'
    trigger: time
    at: "22:00:00"
  - id: restart
    trigger: homeassistant
    event: start
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: 
              - "on"
              - restart
          - condition: time
            after: "8:00:00"
            before: "23:00:00"
        sequence:
          - action: switch.turn_on
            target:
              entity_id: switch.example 
      - conditions:
          - condition: trigger
            id: 
              - "off"
              - restart
          - condition: time
            after: "23:00:00"
            before: "8:00:00"
        sequence:
          - action: switch.turn_off
            target:
              entity_id: switch.example
If you want the switch to turn back on immediately if it's turned off during 'on' hours and vice versa, you would add triggers for those event too.
triggers:
  - id: 'on'
    trigger: time
    at: "08:00:00"
  - id: 'off'
    trigger: time
    at: "22:00:00"
  - id: restart
    trigger: homeassistant
    event: start
  - id: 'on'
    trigger: state
    entity_id: switch.example
    to: 'off'
  - id: 'off'
    trigger: state
    entity_id: switch.example
    to: 'on'
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: 
              - "on"
              - restart
          - condition: time
            after: "8:00:00"
            before: "23:00:00"
        sequence:
          - action: switch.turn_on
            target:
              entity_id: switch.example 
      - conditions:
          - condition: trigger
            id: 
              - "off"
              - restart
          - condition: time
            after: "23:00:00"
            before: "8:00:00"
        sequence:
          - action: switch.turn_off
            target:
              entity_id: switch.example
1 Like

This is terrific…thank you! I am testing it out this evening.