Automation trigger issue on sunset

Hi everybody!

I have an automation that triggers when sun sets and no device is at home (or when all devices leave home - not relevant for my issue):


(Sorry for pasting the code but I’m from mobile)

But it seems that triggers (21:01) before the sun.sun entity really switches from above to below horizon (21:05)

Some notes:

  • The automation has a different action (I used templates) depending if sun is above or below the horizon so triggering before the sun set trigger the wrong action.
  • No device at home during the test
  • I have not the same problem on sunrise
  • The automation worked like a charm before last update to 0.95.
  • I can obviously apply a workaround using some minutes has offset but I don’t understand why it happens.

Have you ever experience a similar issue?
Gianmaria

I’ve heard of similar issues, but haven’t dug into why it might happen. I do know that significant changes were made to the sun component recently. You should probably open an issue.

In the meantime, as long as you’re using no offsets, you could change the sun triggers to:

  - platform: state
    entity_id: sun.sun
    to: above_horizon
  - platform: state
    entity_id: sun.sun
    to: below_horizon

Thanks for the suggestion, I will try it and give you a feedback on it.
In the meanwhile I will open an issue too.

Gianmaria

1 Like

Hi Phil,

I confirm that your suggestion solved the problem: now the automation trigger exactly when the sun sets!! Thanks!

I will update the post as soon as I open the issue or if I have an update on the strange behavior.

Gianmaria