Different time helpers for weekday/weekend?

My daughter would like the lights in her room to go on in the morning, with a different time for weekdays and weekends. I see that that time helpers can be date, time, or date and time – but doesn’t seem to have something like “time and weekday”. So, one Idea I have is have a helper for weekends and one for weekdays, and then check which one triggered in the conditions, and then if the day matches (since time conditions have a weekday option. Is there a better way? In particular, this seeks like it would be pretty ugly if I wanted all seven days to be separate.

alias: '2. Morning '
description: ''
trigger:
  - platform: time
    at: input_datetime.weekday_wake_time
    id: Weekday
  - platform: time
    at: input_datetime.weekend_wake_time
    id: Weekend
condition:
  - condition: or
    conditions:
      - condition: and
        conditions:
          - condition: trigger
            id: Weekday
          - condition: time
            before: '00:00:00'
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
      - condition: and
        conditions:
          - condition: trigger
            id: Weekend
          - condition: time
            before: '00:00:00'
            weekday:
              - sat
              - sun
action:
  [...]

There are a few options to get what you want. First, the Workday sensor. Second, template conditions.

alias: '2. Morning '
description: ''
trigger:
  - platform: time
    at: input_datetime.weekday_wake_time
    id: Weekday
  - platform: time
    at: input_datetime.weekend_wake_time
    id: Weekend
condition:
  - condition: or
    conditions:
      - condition: and
        conditions:
          - condition: trigger
            id: Weekday
          - condition: state
            entity_id: binary_sensor.workday_sensor
            state: "on"
      - condition: and
        conditions:
          - condition: trigger
            id: Weekend
          - condition: template
            value_template: "{{ now().weekday() in [5, 6] }}"
action:
  [...]
1 Like

The second approach there doesn’t look much better to my eyes at least than my original one. But the Workday sensor seems like exactly what I was looking for. (I’m going to suggest an edit to the doc so it includes the words “weekend” and “weekday” for better search discoverability!)

I think that actually what I’ll end up with is a template trigger, using the workday sensor plus my helper time…

FWIW, in the upcoming version of Home Assistant it will be possible to re-write this automation using a new feature. Each trigger can define variables (and they support templates). That means there are some applications where the action won’t need a choose because the variables will contain values computed by the activated trigger.

2 Likes

Ooooh, I’ve wanted that very much. I’ve got several which have convoluted “choose” paths which that would completely solve.