Same automation, different days

I want to run this script at 9pm, fri & sat, then 10pm, sun, mon, tues, wed, thurs. How can I accomplish that?

- alias: Schedule
  trigger:
    - platform: time
      at: '21:00:00'
    - platform: time
      at: '20:00:00'
  condition:
    condition: time
    weekday:
      - fri
      - sat
  condition: time
  weekday:
    - sun
    - mon
    - tue
    - wed
    - thu
  action:
    - service:

By using two separate automations, one handles the Fri/Sat schedule and the other handles the other days. Otherwise, you’ll require a complex template; not worth the effort when two automations simplify life.

Not necessarily all that complex :slight_smile: :

- alias: Schedule
  trigger:
    platform: template
    value_template: >
      {{ is_state('sensor.time', '21:00' if now().isoweekday() > 4 else '22:00') }}
  action:
    ...
3 Likes

Nice! :+1:

… I was anticipating the other shoe to drop … when the full requirement is revealed to be the action depends on which schedule triggered it …

Thanks! I’d like to look more into this option. Where can I find more info about the > 4 and what that means?

The 4 in > 4 represents the fourth day of the week. For isoweekday(), the fourth day of the week is Thursday. So Phil’s clever template is saying:

Check if the current timer is 21:00 if today is beyond Thursday otherwise use 22:00

Hello, for controlling days you can use “turnoffon”


your config will be simple:
turnoffon:
  my_auto:
    action_entity_id: automation.id   # put here id of automation (not alias)
                                      # you will find it in automations.yaml
    timers: { "6:00":"23:59" }        # from the mornig to the rest of the day
    weekdays: ['mon', 'thu']          # the days you want

Automation will be turned-on on Monday, and Thursday.

1 Like