I need some help with automation of lights that I would like to come on at 4pm but only if the sun has set. If the sun has not set at 4pm I want it to come on at sunset.
I have been trying with this but it is not working.
- alias: Turn on light in kitchen and livingroom at sunset
trigger:
- platform: time
at: '16:00:00'
- platform: sun
event: sunset
condition:
- condition: sun
after: sunset
action:
- service: light.turn_on
data:
entity_id:
- light.koksfonster_vanster
- light.koksfonster_hoger_54
- light.vrum_fonster_4
- light.belysning_horn_soffa_40
- light.vrum_hornbumling_33
However this is not working. The light come on at sunset (about 3.20pm) Any help would be greatly appreciated!
So if I understand you correctly, if the sunsets earlier than 4pm you don’t want the lights to turn on?
Right now you have 2 triggers for this automation, either 4pm or sunset and one condition. So if the sun sets at 3:20 it looks for the condition that it’s set (which it would be) and executes.
If you wanted to only trigger 4pm or later, you’ll need to add another condition to check if it’s after 4pm.
Looking at your suggestion once again. Does this condition trigger the light to go on at 4pm if the sun sets before 4pm? I can understand that it will not trigger before 4pm if the sun has not set.
Some more background to understand what I want to achieve. during the winter the sun sets before 4pm but generally no one is at home before 4pm so no need to go off before. During the sumer the sun sets later (like 9pm) and at that time i would like it to trigger at sunset. Just wonder if this can be done i one automation…?
- alias: Turn on light in kitchen and livingroom at sunset
trigger:
- platform: time
at: '16:00:00'
- platform: sun
event: sunset
condition:
condition: and
conditions:
- condition: sun
after: sunset
- condition: time
after: '15:59:59'
action:
- service: light.turn_on
data:
entity_id:
- light.koksfonster_vanster
- light.koksfonster_hoger_54
- light.vrum_fonster_4
- light.belysning_horn_soffa_40
- light.vrum_hornbumling_33
This way it triggers for either event and checks that the other is valid.
I use this method myself for my lights to come on when someone comes home after dark, but if somebody is already home it waits until it gets dark to trigger. Example…
Link removed
PS - I’ve just noticed that the condition offset in my GitHub is wrong and should be ‘-00:40:00’ to match the trigger, to avoid confusion