Lights on at Dusk - is this the best/simplest way?

Yes,

Timezone and location is correct in HA. However there is still a 2 hour difference from the real time.

Ok,

Now I get it. That means that the light really did turn on at Dusk. Right?

You say “correct”, but what is it actually?

Well, when you run the template in dev tools, that uses the Timezone you set in configuration to display it in local time for you. If that time is correct in the template output then I see no reason for this to be wrong

My bad… doh

It was right all along. Just got hung up on that the attribute doesn’t show my dusk, my setting and so on.

That’s why you told me to do the template thing. Which showed the correct Dusk.

Thanks a lot. There really wasn’t any wrong anywhere. Awesome to have sorted this out. :smiley:

1 Like

No worries.

The other thing you can do is check the trace of the automation

Even better,

Thanks for the tips. :+1:

One last thing then,

Lights on at dusk, but with an offset. Any simple solution to that?

Yep

Mentioned previously

In this example, the offset is 180 seconds before dusk

One drawback is that automation only checks if this condition is true or false every 60 seconds so you can’t use any number less than 60 seconds otherwise it might miss the small window of time where the condition is true.

The other drawback with this is that you can only use a minus offset to reduce time before next_dusk triggers. Using a plus means it will never be true.

Now I think about it, the offset could possibly be applied to utcnow() instead of next_dusk() and that might allow positive offset to work. I’m not interested in testing it at the moment as my next_dusk automation works fine for me.

1 Like

Great,

Good for me i’m only interested in offset before dusk :smiley:

1 Like

@del13r wondering if simply replacing dawn for dusk works? I seem to have better success at hacking working code vs comprehension of the docs, thus can’t wait till tomorrow :laughing:
Took awhile to comprehend this won’t work if <60s but now somewhat understood. Soon to look over the dev tools, but currently cleaning up from splitting into /automations & /scripts

Appreciate the posted code :grinning:

If you wish to automate something to occur at dawn, then yes, replacing dusk with dawn will work.

{{ state_attr('sun.sun','next_dawn') }}

If you are curious as to when dusk and dawn will occur, use this template below with dev tools to find out


Next Dawn will be at
{{ as_timestamp(state_attr("sun.sun","next_dawn")) | timestamp_custom('%I:%M:%S %p') }}

Next Dusk will be at
{{ as_timestamp(state_attr("sun.sun","next_dusk")) | timestamp_custom('%I:%M:%S %p') }}