Sun behaving unpredictably

Being new to HA, I thought I’d start off with something simple - Control some lights by sunrise/sunset. I couldn’t get it to work at all, and in the History, I noticed Sun doesn’t seem to be working correctly.
Location, timezone, and elevation are correct.
Nothing seems out of place or unusual in logs.
Any help appreciated.

1 Like

Not sure as to why the sun component is working incorrectly for you but you don’t need it to do basic sunrise/sunset automations.

The following working in my setup and I don’t have sun loaded.

- alias: 'Turn On Outside Lights'
  id: e77dbd72-95fa-499c-ae9d-df60e9a06a6a
  trigger:
    platform: sun
    event: sunset
    offset: '-00:15:00'
  action:
    - service: light.turn_on
      entity_id: 
        - light.bulb1
        - light.bulb2
        - light.bulb3

You may want to check the lat/lon you put in and make sure you don’t have a - where it should/shouldn’t be. Does the map in configurtion->general show your home location properly? Also pay attention to your elevation, it should be meters above sea level regardless of your unit system setting.

I’m not sure what you mean by you don’t have sun loaded. I see in your code
“platform: sun”.
Anyway, my code is pretty much the same as yours, and it doesn’t work.
I’m pretty sure the sun component is the issue, as it is so erratic.
For example(s) from the attached screenshot:

  • Sunset at 8:30 AM?
  • Sunrise at about 1:30 AM?
  • The next sunset at about 9:00 AM?
  • Next sun above the horizon for about 15 mins around 6:30 PM?
  • etc.
    And there is no place on Earth where the Sun could behave like this!
    Location/timezone, and elevation are correct.
    I also rebooted, with no effect.
    It’s got me stumped.

What is your timezone set to?

What are the state and attrubutes of sun.sun?

1 Like

Timezone is set to America/Phoenix.
I’m a complete noob at this…how do I find the state and attributes of sun.sun?

In developer tools/states.

above_horizon next_dawn: 2021-12-11T13:51:40.682274+00:00
next_dusk: 2021-12-11T00:51:34.834902+00:00
next_midnight: 2021-12-11T07:21:47+00:00
next_noon: 2021-12-11T19:21:25+00:00
next_rising: 2021-12-11T14:20:16.483867+00:00
next_setting: 2021-12-11T00:23:00.470569+00:00
elevation: 18.05
azimuth: 225.02
rising: false
friendly_name: Sun

Does that help?

Those times look good to me. Your next solar midday is at 12:21:25, ie 25 minutes after your clock says it is noon.

Do the weird data points co-incide with a startup/reboot time?

OK thanks.
No, I’ve waited some time after rebooting to check on things, I don’t think the reboots are at all correlated to the sun timings.
Could you point me to the decoder ring for how to read those time entries? and their significance?
Many thanks.

I checked with

TZ=America/Phoenix date -d 2021-12-11T19:21:25+
00:00

This means:
Set my timezone to America/Phoenix just for this command, then output this time string to the timezone
and the answer is.

 Sat 11 Dec 2021 12:21:25 MST

It’s tomorrow in Arizona.

It’s still today here, for a few more hours, anyway :sunglasses:

Free beer here tomorrow.

There was free beer here yesterday…:smirk:

It’s not Saturday 12:21:25 MST yet, or am I completely lost is what’s going on here.

next_noon: is always in the future. Pay attention.

1 Like

this is turning into a crypto or stock subreddit.

j/K, thanks for the clarification. I missed it completely.

I think it’s all sorted now.
I adjusted my lat/long to a more precise position ( although only a few miles different from the original) in the config file, rebooted, and it now sun seems to be working.
And the free beer is all gone. It all went yesterday.
Appreciate all ya’ll.

1 Like

There will be more free beer tomorrow, I told you that yesterday!

The lat/long is set in the GUI these days.

1 Like