Dim lights based on the sun's elevation

Tags: #<Tag:0x00007f326894f3f8> #<Tag:0x00007f326894f330> #<Tag:0x00007f326894f1c8>

Don’t want bright lights when the sun is setting, or do you want to have a window light that turn on and off automatically at different sun elevations?

This blueprint fade the brightness of lights depending on the elevation of the sun.

Example of use cases:

  • Have bedroom lights that don’t start to dim until the sun is way below the horizon, but stay dim almost until the sun sets and gets brighter and brighter until the sun is over the horizon.

  • Have a window light that turn on automatically just before sunset and let it dim until it’s completely dark outside.

Features:

  • Control one or more lights in each automation.
  • Don’t update the brightness if brightness has been changed manually (by user).
  • Control max and min brightness in percent.
  • Mode to automatically turn on and/or off at sunset/sunrise.
  • Mode to only update brightness if the light is already turned on.
  • NEW: Option to reverse dimming

The Configuration (default value in parenthesis):

  • Select the light entities or light groups to affect

  • The elevation when brightness shall start to change during sunset (0 degrees)

  • The elevation when brightness shall stop to change during sunset (-30 degrees)

  • Toggle if the light shall be turned on when passing the start elevation described above (off)

  • The elevation when brightness shall start to change during sunrise (-8 degrees)

  • The elevation when brightness shall stop to change during sunrise (6 degrees)

  • Toggle if the light shall be turned off when passing the stop elevation described above (off)

  • Max brightness in percent (100%)

  • Min brightness in percent (1%)

  • Transition time (0 seconds)

  • Debug toggle (off)

If a light is manually adjusted, the automation will not touch the light until it has been turned off and on again manually (or at next sunset if automation is configured to automatically turn on the lights).

Blueprint

Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Get the blueprint from GitHib

The Future:
I’m currently working on dynamic elevations. This is useful on places where the elevation change a lot depending on the different seasons.

Feedback:
Please use the issue tracker on GitHub, or write a comment here to report problems or share your ideas for improvements.

3 Likes

I have been using automations based on the sun’s elevation with great success for the past 3 years, but as you mentioned I have to tweak the elevations slightly throughout the year. I have thought about how to combine the elevation and the time of year to eliminate this manual process, but haven’t had the time to make it a reality. If you could make the dynamic elevations work, I would greatly appreciate it FWIW.

1 Like

Feedback on the elevation adjustments throughout the year, you could possibly use the azimuth or even the zenith or put those along with the elevation into a formula to produce a value on an arbitrary scale say 0-100 then base your light brightness on that. The azimuth at elevation 0 will change throughout the year and should account for daylight saving time. This could even be expanded to control of shades throughout the day.

1 Like

I have thought about how to combine the elevation and the time of year to eliminate this manual process,

Yes one idé have been to set percent from max elevation for the day and the possibility to use time/azimuth to start the dimming.

you could possibly use the azimuth or even the zenith or put those along with the elevation into a formula to produce a value on an arbitrary scale say 0-100 then base your light brightness on that. The azimuth at elevation 0 will change throughout the year and should account for daylight saving time.

This is interesting. I’ll do some calculations.

I have already calculated the max elevation for the day and also max an min elevation över the year. This tell me about the variation (which also the latitude does in some way ofcourse).

Thanks for the feedback. I’ll look into this.

I use circadian-lighting, does the same job perfectly for me

I just pushed some bug fixes and also improvements to the debug feature.

Just fixed a problem when catching events where an affected light just has been switched on and shall be set to the correct brightness. Updated blueprint is available on GithHub

Hi.

Newbie HA user here so I apologize that I don’t understand everything or ask questions in the wrong place.

I was trying to make my yard lights turn on at sunset and dimming based on the sun elevation to minimum against the night. Then in the morning brighten again and turn off at sunrise. Your blueprint seemed perfect for that but it doesn’t work how was I was planning.

Now if I toggle switch “Turn on lights when sun is setting” to ON, my lights turn on that point what I have set to “Elevation of the sun to start dim the light when the sun is set.” Is this what should happen or is it wrong behavior? Lights start to dim from that point where they turn on and then again brighten at morning and turn off so automation is working OK I think.

Should I forget that option and make another automation to turn lights on at sunset?

Thanks.

Now if I toggle switch “Turn on lights when sun is setting” to ON, my lights turn on that point what I have set to “Elevation of the sun to start dim the light when the sun is set.” Is this what should happen or is it wrong behavior?

This is the correct behavior.

Let me try to explain the logic a bit more in depth.

If you don’t have the turn on at sunset nor turn off at sunrise options set, then the automation will only set the brightness after you have manually turned on the light and it will stay on until you manually turn the light off again.

However, if you have checked the Turn On when sun is setting feature, then the light will automatically turn on.

It will only turn on when the following happens:

  • When the sun’s elevation changes
    AND
  • the new elevation is lower or equal to the value you have specified as the sun’s elevation when the light shall start to get more dim
    AND
  • the previous elevation was greater than the value you have specified as the sun’s elevation when the light shall start to get more dim

Example. You have specified that the light shall start to dim when the sun’s elevation gets below or equal to 2°

State changes to 3 degrees (from 5 degrees)
Light is still off

State change to 1.2 degrees (from 3 degrees)
Light will be turned on (2 which you have specified is between 1.2 and 3)

State change to -0.5 degrees
Light stays on (but will NOT be turned on if it was manually turned off)

If you change the brightness manually at any time, the automation will not touch the brightness until the light has been turned off and on again.

When the sun is rising, the same thing happens but the other way around.

Should I forget that option and make another automation to turn lights on at sunset?

You don’t need two automations to both turn on and off the light.

I hope this made things a bit more clear?

Please note that updates to the blueprint was made last weekend, so make sure to update if you installed it before that.

Have you thought about a physical sensor to track when the sun is below a certain angle. If being in certain locations causes the angle at the time of day to vary over the year it may be an option.

There is a solar panel tracker than may be suitable.

Normally it determines if one sensor has more light than the other and drives a motor holding a panel towards the sensor that has more light, keeping the panel at a right angle to the sun. As such it seems to have a binary output.

If it was mounted on a base with a divider between the sensors and the divider was set at the angle when ON/OFF was required for your automation it could be left in that position with no adjustment needed seasonally.

Norm.

I have planned on implementing combination with time and/or sun azimuth. However it would be nice to have conditional gui for the settings of the blueprint in that case.

I have already written parts of it, but haven’t got the time lately to get it done

I wonder if I have understood this correctly. When the sun goes down the brightness of the lamp increases to the value I choose and when the sun goes up it decreases? I would like the lamp to start shining brightly and dimming when it gets darker outside, is that possible?

1 Like

That is how it works.

The higher the sun angle the brighter the light will shine.

At midnight it will be the most dim and at noon it will be at maximum brightness (as long as the specified sun angles are within the min and max elevation of the sun that particular day).

The purpose of this is to be able to have use of the light even if there still is some daylight outside and then it gets more dim when the sun sets further down.

It would be possible to have a toggle that reverse the setting or simply allow that the min value is greater than the max value in the configuration.

Okay, that’s exactly how I want it to work :slight_smile: I had probably misunderstood it when I installed the Blueprint. Thanks!

1 Like

Okay so I have now tested this blueprint for a couple of days. But it does not work properly for me… My lamp starts to shine at 90% @6 degrees when sun is setting which is correct. But it never starts to dim? Could it be a problem when I have the sunrise @6 degrees as well?

May I see your configuration?

Basically the settings for when the sun is rising are separate from when the sun is setting. For instance you might want to make it dim quite a long time in the evening but for just a couple of degrees in the morning.

Okay i hope this picture helps :slight_smile:

Yes that looks valid.

Do you get anything in the log?
If not, could you make sure you have activated logger in your configuration.yaml and turn on debug in the automation?

What hardware are you running this on?

Could you try to manually update the elevation of the sun.sun entity in developer tools in lovelace to see if any thing happens?

Could you try to change the transition to something else than 0 just to rule out something there?

I did not have the debug activated, but now it is! Maby i get some logs tonight.
I am running Hass io on a raspberry pie. Everything is updated.
I tried to change the elevation in the developer tools, it seems to be something wiered there. I got the lamp to dim when i put in -30 degrees. But i can not get it to shine brighter again.

This works randomly, sometimes nothing happens. If i change the value and turn off and on the lamp manually it takes the new value.

1 Like