basnijholt / adaptive-lighting

Adaptive Lighting custom component for Home Assistant
https://basnijholt.github.io/adaptive-lighting/
Apache License 2.0
1.86k stars 135 forks source link

Adaptive lightning doesn't work at all if sun is always above the horizon #138

Open lurandly opened 3 years ago

lurandly commented 3 years ago

I noticed adaptive lightning doesn't control lights anymore yesterday. Every light started from 5% and changing brightness and turning lights on/off did nothing. Log message below keeps repeating every minute. Around summer solstice sun doesn't set at all where I live.

ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/astral/sun.py", line 812, in sunset
return time_of_transit(
File "/usr/local/lib/python3.8/site-packages/astral/sun.py", line 356, in time_of_transit
hourangle = hour_angle(
File "/usr/local/lib/python3.8/site-packages/astral/sun.py", line 243, in hour_angle
HA = acos(h)
ValueError: math domain error
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/config/custom_components/adaptive_lighting/switch.py", line 738, in _async_update_at_interval
await self._update_attrs_and_maybe_adapt_lights(
File "/config/custom_components/adaptive_lighting/switch.py", line 851, in _update_attrs_and_maybe_adapt_lights
self._settings = self._sun_light_settings.get_settings(
File "/config/custom_components/adaptive_lighting/switch.py", line 1149, in get_settings
percent = self.calc_percent()
File "/config/custom_components/adaptive_lighting/switch.py", line 1112, in calc_percent
today = self.relevant_events(now)
File "/config/custom_components/adaptive_lighting/switch.py", line 1100, in relevant_events
events = [
File "/config/custom_components/adaptive_lighting/switch.py", line 1101, in <listcomp>
self.get_sun_events(now + timedelta(days=days)) for days in [-1, 0, 1]
File "/config/custom_components/adaptive_lighting/switch.py", line 1059, in get_sun_events
location.sunset(date, local=False)
File "/usr/local/lib/python3.8/site-packages/astral/location.py", line 381, in sunset
return astral.sun.sunset(observer, date)
File "/usr/local/lib/python3.8/site-packages/astral/sun.py", line 822, in sunset
raise ValueError(msg) from exc
ValueError: Sun is always above the horizon on this day, at this location.
RubenKelevra commented 2 years ago

Hey @lurandly,

sorry for the long delay. Please understand that the resources of the team was pretty limited in the last month.

The v1 has a feature freeze and while I would consider this more of a bug, I will still move it to v2 since it will be fixed there naturally as most stuff gets revisited or rewritten.

Keep this ticket open until you can verify that it's properly working in the upcoming version 2.

RubenKelevra commented 2 years ago

Hey @lurandly,

I would like to hear your opinion how this should work ideally. I mean, should adaptive lighting "emulate" a night for you, or should it reflect the outside conditions including no night?

GregWoods commented 2 years ago

I was about to raise an issue for my use case which seems closely related to this. I don't live far enough north to have zero nightime, but there is still significant differences between summer and winter

The following are all my local times Shortest day: sunrise: 08:30 Sunset: 15:50 Longest day: sunrise: 04:40 Sunset: 21:48

These are just too extreme for me. I don't want to wake up in the morning in summer to go to the bathroom, to be blinded by full spectrum "daylight" And in winter I want to extend the productive part of the day and help combat seasonal affective disorder.. not increase it!

One Solution One solution is simply to add a setting to set a location for sunrise/sunset. Clicking around https://sunrisesunsetmap.com/ I can move my fake location further south to reduce the differences between summer and winter. I can also move west to bias the daylight times towards evening rather than early morning.

Doing this, I've decided I'd like to live in Lisbon. or maybe the Azores. There is still plenty of difference between summer and winter, but it is less extreme.

I'd be interested to know feedback. If I've misinterpreted Issue 138, I can raise this as a separate feature/enhancement, and if it has already been raised, my apologies.