Above polar circle - sun state is wrong - how to fix?

Hi,

I live above the polar circle, and here it is now midnight sun (up 24 hrs/day) until July 23rd.
But, the sun.sun state claims it is ‘below horizon’ (!) and, well, lucky us it is ABOVE for the next 7 weeks.

How can I fix this?

Capture

At the very least, you can open an issue against the sun component. If you know Python, then you can submit a PR against the source that corrects the behaviour.

@Tinkerer Ahh, so this is possibly a bug then?
No, my Python skills are not good and I can’t make a PR.

Are the latitude & longitude correct in your configuration file?

@anon34565116 Yes sir, I’m 100% sure.
Before the midnight sun started, sunrise/sunset was 100% correct.

An elevation of 23.7 and below horizon… I’d call that a bug :smiley:

3 Likes

OK, I think they should open an issue with details such as lat/long so it could be replicated.

Issue created :slight_smile:

https://github.com/home-assistant/home-assistant/issues/24271

2 Likes

An idea for a ‘dirty fix’ - creating an automation which says between May 21 and July 26 - set sun.sun state to 'above_horizon’

Anybody who are good at automations that might help me with that? Please?

use numerical states and check the sun elevation being greater than zero

  trigger:
    platform: numeric_state
    entity_id: sun.sun
    # Optional
    value_template: '{{ state.attributes.elevation}}'
    # At least one of the following required
    above: 0

But that my never trigger if it’s always above zero. If that’s what you want, make the change.

Thanks.
Near the end, the link text is correct but the link itself is wrong.

URL fixed :slight_smile:

1 Like
   trigger:
   - above: '0'
     entity_id: sun.sun
     platform: numeric_state
     value_template: '{{ state.attributes.elevation}}'
   action:
   - condition: state
     entity_id: sun.sun
     state: above_horizon

…didnt change the sun.sun state after pressing ‘trigger’ of the automation

One of the challenges to resolve this issue is that in order for trigger to activate the automation, sun.sun must experience a state-change. In other words its state has to change from below_horizon to above_horizon to cause it to trigger the automation. However, that’s not going to happen for the next 7 weeks.

Similarly, testing for above: 0 requires it to first go below 0 then rise above it to cause trigger to activate the automation. It won’t dip below 0 for another 7 weeks.

1 Like