Weekday Condition Challenge

I finally got the routine to work to gradually increase the lamps in the bedroom starting at 6:15AM, but I’d like to avoid waking up at that time during the weekend.

Where did I go wrong when I added the weekday condition?

  action:
    - service: light.turn_on
      data:
        entity_id: light.graham_lamp
        brightness: 5
    - repeat:
        sequence:
          - service: light.turn_on
            data:
              entity_id: light.graham_lamp
              brightness: "{{ state_attr('light.graham_lamp', 'brightness') | int + 10}}"
          - delay: "00:00:03"
        until:
          condition: and
          conditions:
            - condition: time
              weekday:
                - mon
                - tue
                - wed
                - thu
                - fri
            - condition: template
              value_template: "{{ state_attr('light.graham_lamp', 'brightness') | int >= 254 }}"
            - condition: state
              entity_id: light.graham_lamp
              state: "off"

Put it in the condition section.

According to your example, it will gradually increase the light’s brightness until all three of the following conditions are fulfilled:

  1. It’s a weekday.
  2. Brightness exceeds 254.
  3. The light is off.

How can the last two conditions be satisfied together? They require the light to be simultaneously off and be at maximum brightness.

Maybe you wanted to logically OR the last two conditions?

I agree with pedolsky that the weekday condition doesn’t belong in the repeat-until.

Also if you use this sensor:

You can simplify this:

            - condition: time
              weekday:
                - mon
                - tue
                - wed
                - thu
                - fri

To:

            - condition: state
              entity_id: binary_sensor.workday
              state: 'on'

It has the advantage of excluding public holidays as well as weekends.

Thanks I’ll give that a try.

I updated the routine with the workday sensor, but I must have messed up the condition statements because it is still turning on during the weekends.

Any help would be appreciated!

- id: morningBrianLampOn
  alias: "Brian lamp turned on at specific time"
  trigger:
    - at: "06:15:00"
      platform: time
  condition:
    - condition: state
      entity_id: binary_sensor.workday
      state: "on"
  action:
    - service: light.turn_on
      data:
        entity_id: light.graham_lamp
        brightness: 5
    - repeat:
        sequence:
          - service: light.turn_on
            data:
              entity_id: light.graham_lamp
              brightness: "{{ state_attr('light.graham_lamp', 'brightness') | int + 10}}"
          - delay: "00:00:03"
        until:
          condition: and
          conditions:
            - condition: template
              value_template: "{{ state_attr('light.graham_lamp', 'brightness') | int >= 255 }}"
            - condition: state
              entity_id: light.graham_lamp
              state: "off"
- id: morningBrianLampOn
  alias: "Brian lamp turned on at specific time"
  trigger:
    - platform: time
      at: "06:15:00"
  condition:
    - condition: template 
      value_template: '{{ 1 <= now().isoweekday() <= 5 }}'
  action:
    - variables:
        lamp: light.graham_lamp
    - service: light.turn_on
      target:
        entity_id: '{{ lamp }}'
      data:
        brightness: 5
    - repeat:
        sequence:
          - service: light.turn_on
            target:
              entity_id: '{{ lamp }}'
            data:
              brightness_step: 10
          - delay: "00:00:03"
        until: "{{ state_attr(lamp, 'brightness') >= 255 or is_state(lamp, 'off') }}"

Thanks for the help @123

1 Like