And the âONâ part (the one with the condition) does not work right now at 1am. Without the condition it works just fine so the sensor and the light are correct. What do I miss? Is it a bug or https://www.home-assistant.io/docs/scripts/conditions/ needs an update? Right now it says " 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".
Update:
condition: not
conditions:
- condition: sun
before: sunrise
after: sunset
this works too. So I am really curious now why the recommended setup does not work.
You have made a classic mistake, we all made them
You have said, before sunrise AND after sunset
That canât happen
Try states(âsun.sunâ) == âbelow_horizonâ
So you tried to do the right thing, but this is another classic mistake â misunderstanding how the and and or conditions work. Try this:
condition:
- condition: or
conditions:
- before: sunrise
condition: sun
- after: sunset
condition: sun
Or @Muttâs suggestion is another way to effectively do the same thing, although it requires including the sun integration in your configuration, which the above does not.
EDIT: And, actually, now that we have a not condition, your updated solution is probably just as good, or better, since itâs slightly more compact.
EDIT 2: Actually, your updated solution shouldnât work. The âinsideâ condition is âbefore sunrise and after sunsetâ, which, again, is always False. Then the âoutsideâ condition inverts that, which makes it always True. What you really want is:
condition: not
conditions:
- condition: sun
after: sunrise
before: sunset
The main point is: âbefore sunriseâ means the period of time from todayâs midnight (i.e., the start of today) to sunrise, and âafter sunsetâ means from sunset to tomorrowâs midnight (i.e., the end of today.) As pointed out, it canât be both the start of the day and the end of the day at the same time.
@pnbruckner I noticed my mistake in the second variant this morning
Regarding the âorâ - I misunderstood how the UI works around âorâ, I think I get it now (this is how I got the first variant and I was looking how to do it right from the UI as I was doing it on the phone). Thanks!