Enhanced Sun component

Passes on my end.

* sun2 (tomorrow) sun (next_*)
dawn 1561107184.0 1561107184.0
dusk 1561166995.0 1561166995.0
sunrise 1561109324.0 1561109324.0
sunset 1561164855.0 1561164855.0

Everything also has a value

sensor.dawn
  yesterday = 2019-06-19 04:52:46-04:00
  today = 2019-06-20 04:52:54-04:00
  tomorrow = 2019-06-21 04:53:04-04:00
sensor.daylight
  yesterday = 15.421388888888888
  today = 15.424166666666666
  tomorrow = 15.425277777777778
sensor.dusk
  yesterday = 2019-06-19 21:29:21-04:00
  today = 2019-06-20 21:29:39-04:00
  tomorrow = 2019-06-21 21:29:55-04:00
sensor.night
  yesterday = 3.898888888888889
  today = 3.894722222222222
  tomorrow = 3.8930555555555557
sensor.solar_noon
  yesterday = 2019-06-19 13:11:03-04:00
  today = 2019-06-20 13:11:16-04:00
  tomorrow = 2019-06-21 13:11:30-04:00
sensor.sunrise
  yesterday = 2019-06-19 05:28:25-04:00
  today = 2019-06-20 05:28:33-04:00
  tomorrow = 2019-06-21 05:28:44-04:00
sensor.sunset
  yesterday = 2019-06-19 20:53:42-04:00
  today = 2019-06-20 20:54:00-04:00
  tomorrow = 2019-06-21 20:54:15-04:00
1 Like

Thanks! I’ll let you know what I find.

No, not really. They all agree.

image

is the same as

image

And

image

is the same as

image

I am really sorry…causing all this confusion.
I checked sun2. sensors state and not attribute against sun.sun attributes, hence the few seconds Off… as it was supposed to be.
Sorry again.

Hope you can find the midnight issue though, because that is still here, even after reinstalling sun2 and several restarts/clean cache.

btw does this interfere in any way: Reset location elevation back to civil after updating sun by Swamp-Ig · Pull Request #24612 · home-assistant/core · GitHub

do have another question though…:

trying your daylight template few posts above works fine:

       daylight_delta_yesterday:
        friendly_name: Daylight delta yesterday
        value_template: >
          {{((state_attr('sensor.sun2_daylight','today') - 
              state_attr('sensor.sun2_daylight','yesterday'))*3600)|round(1)}}

      daylight_delta_tomorrow:
        friendly_name: Daylight delta tomorrow
        value_template: >
          {{((state_attr('sensor.sun2_daylight','tomorrow') - 
              state_attr('sensor.sun2_daylight','today'))*3600)|round(1)}}

but trying to do that for tomorrow yields ‘0’.

Now I know I am experimenting on the first day of Summer, being the longest day, but I thought id better ask whether this is correct?

I’m seeing zero difference in day length for tomorrow. Today is 4 seconds.

That’s because the value is the same… June 21st is the longest day of the year from what I remember. This is expected :wink:

image

Yeah that’s what I was alluding to.

1 Like

right, I expected as much, but never really realized it was precise up to the second …
proves the integration’s calculation is pitch perfect ;-

Only thing left is my missing Night. Hope HA isn’t as intelligent to spot that’s the time my HA tinkering is most frequent…

lol! No, I don’t think it’s that. Here is the issue:

astral.AstralError: Sun never reaches 18 degrees below the horizon, at this location.

FWIW, I think I’m going to change the state (& attributes) back specifically to 'none' in this case. Leaving them as None gets displayed misleadingly – 'unknown' for state, and null for attributes.

but would that give me a Night? It s not so much that I didn’t like the display of the state, but more the fact it wasn’t calculated at all?? as you wrote here: Enhanced Sun component it should be Night between sunset/sunrise, or maybe even better between Dusk/Dawn

      period_of_day:
        friendly_name: 'Period of the day'
        value_template: >
          {% if (as_timestamp(state_attr('sun.sun','next_dusk'))) - 
                (as_timestamp(state_attr('sun.sun','next_setting'))) < 0 %} Dusk
          {% elif (as_timestamp(state_attr('sun.sun','next_rising'))) - 
                  (as_timestamp(state_attr('sun.sun','next_dawn'))) < 0 %} Dawn
          {% elif (state_attr('sun.sun', 'elevation')) < 0 %} Night
          {% else %} Day
          {% endif %}
        icon_template: >
          {% if is_state('sensor.period_of_day','Dusk') %} mdi:weather-sunset-down
          {% elif is_state('sensor.period_of_day','Dawn') %} mdi:weather-sunset-up
          {% elif is_state('sensor.period_of_day','Night') %} mdi:weather-night
          {% else %} mdi:weather-sunny
          {% endif %}

Note the “what night used to be” part. In the current implementation night is between Astronomical dusk/dawn. But it will be:

BTW, for types like daylight & night, which are numbers of hours, I should probably make them 0.0 in this case, rather than 'none'. That probably makes more sense.

I’m working on a new version (to implement the sensor types in the post you referenced), but it will take a while.

I overlooked to mention that I agree with your proposed definitions. Even though your version of night doesn’t jibe with Astral’s version (astronomical night), it’s probably a better fit with what many people consider to be ‘night’ (that period between sunset and sunrise).

1 Like

Yes, I’ve read that, but please let me ask to be certain of what you’ve written: you will also support:

`nautical_night`  = between Nautical dusk/dawn, -12°
`civil_night`  = between Civil dusk/dawn, -6

Which I would template out for sure then in my config.

Personally I find the new definition of Night way too wide, being the period between Sunset and Sunrise. I am a nature kinda guy, and feel that there is a great distinction between evening, dusk, night, and dawn … which in the new setting all would be Night? Not even Evening and Morning :wink:

Follow the song of the birds and you know what I mean…

What’s the time period for ‘evening’?

This is what I’m currently attempting to implement:

There will be two types of sensors: ones that provide points in time, and ones that will provide lengths of time. All sensors with have yesterday, today and tomorrow attributes, which will be as “raw” as possible (either a Python aware datetime in the local time zone, or a non-rounded float in hours), and the state will be a “prettier” version of the today attribute (for point in time types the datetime will be converted to a string in ISO format, and the others will be rounded to 3 decimal places and, of course, also converted to a string.)

The list of options for the “point in time” type will be:

solar_midnight
dawn
sunrise
solar_noon
sunset
dusk

The dawn and dusk sensors will be “civil”. I could be talked into providing astronomical & nautical versions of dawn & dusk as well. :slight_smile:

The list of options for the “length of time” type will be:

daylight - from sunrise to sunset (-0.833°)
civil_daylight - from civil dawn to civil dusk (-6°)
nautical_daylight - from nautical dawn to nautical dusk (-12°)
astronomical_daylight - from astronomical dawn to astronomical dusk (-18°)
night - from sunset to tomorrow’s sunrise (-0.833°)
civil_night - from civil dusk to tomorrow’s civil dawn (-6°)
nautical_night - from nautical dusk to tomorrow’s nautical dawn (-12°)
astronomical_night - from astronomical dusk to tomorrow’s astronomical dawn (-18°)

To be clear, these don’t indicate when the time is in these periods, they are simply the length of these periods.

Also, right now the plan is to have these all update 1) when HA starts, 2) if HA’s location configuration changes, and 3) at local midnight.

So, not really worried about how the current version works. I’m more concerned with making something reasonable, even if it means the next release will be a “breaking change.” :wink:

great, if I misunderstood that before, this is way precise, and what I would have hoped for.

well, I hope you don’t get me wrong, and having read my earlier request, please let me talk you into it, not pushing in any way, and only if you see it fit because of added value. I would certainly appreciate it :wink:

Agree all of what you stated after that, provided I fully grasp what it means here and there, have to read up on some specifics…

and

its not as much a time period, more of a behavior or consideration to paraphrase your words. I would consider Evening the end of the day, lets say beginning with sunset, and including dusk. Most importantly the song of the blackbird…or nightingale for that matter.
All silent makes it a night (that is, I don’t live in a rainforest, so please forgive me its not a universal definition), and the hedgehogs walk.

Same would go for morning, starting from dawn, until Noon. Of course, get up at 5 and hear the same songs echoing and you get the feeling. Replace Nightingale for a whole army of morning whistlers.

Not very digital, I know.

That works for me.

For the folks at home having trouble understanding all of these time periods, here’s Wikipedia to the rescue:

wikipedia

The only thing in my proposed definitions that seems to go against established norms, and that picture, is the definition of night. As I stated above, I’ll use the sensor type of astronomical_night to correspond to what is usually meant by night, and I’ll use night to mean 24 hr - daylight. It’s a trade-off to make things more symmetrical.

No, but rather magical. :unicorn:

Where nightingales sing :bird: and hedgehogs roam. :hedgehog:

1 Like

You have my vote. Using the astronomical definition of night would be technically correct but your repo willl be buried in Issues complaining about “How can night possibly be only 3 hours long??” :wink:


EDIT

I’m still of the opinion that you should expose Astral’s moon phases and then call the whole shebang the astro component. That way there’s no way to confuse it with the stock sun component nor with your customized sun component. So rather than rolling it out as a ‘breaking change’ version of your custom sun component, you can say it is now deprecated and superseded by the new astro component.

4 Likes