Dim lights based on the sun's elevation

Hello to all! Glad to join this great community…I must say that I am a newbie… Got my Raspberry 2 weeks ago…
I installed this blueprint, and it seems the work well… But I have an issue…
It works perfectly when I turn the lamp on through HA…
But then I turn it on through Smart Life or Alexa, it doesn’t work… Seems it doesn’t start the full process…
Any clue on what I should do to have it work also when turning off by Smart Life and Alexa?
Thanks in advance for your support

@mukens Hey thanks for the awesome contribution this blueprint is great! I just had one issue, I noticed that it is activated by a call_service and was wondering if their was any way to trigger it by a state_changed instead. Ex when my lights are turned on by a motion sensor they work great and dim like they should but when they are turned on by a Kasa dimmer switch the automation does not trigger due to the lights not being turned on by a call_service.
Thanks for your time!

I remember there was some problem with state change when I created it, but can’t remember what at the moment.

Unfortunately I don’t have the time right now to look into it, buy I’d be happy to receive pull requests from anyone willing to add that functionality.

I just ended up finding a work around, I used a node red device trigger to activate a call_service. so the switch turns on then home assistant registers the change state and fires the lights to turn on again which activates the automation. Thanks!

I just want to make sure I properly understand the way elevation works. So the solar elevation angle is NOT the same as degrees above horizon…

Here’s a calculator example

per my values, roughly placed in the upper left USA, using your default values, but turning on light at sunset and off at sunrise, sun should set at 4:20pm which would mean the elevation would be roughly -62.75…

|16:00|-61.34|331.22|
|16:15|-62.42|338.26|
|16:30|-63.20|345.71|

then this automation by default should start dimming the light from 100% when elevation is at 0, it seems like the 0 elevation is to clear a threshold, 4:20pm the elevation is at -62 it should start dimming right away and be completely dim when elevation is at -30, which in this case on that specific date is 9:35pm or so.

|21:15|-32.89|86.53|
|21:30|-30.37|89.36|
|21:45|-27.85|92.12|

Then the default value is to start brightening when elevation is -8, which would be at 11:35pm or so.

|23:30|-10.69|110.50|
|23:45|-8.36|113.12|
|24:00|-6.06|115.77|

it should be max brightness when elevation is 6 which roughly is after 1:17am Or so.

|01:15|4.96|129.60|
|01:30|6.82|132.54|
|01:45|8.61|135.55|

the lights should turn off completely at sunrise, which in my case is 7:36am, roughly 12.90 or something elevation

|07:30|12.85|216.13|
|07:45|11.31|219.33|
|08:00|9.68|222.45|

BUT all of this is ONLY possible if you’ve not messed around with turning the lights on or off at any point…

HOWEVER if you wanted to “ignore” the brightening again feature you could set your elevation from -60 to -55, at least in my part of the world.

Also sorry for being so dense… I don’t remember this at all from school.

Is this still a limitation? I use KNX and it doesn’t trigger the service when putting on the lights. The state change is registered correctly, but I tried changing that in the blueprint, but then it doesn’t do anything anymore.

For me the workaround was to create an automation that would trigger a script that would trigger the dimming automation every time the light state was changed to “on”. It also solves other issues if you also have scenes that control dimming for the same lights.

  1. automation to dim with a low “change allowance”. So i could manually change the brightness when needed. This one is always on.
  2. clone of first automation but with a 100% change allowance. This one is off by default.
  3. script that woudl turn on, trigger and turn off the second automation after 10 seconds.
  4. automation that would run the script every time the lights state changed to “on”

This could probably be done in a more sophisticated manner but it works for me.

Now i can change the brightness when needed and every time the light is turned on (by a switch) the light is dimmed according to the sun elevation. Also now you can have other scenes (like movie lights) that control the brightness of the same lights without them reverting back to the sun elevation.

The script that basically tells the lights to dim now according to the sun elevation comes in handy with other scenes when i want to switch back to sun elevation dimming after i have changed the brightness manually or with a scene like “movie lights”.

I use the blueprint on my living room and kitchen lights and its almost perfect. Only issue is that i have to tweak the elevations every few months to adjust with the seasons. It can get dark very early in the winter.

1 Like

Thank you for the tip. Was scratching my head trying to figure out why I couldn’t get this working. Switched over to entity from the blueprint page and worked right away!

Instead of choosing a ‘device,’ choose an entity

1 Like

I’m not sure if the light is supposed to turn off completely or not, but mine isn’t and I’d like it to.

My use is for my chicken coop. I have an LED strip that I use as a light for them. I have it turn on about 30 minutes before sun down and then ideally, turn off completely about 45 minutes after sun down (I also have a door that closes about 30 minutes after sun down). Right now, the LED strip goes to 1% and then hangs there, so, it’s still light enough for them to jump up and down off their roost and not go to sleep, lol

Or do I need to add a second automation to turn the light off X amount of time after sunset?

Yes, the light only turn off at sunrise.
So a second automation would be needed and it’s pretty straight forward since you already know at which elevation you stop dimming the light. Just add an automation that trigger at a lower elevation to turn off the light.

1 Like

I ended up setting that up last night and seems to be working. Would love to have it all in one spot, but this works just the same. Thanks for confirming :slight_smile:

1 Like

Well, it might be possible to add that by allowing the light to go to 0% to indicate turn off maybe… I’ll think about it.

1 Like

Thanks for the blueprint, I love it that my lights are automatically dimmed in the morning and evening. The only “problem” is that the automation isn’t triggered when the lights are turned on by a wall switch and they shine in full brightness until I turn them off and on again via the app or a Hue Dimmer Switch. As I read above this has something to do with the trigger via “call_service”. Does anyone have a workaround for this, I’m new to Home Assistant so please “explain me like I’m 5”? :slight_smile: Thanks!

1 Like

There are any option to start light only when a person is home?

1 Like

I think the easiest way to do that is to create an automation that trigger when any person comes home or leave home and the automation enables or disables the dim lights automation.

So when leaving home, the dim lights automation is turned off using service homeassistant.turn_off and optionally turns off the light. When coming home the automation instead call homeasistant.turn_on to turn on the dim lights automation that was created from the blueprint.

Is it possible to reverse the action?, start brightening at sunrise to full brightness by 8am, and start dimming at sunset to off by 8pm?

1 Like

There is a reverse toggle button, but I’m not sure it will handle turn on/off correctly for you.

I have set it up for reverse, but won’t know the effects I guess until tomorrow AM, I did set it up initially without the reverse option, but it didn’t seem to work though, thanks.

So, is it dimming to 0, and not turning off the light?

First off huge Thank you for the blueprint!!!

Is there an actual you can read automation or config example? I read the entire post but am hoping someone will be kind enough to share their formatted automation/config. I’m also needing to use this in reverse…

Thank you all!