basnijholt / adaptive-lighting

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

Sun Events Order Error #990

Open vladimir1408v opened 1 month ago

vladimir1408v commented 1 month ago

I've been trying to identify an issue for several days now. When I enable the switch.adaptive_lighting_light, I encounter the following error:

_The sun events ('solar_midnight', 'solarnoon', 'sunset', 'sunrise') are not in the expected order. The Adaptive Lighting integration will not work! This might happen if your sunrise/sunset offset is too large or your manually set sunrise/sunset time is past/before noon/midnight.

I have examined the code and attempted to understand why this is happening. My settings in HA are correctly configured, with the timezone and location being accurate. I create a configuration from scratch, opting only for control and not changing anything else in the integration, yet I still receive this error. Please help.

vladimir1408v commented 1 month ago
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/opt/var/lib/homeassistant/custom_components/adaptive_lighting/switch.py", line 1141, in _async_update_at_interval_action
    await self._update_attrs_and_maybe_adapt_lights(
  File "/opt/var/lib/homeassistant/custom_components/adaptive_lighting/switch.py", line 1372, in _update_attrs_and_maybe_adapt_lights
    self._sun_light_settings.get_settings(
  File "/opt/var/lib/homeassistant/custom_components/adaptive_lighting/color_and_brightness.py", line 390, in get_settings
    return self.brightness_and_color(dt, is_sleep)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/var/lib/homeassistant/custom_components/adaptive_lighting/color_and_brightness.py", line 337, in brightness_and_color
    sun_position = self.sun.sun_position(dt)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/var/lib/homeassistant/custom_components/adaptive_lighting/color_and_brightness.py", line 176, in sun_position
    (_, prev_ts), (next_event, next_ts) = self.prev_and_next_events(dt)
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/var/lib/homeassistant/custom_components/adaptive_lighting/color_and_brightness.py", line 164, in prev_and_next_events
    events = [
             ^
  File "/opt/var/lib/homeassistant/custom_components/adaptive_lighting/color_and_brightness.py", line 167, in <listcomp>
    for event in self.sun_events(dt + timedelta(days=days))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/var/lib/homeassistant/custom_components/adaptive_lighting/color_and_brightness.py", line 145, in sun_events
    self._validate_sun_event_order(events)
  File "/opt/var/lib/homeassistant/custom_components/adaptive_lighting/color_and_brightness.py", line 160, in _validate_sun_event_order
    raise ValueError(msg)
ValueError:  The sun events ('solar_midnight', 'solar_noon', 'sunset', 'sunrise') are not in the expected order. The Adaptive Lighting integration will not work! This might happen if your sunrise/sunset offset is too large or your manually set sunrise/sunset time is past/before noon/midnight.
vladimir1408v commented 1 month ago

If you set the sunrise_time parameter, then everything starts working, why is this so?