Problem with condition based on sun

Hi all…
I have an automation that should trigger only between sunset and sunrise, aka during night :smiley: It has been worked for a long time, but since some days I have this strange behaviour… Is anyone else facing this issue?

The sun sensor shows the sunset and sunrise at the same day.
So before sunrise means between midnight and sunrise and after sunset means between sunset and midnight.
Both of these two will hardly ever be true at the same time unless you live high north or south where you might be close to polar nights.

The condition is set to AND as default, so it will most likely fail.
Make sure to set the condition to OR explicitly instead.

Perhaps this will work for you.

    condition: state
    entity_id: sun.sun
    state: below_horizon
1 Like

As per documentation it should works

Actually it is working on some situations, it just seems that sometimes it is using wrong times…

Actually, the issue continues to be here… I’m thinking this could be related to some sort of timezone problem… It seems that the condition does not take into consideration the DST… Can this be fixed in some way?

Stop fighting it. It is a losing battle.
Use elevation values instead or use above_horizon/below_horizon.