WTH Is there no golden hour data available to trigger light automations?

I used to do my light automations in NodeRED and I used the golden hour component to switch on/off my lights. For me, the start of the golden hour is the perfect time to switch on my lights.

So, I would really like to see the golden hour being added to the SUN component. Currently, it’s really a pain to accomplish the same using the sun/elevation.

There is a python library called Astral which can provide the calculations https://github.com/sffjunkie/astral

Would this work?

    platform: sun
    event: sunset
    offset: "-01:00:00"

It’s from here: https://www.home-assistant.io/cookbook/automation_sun/

HA uses Astral.
You could look at the enhanced sun component thread and ask @pnbruckner about adding it?

1 Like

for the time being, this is all there is to it, no real pain at all?

  - platform: template
        friendly_name: Golden hour
        value_template: >
          {{ -4 < state_attr('sun.sun','elevation')|float < 6}} #edited the -4 to have a leading space, otherwise the jinja interpretes that as a white space killer and the template is false going below 4 ;-) )
        device_class: light

and you can trigger of the state of that binary_sensor.

still, would be cool if Phil could add it indeed.


You can also instal deCONZ add on, even if not using it for controlling Zigbee devices,it contains daylight sensor:
The sensor’s state value is a string corresponding to the phase of daylight (descriptions below taken from https://github.com/mourner/suncalc, on which the deCONZ implementation is based):

Sensor State	Description
sunrise_start	sunrise (top edge of the sun appears on the horizon)
sunrise_end	sunrise ends (bottom edge of the sun touches the horizon)
golden_hour_1	morning golden hour (soft light, the best time for photography)
solar_noon	solar noon (sun is in the highest position)
golden_hour_2	evening golden hour
sunset_start	sunset starts (bottom edge of the sun touches the horizon)
sunset_end	sunset (sun disappears below the horizon, evening civil twilight starts)
dusk	dusk (evening nautical twilight starts)
nautical_dusk	nautical dusk (evening astronomical twilight starts)
night_start	night starts (dark enough for astronomical observations)
nadir	nadir (darkest moment of the night, the sun is in the lowest position)
night_end	night ends (morning astronomical twilight starts)
nautical_dawn	nautical dawn (morning nautical twilight starts)
dawn	dawn (morning nautical twilight ends, morning civil twilight starts)

Don’t get me wrong, I know it can be done. But for UI only users, like my dad (who is using HA!! how cool is that :sunglasses:), this is way to complex.

thanks! just found this thread again, because I was finally able to use the conbee and setup this sensor.

Seems a bit odd though with enormously long golden hours and nadir (which should be only a short period) taking almost all night. Astral has got those lighting scenes in a more natural way I feel.

fyi, Ive made this customization, and had a bit of a struggle with the available mdi icons. If you could see an improvement, please let me know:

        icon: >
          var icon = {'Night start':'theme-light-dark',
                      'Night end':'theme-light-dark',
                      'Nautical dawn':'white-balance-sunny',
                      'Sunrise start':'weather-sunset-up',
                      'Sunrise end':'weather-sunset-up',
                      'Golden hour 1':'brightness-7',
                      'Solar noon':'weather-sunny',
                      'Golden hour 2':'brightness-5',
                      'Sunset start':'weather-sunset-down',
                      'Sunset end':'weather-sunset-down',
                      'Nautical dusk':'weather-sunset-down'}
          return icon[state] ? 'mdi:' + icon[state] : 'mdi:weather-sunny-alert';

Well… after some time of using this sensor I also found it a bit frustrating, that timeframes of different states are a bit… off time :slight_smile: What I really wanted is to know when I should trigger my lights, because it is dark enough.
So finally I went completely different route for this and I created small sensor that combines sunset and cloud coverage, giving on return ‘adjusted’ sun elevation. If it is positive, it light enough not to switch the lights on, if negative I either swithc the lights on or use it as condition in automations to determine if, for example, motion detection should trigger the light on.
Here is the code:

  - platform: template
        friendly_name: "Overal lighting status"
        unit_of_measurement: '°'
        value_template: >-
          {{ (states.sun.sun.attributes.elevation | float - (states('sensor.weatherbit_cloud_coverage') | float / 30)) | round(1) }}
        icon_template: >-
          {% if (states.sun.sun.attributes.elevation | float - (states('sensor.weatherbit_cloud_coverage') | float / 30)) > 0 %}
          {% else %}
          {% endif %}

It is very simplistic, especially comparing to other solutions I found in this forum, but somehow working quite well for me :slight_smile