Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed of sunset/sunrise setting #616

Closed
funkytwig opened this issue Jun 17, 2023 · 27 comments · Fixed by #699
Closed

Speed of sunset/sunrise setting #616

funkytwig opened this issue Jun 17, 2023 · 27 comments · Fixed by #699

Comments

@funkytwig
Copy link

So you can tweak around sunset_offset and sunrise_offset to tell AL the sun is setting/rising earlier/later but I guess there is a curve that is used to say how this happens. I would like to change this. I guess this is affected by where you are.

"The distance from the equator and the path of the sun determines not only the time of sunrise and sunset.....While a sunset near the equator lasts only about 20 minutes, in the United Kingdom, this period averages 50 minutes. In June, it's about 60 minutes in London, while in December it's 41 minutes. "worlddata.info.

I am not saying AL has got this wrong, its just I would like to be able to make my lights dim a bit quicker. Maybe telling changing the curve is a bit much for users, but maybe a sunser_speed and a sunrise_speed percentage maybe 500 to -500%. Think this would only be applied to the main bit of the curve, effectively squashing (maybe) 10% around subset/sunrise (could have a squash_curve_around_sunrise_sunset percent).

If there is anything to do to help let me know. I love the Integration. I had a little look around the code but can't work out how this would be done. Is there some type of document that explains how things are done /fit together?

@th3w1zard1
Copy link
Collaborator

I don't quite understand why sunset_offset and sunrise_offset aren't options here. You say you want your lights to dim by around an hour, wouldn't setting sunset_offset to -3600 allow you to do this?

The percentages used in your example sunset_speed and sunrise_speed just don't make sense as the offsets should already control that. Apologies if I misunderstood something here.

@danielbrunt57
Copy link

I think what he wants is for the duration of sunrise to be either shorter or longer in addition to when it actually starts, which we can do now via sunrise_offset, We should also be able to alter the effective duration of sunrise which is sun.sunriseEnd - sun.sunriseStart. If we had an input like like sunrise_end_offset, we could affect the slope the circadian curve from sun.sunriseStart to sun.sunriseEnd,

At the equator, sunrise duration is only 20 minutes while further north it lengthens to upwards of an hour or more, which leads me to another approach. Rather than using sunrise_offset, allow input of a different location's cordinates for the sun curve, or an input of a +/- number of degrees to add to or subtract from the current location's coordinates. It would depend on Adaptive Lighting's internal coding, whether this is feasible or not.

All food for thought...

@basnijholt
Copy link
Owner

I have started working on #699

@basnijholt
Copy link
Owner

Hi folks, I have implemented this feature request in #699.

That PR allows setting different brightness_modes which determine how the brightness changes around sunrise and sunset. Here brightness_mode can be either "default" (current behavior), "linear", or "tanh". Additionally, when not using "default", you can set brightness_mode_time_dark and brightness_mode_time_light.

with brightness_mode: "linear":

  • During sunset the brightness will start adapting constantly from max_brightness at time=sunset_time - brightness_mode_time_light to min_brightness at time=sunset_time + brightness_mode_time_dark.
  • During sunrise the brightness will start adapting constantly from min_brightness at time=sunrise_time - brightness_mode_time_dark to max_brightness at time=sunrise_time + brightness_mode_time_light.

with brightness_mode: "tanh" it uses the smooth shape of a hyperbolic tangent function:

  • During sunset the brightness will start adapting from 95% of the max_brightness at time=sunset_time - brightness_mode_time_light to 5% of the min_brightness at time=sunset_time + brightness_mode_time_dark.
  • During sunrise the brightness will start adapting from 5% of the min_brightness at time=sunrise_time - brightness_mode_time_dark to 95% of the max_brightness at time=sunrise_time + brightness_mode_time_light.

It would be awesome to get some feedback!

@basnijholt
Copy link
Owner

basnijholt commented Aug 4, 2023

Some more examples:
Notice the values of brightness_mode_time_light and brightness_mode_time_dark in the text box.
image
image
image

@danielbrunt57
Copy link

I for one am anxious to try this out!

@funkytwig
Copy link
Author

Sorry, I have not replied, and thanks for everybody's time replying. Should fo said how I saw the problem, not what I thought the solution was. rucky error. Basically, Inside a building from around 1/2-1 house after sunset, it is (for all intense and purposed) dark but the Adaptive Lighting service takes a lot longer to go to minimum brightness (maybe 2-3 hours). In the morning it is similar. I want it to stay on minimum brightness until the sun starts raising (i.e. start going to max brightness 1/2 house before sunrise and reach max brightness maybe 1 house after sunrise).

So basically I am asking if there is a way of saying how long after sunset minimum darkness is reached. So maybe start reducing brightness 45 mins before sunrise and get to max brightness 45 mins after. This seems about right for the UK.

Sunrise, it is similar. Maybe start getting brighter 45 mins after sunrise and reach max brightness 45 minutes after.

So I guess the second curve is the closest. One way of doing this is to have a number of curves based on total duration min to max brightness around sunset/sunrise. For me, in the UK the curve may be called '1.5-hour transition' (i.e. start diming/britening 45 mins before/after sunset/sunrise)

The curves could be.

  • 1/2 hour transition
  • one-hour transition
  • 1.5 hour transition
  • 2-hour transition

The shortest would be if you were on the equator and the longest if you were furthest from the equator. In brackets, you could also have places or a Curve for each UTC time zone.

Hope this makes sense and is useful. I initially thought it would be numeric parameters but looking at this post curves seem to be the way things are done.

@basnijholt
Copy link
Owner

Please try out version 1.19.0 beta 1 🎉 🚀

@danielbrunt57
Copy link

Installed and reconfigured office lights but I won't be home to observe until tommow night 😭
Sunrise/Sunset offsets now 0.
brightness_mode: tanh
brightness_mode_time_dark: 7200
brightness_mode_time_light: 1800

@danielbrunt57
Copy link

danielbrunt57 commented Aug 6, 2023

@funkytwig You need to get your before's/after's, min/max straight as well as sunrise/sunset! :)

So basically I am asking if there is a way of saying how long after sunset minimum darkness is reached. So maybe start reducing brightness 45 mins before sunrise and get to max brightness 45 mins after. This seems about right for the UK.
Sunrise, it is similar. Maybe start getting brighter 45 mins after sunrise and reach max brightness 45 minutes after.

I think what you want is to start dimming 45 minutes before sunset and reach min brightness 45 minutes after sunset
and for sunrise...
Start brightening 45 minutes before sunrise and reach max brightness 45 minutes after sunrise.

For that, install the beta, change brightness_mode from default to either tanh or linear, set brightness_mode_time_dark and brightness_mode_time_light to 2700 (seconds) which will be start 45 minutes before and end 45 minutes after sunrise/sunset.

@basnijholt
Copy link
Owner

Check out https://basnijholt.github.io/adaptive-lighting/ for an interactive graph.

@funkytwig
Copy link
Author

I think what you want is to start dimming 45 minutes before sunset and reach min brightness 45 minutes after sunset and for sunrise... Start brightening 45 minutes before sunrise and reach max brightness 45 minutes after sunrise.

For that, install the beta, change brightness_mode from default to either tanh or linear, set brightness_mode_time_dark and brightness_mode_time_light to 2700 (seconds) which will be start 45 minutes before and end 45 minutes after sunrise/sunset.

Thanks, You lot rock.

@funkytwig
Copy link
Author

funkytwig commented Aug 7, 2023

Check out https://basnijholt.github.io/adaptive-lighting/ for an interactive graph.

Love it. I take it that if the sunset/sunrise time is not set (in the adaptive lighting add-on) it uses the actual time (i.e. the change does not require the times to be set).

@funkytwig
Copy link
Author

funkytwig commented Aug 7, 2023

Please try out version 1.19.0 beta 1 🎉 🚀

Will give it a go but I've never installed 'manually' Can you point me to a howto to do this?

Also, do I need to disable/remove the current Adaptive Lighting add-on first?

Thanks for everybody's work.

@basnijholt
Copy link
Owner

@funkytwig, I’m HACS there is an option “Show beta versions”:
IMG_3717

@funkytwig
Copy link
Author

@funkytwig, I’m HACS there is an option “Show beta versions”: IMG_3717

How do I get to this screen? I looked at Home Assistant -> Hacks -> Integratinos -> Adaptive Lighting, which judging by the faded background is there you are (Mobile) but can't work out how to get to the pop-up you are on.

Do I need to remove it first?

@danielbrunt57
Copy link

Once you are here...
Screenshot_20230807_102221_Home Assistant
click the three dots top right and select Redownload...
Screenshot_20230807_102354_Home Assistant
which takes you here...
Screenshot_20230807_102449_Home Assistant

@funkytwig
Copy link
Author

LOL, that was the only option I did not try. I feel quiter stupid.

@funkytwig
Copy link
Author

Thanks, done. Set up and will test it tonight. I set offsets to 0 and brightness_time_mode_dark/light to 2700.

I noticed (you will see in the screengrab below) The long descriptions of these parameters go over the edge of the pop-up, not truncated with ...).

Also these default to 900/3600, I was expecting 0. Not sure if that is relevant.

image

@funkytwig
Copy link
Author

OK, notised something else. Can raise another issue if you want. If you remove the offsets and set them blank, rather than set them to 0, it does not work. When you go back they are set to what they were before.

@danielbrunt57
Copy link

"Also these default to 900/3600, I was expecting 0. Not sure if that is relevant."
That is not relevant if brightness_mode is 'default' since the brightness_mode_time... only applies to tanh or linear. 900 & 3600 are only there to act as programmed defaults for tanh & linear.

@danielbrunt57
Copy link

danielbrunt57 commented Aug 7, 2023

OK, notised something else. Can raise another issue if you want. If you remove the offsets and set them blank, rather than set them to 0, it does not work. When you go back they are set to what they were before.

@basnijholt The integration could use better error checking of inputs there....

@danielbrunt57
Copy link

@funkytwig Perhaps you could open a new issue for @basnijholt to keep track of it...

@funkytwig
Copy link
Author

OK. Seems to be working well. 2700 Matched the sunset nicely. As for sunrise not sure when I will be around for it but if it happens will let you know. Nice job.

@funkytwig
Copy link
Author

@funkytwig Perhaps you could open a new issue for @basnijholt to keep track of it...

Will test again and do so.

@basnijholt
Copy link
Owner

Check out this new webapp to visualize the parameters https://basnijholt.github.io/adaptive-lighting/

adaptive-lighting

adaptive-lighting.mp4

@funkytwig
Copy link
Author

Could not sleep last night so got to test whne sun came up and it works. So basic user testig passed :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants