Automation to turn ON/OFF devices at different times/days

I have lights that I want turn on from 6 pm to 9 pm Sunday to Thursday and from 7 pm to 11 pm Friday and Saturday. What is the best way to create this automation ?

You could do it all in one automation with a choose action.

trigger:
  - platform: time
    at: 
      - "18:00:00"
      - "19:00:00"
    id: "turn_on"
  - platform: time
    at: 
      - "21:00:00"
      - "23:00:00"
    id: "turn_off"
action:
  - choose:
      - conditions:
          - condition: trigger
            id: "turn_on"
          - condition: or
            conditions:
              - condition: time
                after: "18:00:00"
                before: "19:00:00"
                weekday:
                  - sun
                  - mon
                  - tue
                  - wed
                  - thu
              - condition: time
                after: "19:00:00"
                weekday:
                  - fri
                  - sat
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.your_light  ### change this ###
      - conditions:
          - condition: trigger
            id: "turn_off"
          - condition: or
            conditions:
              - condition: time
                after: "21:00:00"
                before: "23:00:00"
                weekday:
                  - sun
                  - mon
                  - tue
                  - wed
                  - thu
              - condition: time
                after: "23:00:00"
                weekday:
                  - fri
                  - sat
        sequence:
          - service: light.turn_off
            target:
              entity_id: light.your_light  ### change this ###

Or you could do it with two separate automations, which may be a bit easier to understand:

description: turn lights on
trigger:
  - platform: time
    at: 
      - "18:00:00"
      - "19:00:00"
  - condition:
      - condition: or
        conditions:
          - condition: time
            after: "18:00:00"
            before: "19:00:00"
            weekday:
              - sun
              - mon
              - tue
              - wed
              - thu
          - condition: time
            after: "19:00:00"
            weekday:
              - fri
              - sat
action:
  - service: light.turn_on
    target:
      entity_id: light.your_light  ### change this ###
description: turn lights off
trigger:
 - platform: time
   at: 
     - "21:00:00"
     - "23:00:00"
 - condition:
     - condition: or
       conditions:
         - condition: time
           after: "21:00:00"
           before: "23:00:00"
           weekday:
             - sun
             - mon
             - tue
             - wed
             - thu
         - condition: time
           after: "23:00:00"
           weekday:
             - fri
             - sat
action:
 - service: light.turn_off
   target:
     entity_id: light.your_light  ### change this ###

THANKS. I will implement tomorrow

Another way is to use the Schedule integration. Set the time periods for each day of the week and then the required automation is simply this:

alias: example
trigger:
  - platform: state
    entity_id: schedule.your_weekly_schedule
condition: []
action:
  - service: 'light.turn_{{ trigger.to_state.state }}'
    target:
      entity_id: light.your_light
3 Likes

Nice. I forgot about that.

Schedule Integration is a brilliant suggestion. Thanks