Hello,
I want to get up at a certain time every weekday, switch on two lamps that stay on for 2:30 hours. Unless the sun rises during this time (2:39). Then the two lamps should go out. This is exactly the condition for switching off the lights after sunrise. I don’t know how to do that. This is my approach. I can’t get any further.
alias: LichtAufstehen
description: Nach dem Aufstehen geht das Licht im Wohnzimmer an.
trigger:
- platform: time
at: input_datetime.aufstehen_wochentags
condition: []
action:
- if:
- condition: state
entity_id: binary_sensor.workday_sensor
state: "on"
then:
- action: light.turn_on
metadata: {}
data: {}
target:
entity_id: light.lichtwohnzimmer
- if:
- condition: sun
after: sunrise
then:
- action: light.turn_off
metadata: {}
data: {}
target:
entity_id: light.lichtwohnzimmer
- delay:
hours: 1
minutes: 30
seconds: 0
milliseconds: 0
- action: light.turn_off
metadata: {}
data: {}
target:
entity_id: light.lichtwohnzimmer
mode: single
input_datetime.aufstehen_wochentags = 6:20 Uhr
Do you have any idea how I can implement this?
Greetings from Stefan
alias: LichtAufstehen
description: Nach dem Aufstehen geht das Licht im Wohnzimmer an.
trigger:
- platform: time
at: input_datetime.aufstehen_wochentags
id: 'on'
- platform: state
entity_id: light.lichtwohnzimmer
to: 'on'
for: "02:30:00"
id: 'off'
- platform: sun
event: sunrise
id: 'off'
condition:
- condition: state
entity_id: binary_sensor.workday_sensor
state: "on"
action:
- action: light.turn_{{ trigger.id }}
target:
entity_id: light.lichtwohnzimmer
Turns on at your set time; turns off when the light has been on for 2:30 or when the sun rises. It doesn’t matter that the light gets turned off twice.
It’s good practice not to have long delays in automations; and I prefer to keep complex logic out of the action block.
Note that this will turn off the lights after 2:30 regardless of whether they were turned on by this automation or elsewhere. If that’s a problem, you could create a template sensor with device class timestamp that is your input_datetime plus 2:30 and replace the state trigger with a time trigger for that sensor.