I have a cover that I want to open at 8:30 on weekdays and at 10:00 on weekends. Initially I set up a Time Trigger at 8:30 and a condition (Time) for weekdays. It works well. I could simply do 2 automations (one for weekdays and the other for weekends) but I would like to set up everything on a single automation.
So I set up 2 triggers, (Time 8:30 and Time 10:00) then I set 2 OR conditions, one that says Time after 8:29 on weekdays OR Time after 9:59 on weekends.
Surprise the automation doesn’t get triggered anymore… why it’s that ? what is the best way to do what I want to do ?
alias: Open covers
description: ''
trigger:
- at: '8:30'
platform: time
- platform: time
at: '10:00'
condition:
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
after: '8:29'
- condition: or
conditions:
- condition: time
after: '9:59'
weekday:
- sat
- sun
action:
- data: {}
entity_id: cover.rho1_cover
service: cover.open_cover
mode: single
alias: Open covers
description: ''
trigger:
- platform: time
at:
- '8:30'
- '10:00'
condition:
- condition: template
value_template: >
{% set h = now().hour %}
{% set wd = now().isoweekday() %}
{{ (h == 8 and 1 <= wd <= 5) or
(h == 10 and wd in [6,7]) }}
action:
- service: cover.open_cover
target:
entity_id: cover.rho1_cover
mode: single
The template works like this:
If the current hour is 8 and the weekday is between 1 and 5 inclusively OR
If the current hour is 10 and the weekday is either 6 or 7
now().isoweekday() returns the current weekday as a number between 1 (Monday) and 7 (Sunday).
NOTE
In case you’re wondering why your condition didn’t work it’s because the logical OR statement is in the wrong place. Look at the first example on this page:
You could use a choose block with your trigger as is with an automation like this. It’s perhaps a little more complex than using templates but I’ve become averse to templates because the “new” automation options are very powerful.