I want to turn on ambient light in the hall when someone enters it and then turn it off automatically again. That works fine - I have a motion sensor that detects move and a light that is turned on/off based on that movement info. So far so good. But I wanted to add a condition to turn on the light only during when (called “when dark” in the docs). So I created a condition and selected both before sunrise and after sunset. I believe this is the right way. It does not work though.
With this condition the light is not turned on automatically even after sunset - I have another automation that use sunset as a trigger and it was already triggered today so I am sure that HA knows that now it is dark outside. It works only if I select just after sunset, then it works fine. But this setting turns the light on only until midnight.
What is wrong with my config or understanding this sunset/sunrise condition? Can someone maybe please test that it really works for you as expected? Because to me it seems like it might be a bug.
Do the docs say it is supposed to work? Can you point out where?
As @123 pointed out in a similar topic, the docs state sunrise and sunset need to be specified in two separate conditions under an or condition, as you have written above.
From the docs:
Therefore, to cover time between sunset and sunrise one need to use after: sunset and before: sunrise as 2 separate conditions and combine them using or.
it used to work as it is now but at some point I was sure the docs were changed to say that if you used both before and after in the same condition it would then span midnight.
it was either changed or i was completely misremembering. My bet would be on the latter, tho.
EDIT: nevermind. I was thinking of the time condition which if you use both before and after then it spans midnight. confusing that they work differently tho.
they seem to be saying that it will work in the first example above then later saying it won’t work and you have to use ‘or’.
it’s mostly understandable if you already know it but if you don’t then it is very misleading.
and it makes it more confusing since you actually can use “after: sunrise” and “before: sunset” in the same condition since they are not logically contradictory since they don’t span midnight.
Full disclosure: I don’t use the Sunrise/Sunset Condition so I never bothered to confirm if both examples represent “counter-examples” (as in “don’t do this”) or just the second one.
Somebody ought to confirm what’s what and then update the docs … but I’m not volunteering for it (too much on my plate at the moment).