Any weekday examples?

Does anyone have yaml code I can look at where weekday is used as a condition? I’m having trouble with one I’m trying to setup.

thanks

Only fires on a Wednesday…

link removed

2 Likes

Here’s a template that uses weekdays

{% set curhour = now().hour %}
{% if now().weekday() in (0,1,2,3,4) %}
  {% if curhour <= 23 and curhour >= 13 %}
    homeassistant.turn_on
  {% else %}
    homeassistant.turn_off
  {% endif %}
{% else %}
  {% if curhour <= 2 or curhour >= 13 %}
    homeassistant.turn_on
  {% else %}
    homeassistant.turn_off
  {% endif %}
{% endif %}
1 Like
- alias: Lights on before Sunrise
  trigger:
    - platform: sun
      event: sunrise
      offset: '-00:50:00'
  condition:
    condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
  action:
    - service: scene.turn_on
      entity_id: scene.morning_sunrise
9 Likes

Triggers at 04:30 on Monday to Thursday, but only if we’re at home.

- id: gym lights
  alias: Gym lights
  trigger:
    platform: time
    at: '04:30:00'
  condition:
  - condition: and
    conditions:
    - condition: time
      weekday:
      - mon
      - tue
      - wed
      - thu
    - condition: state
      entity_id: device_tracker.karley
      state: home
  action:
  - service: light.turn_on
    entity_id: light.bike_stand
    data:
      brightness: 58
      rgb_color:
      - 58
      - 58
      - 58
  - service: light.turn_on
    entity_id: light.cave_lamp
    data:
      brightness: 20
      rgb_color:
      - 20
      - 20
      - 20
2 Likes

Three years later - here my solution I’ve found. I needed two timers for weekdays and weekend. During the week at 6:45 on weekend at 8:15. I’ve tried many times and got it working with this

alias: Good morning 0645 birds chirping and light on
description: ''
trigger:
  - platform: time
    at: '06:45:00'
  - platform: time
    at: '08:15:00'
condition:
  - condition: state
    entity_id: group.family
    state: home
  - condition: template
    value_template: >-
      {{ ( now().weekday() in (0,1,2,3,4) and now().hour == 6) or (
      now().weekday() in (5,6) and now().hour == 8) }}
action:
  - scene: scene.morning_lights
  - service: script.turn_on
    data:
      variables:
        volume: 0.01
        media: birds chirping 1 - 60min - loud - 64k.mp3
        speakers: >-
          media_player.wohnzimmer_paar,media_player.schlafzimmer_paar,media_player.shower,media_player.bad
    entity_id: script.play_song_media_speakers
mode: single

Searched for this too, well, now you can do the following (still pretty stupid):

alias: 'demo'
description: ''
mode: queued
trigger:
  - platform: time
    at: '08:00:00'
    id: weekdays
  - platform: time
    at: '10:00:00'
    id: weekends
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: weekdays
          - condition: time
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
        sequence: []
      - conditions:
          - condition: trigger
            id: weekends
          - condition: time
            weekday:
              - sat
              - sun
        sequence: []
    default: []
max: 10

Or if you want to do one thing, regardless if it’s a weekday or weekend, flip the days on the cases and use the default case:

alias: demo
description: ''
mode: queued
trigger:
  - platform: time
    at: '08:00:00'
    id: weekdays
  - platform: time
    at: '10:00:00'
    id: weekends
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: weekdays
          - condition: time
            weekday:
              - sat
              - sun
        sequence: []
      - conditions:
          - condition: trigger
            id: weekends
          - condition: time
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
        sequence: []
    default:
      - type: turn_on
        device_id: ba53147b3446b11fcb46bb8dd12fcfe8
        entity_id: light.ceiling
        domain: light
max: 10

For future readers, this is detailed in the docs under Time Condition in Conditions - Home Assistant.
It also mentions the included Workday integration, which is a more powerful alternative: Workday - Home Assistant

2 Likes

What if I want to run my automation only biweekly (withouth using custom components or calendar integration, I want to do this natively with HA)?

Would I need to template a trigger/condition? What would this look like?


Update:
found a “solution” following Monthly automation - #2 by VDRainer.

I needed something to work on Sundays only.
Functioning example, using UI:

Trigger:
Time at 10am
Condition:
Time between 10am and 10:05am on Sundays
Action:
Device make coffee, I wish :relaxed:

I hope this helps.

Just because the before and after boxes are there in the condition UI doesn’t mean you have to fill them in.

1 Like