Heyhey
I stuck in my automation and dont know how to solve my problem.
I wrote the following automation to turn on and off devices.
In addition to the existing code, I want the devices to be turned OFF on saturday at 16.15.
This means on every workday at 08.45
off on Mon - Friday at 18.45
and off on Sat at 16.45
The only solution I have is creating two automations for Mon - Fr and one for Sat.
But isn’t that possible within 1 automation:
alias: Kasse und Eingangstür an und aus
description: Schaltet die Kasse und Eingangstür an Werktagen ein und aus
trigger:
- platform: time
at: "08:45:00"
id: ein
- platform: time
at: "18:45:00"
id: aus
condition:
- condition: state
entity_id: binary_sensor.workday_sensor
state: "on"
action:
- choose:
- conditions:
- condition: trigger
id: ein
sequence:
- type: turn_on
device_id: ad690d3c4f5f940135719d388b8ccbb2
entity_id: switch.hmip_steckdose_kasse
domain: switch
- type: turn_on
device_id: b65c65fdf007d0ea44e8f591b5721b5e
entity_id: switch.hmip_steckdose_eingangstur
domain: switch
- conditions:
- condition: trigger
id: aus
sequence:
- type: turn_off
device_id: ad690d3c4f5f940135719d388b8ccbb2
entity_id: switch.hmip_steckdose_kasse
domain: switch
- type: turn_off
device_id: b65c65fdf007d0ea44e8f591b5721b5e
entity_id: switch.hmip_steckdose_eingangstur
domain: switch
mode: single
i used a delay, something like this:
If triggered by aus, check if it is a weekday.
If a weekday, delay for 2 hours before turning off, otherwise use the sub-default without delay to turn off
If not triggerd by aus, use the main-default to turn on
Something like this
alias: Kasse und Eingangstür an und aus
description: Schaltet die Kasse und Eingangstür an Werktagen ein und aus
trigger:
- platform: time
at: "08:45:00"
- platform: time
at: "18:45:00"
id: aus
condition:
- condition: state
entity_id: binary_sensor.workday_sensor
state: "on"
action:
- choose:
- conditions:
- condition: trigger
id: aus
sequence:
- choose:
- conditions:
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
sequence:
- delay:
hours: 0
minutes: 2
seconds: 0
milliseconds: 0
- type: turn_off
device_id: ad690d3c4f5f940135719d388b8ccbb2
entity_id: switch.hmip_steckdose_kasse
domain: switch
- type: turn_off
device_id: b65c65fdf007d0ea44e8f591b5721b5e
entity_id: switch.hmip_steckdose_eingangstur
domain: switch
default:
- type: turn_off
device_id: ad690d3c4f5f940135719d388b8ccbb2
entity_id: switch.hmip_steckdose_kasse
domain: switch
- type: turn_off
device_id: b65c65fdf007d0ea44e8f591b5721b5e
entity_id: switch.hmip_steckdose_eingangstur
domain: switch
default:
sequence:
- type: turn_on
device_id: ad690d3c4f5f940135719d388b8ccbb2
entity_id: switch.hmip_steckdose_kasse
domain: switch
- type: turn_on
device_id: b65c65fdf007d0ea44e8f591b5721b5e
entity_id: switch.hmip_steckdose_eingangstur
domain: switch
mode: single
Here you go. German trigger IDs converted to on/off in the templates.
alias: Kasse und Eingangstür an und aus
description: Schaltet die Kasse und Eingangstür an Werktagen ein und aus
trigger:
- platform: time
at: "08:45:00"
id: ein
- platform: time
at: "18:45:00"
id: aus_woche
- platform: time
at: "16:15:00"
id: aus_samstag
condition:
- or:
- "{{ trigger.id == 'ein' and now().weekday() < 6 }}"
- "{{ trigger.id == 'aus_woche' and now().weekday() < 5 }}"
- "{{ trigger.id == 'aus_samstag' and now().weekday() == 5 }}"
action:
- service: switch.turn_{{ {'ein':'on','aus':'off'}[trigger.id[:3]] }}
target:
entity_id:
- switch.hmip_steckdose_kasse
- switch.hmip_steckdose_eingangstur