That condition means the time must be after “20 minutes before sunset.” Seems fine to me. Do you have the sun.sun entity configured in your system? If so, take a look at its attributes. What does it say for next_setting? If its after sunset then it’s probably for tomorrow, but that’s fine, since sunset doesn’t change that drastically from day to day. Does it seem about right? Note that if you look at sun.sun on the STATES page, the attribute’s value will be expressed in UTC. Or you can look at the “more info” page (e.g., click on the sun’s badge, or click on the circle with an “i” in it to the left of sun.sun on the STATES page) and it should show you the time of the next sunset in your local time. Do these values look correct?
after: sunset is also only true until midnight. Are you sure your timezone is set correctly (should still work at 23:55); and were you aware that it won’t work at say 00:05?
What time zone are you in? According to what you posted above, the sun sets near you around 20:11 UTC, but when it sets in your local time depends on what time zone you’re in.
Let’s say you’re in a time zone with a +01:00 offset from UTC. That would mean the automation will only run between about 9 PM (or 8:40 PM if you use the -20 min offset) and midnight (local.)
As @Troon suggested you might want to change to a sun elevation based condition, or at least add the time period between midnight and sunrise (per Sunset/sunrise condition.)
- condition: sun
after: sunset
after_offset: '-00:20:00'
and I move then the light comes on so I know the automation works in general. Just adding the sun code makes it fail. I will retest tonight after sunset but way before 11pm (incase timezone is messed up).
By “fail” do you just mean the actions don’t run when you expect they should? Or do you mean something else, like you see errors somewhere?
According to the info you posted, it looks like HA’s time zone is configured correctly. But there’s also the time zone setting in the OS environment that HA runs in (OS, docker container, etc.) that can sometimes cause problems. Enter the following in the template editor, and post the results you see:
Nope, that’s fine. For our purposes here, BST is equivalent to Europe/London. As you can see in my case the OS has CDT (Central Daylight saving Time), even though HA has America/Chicago. And it looks like the clock is set correctly.
So, bottom line, if the automation has the following condition:
- condition: sun
after: sunset
after_offset: -00:20:00
it will only run the actions if, when the binary sensor goes on, the current time is between 20 minutes before sunset (around 8:40 PM) and midnight (local.)