basnijholt / adaptive-lighting

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

Adaptive lighting always sets light to 1% #902

Open funkytwig opened 5 months ago

funkytwig commented 5 months ago

Home Assistant Adaptive Lighting Issue Template

Before submitting a bug report, please follow these troubleshooting steps:

Please confirm that you have completed the following steps:

Required information for bug reports:

Please include the following information in your issue.

Issues missing this information may not be addressed.

  1. Debug logs captured while the issue occurred. See here for instructions on enabling debug logging:
Turn off
2024-01-13 18:14:59.771 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'light.turn_off('['light.mbed_bulb_left', 'light.mbed_bulb_right']', transition=None)' event with context.id='01HM20HGXQ966NBJVR023BJ9W3'
2024-01-13 18:14:59.951 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'on' → 'off' event for 'light.mbed_bulb_right' with context.id='01HM20HGXQ966NBJVR023BJ9W3'
2024-01-13 18:14:59.987 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'on' → 'off' event for 'light.mbed_bulb_left' with context.id='01HM20HGXQ966NBJVR023BJ9W3'

Turn On
2024-01-13 18:15:12.747 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (0) _service_interceptor_turn_on_handler: call.context.id='01HM20HXKA3ZE1DXN1D7Y3DNST', is_skipped_hash='False'
2024-01-13 18:15:12.748 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (1) _service_interceptor_turn_on_handler: call='<ServiceCall light.turn_on (c:01HM20HXKA3ZE1DXN1D7Y3DNST): entity_id=['light.mbed_side'], params=>', service_data='{'entity_id': ['light.mbed_side'], 'params': {}}'
2024-01-13 18:15:12.749 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] No switch found for entity_id='light.mbed_side', skipped='['light.mbed_side']'
2024-01-13 18:15:12.750 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (2) _service_interceptor_turn_on_handler: switch_to_eids='{}', skipped='['light.mbed_side']'
2024-01-13 18:15:12.752 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (0) _service_interceptor_turn_on_handler: call.context.id='01HM20HXKA3ZE1DXN1D7Y3DNST', is_skipped_hash='False'
2024-01-13 18:15:12.752 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (1) _service_interceptor_turn_on_handler: call='<ServiceCall light.turn_on (c:01HM20HXKA3ZE1DXN1D7Y3DNST): entity_id=['light.mbed_bulb_left', 'light.mbed_bulb_right'], params=>', service_data='{'entity_id': ['light.mbed_bulb_left', 'light.mbed_bulb_right'], 'params': {}}'
2024-01-13 18:15:12.756 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Switch is off or light is already on for entity_id='light.mbed_bulb_left', skipped='[]' (is_on='True', is_state='False', manual_control='False', switch._intercept='False')
2024-01-13 18:15:12.757 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Switch is off or light is already on for entity_id='light.mbed_bulb_right', skipped='['light.mbed_bulb_left']' (is_on='True', is_state='False', manual_control='False', switch._intercept='False')
2024-01-13 18:15:12.757 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (2) _service_interceptor_turn_on_handler: switch_to_eids='{}', skipped='['light.mbed_bulb_left', 'light.mbed_bulb_right']'
2024-01-13 18:15:12.759 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'light.turn_on('['light.mbed_bulb_left', 'light.mbed_bulb_right']')' event with context.id='01HM20HXKA3ZE1DXN1D7Y3DNST'
2024-01-13 18:15:12.925 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected a 'light.mbed_bulb_right' 'state_changed' event: '{'min_color_temp_kelvin': 2202, 'max_color_temp_kelvin': 4000, 'min_mireds': 250, 'max_mireds': 454, 'effect_list': ['colorloop'], 'supported_color_modes': [<ColorMode.COLOR_TEMP: 'color_temp'>, <ColorMode.XY: 'xy'>], 'color_mode': <ColorMode.COLOR_TEMP: 'color_temp'>, 'brightness': 254, 'color_temp_kelvin': 2202, 'color_temp': 454, 'hs_color': (29.79, 84.553), 'rgb_color': (255, 146, 39), 'xy_color': (0.579, 0.388), 'effect': None, 'off_with_transition': False, 'off_brightness': None, 'friendly_name': 'MBed Bulb Right Light', 'supported_features': <LightEntityFeature.EFFECT|FLASH|TRANSITION: 44>}' with context.id='01HM20HXKA3ZE1DXN1D7Y3DNST'
2024-01-13 18:15:12.926 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'off' → 'on' event for 'light.mbed_bulb_right' with context.id='01HM20HXKA3ZE1DXN1D7Y3DNST'
2024-01-13 18:15:12.926 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01HM20HXKA3ZE1DXN1D7Y3DNST'
2024-01-13 18:15:12.926 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] just_turned_off: State change 'off' → 'on' triggered by 'light.turn_on'
2024-01-13 18:15:12.927 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01HM20HXKA3ZE1DXN1D7Y3DNST'
2024-01-13 18:15:12.930 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] MBed Side Bulbs: '_update_attrs_and_maybe_adapt_lights' called with context.id='01HM20HXRZ:al:JVBG:lght:19' lights: '['light.mbed_bulb_right']', transition: '0.0', force: 'True'
2024-01-13 18:15:12.934 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] MBed Side Bulbs: filtered_lights: '['light.mbed_bulb_right']'
2024-01-13 18:15:12.934 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01HM20HXKA3ZE1DXN1D7Y3DNST'
2024-01-13 18:15:12.935 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] MBed Side Bulbs: Calling _adapt_light from _update_attrs_and_maybe_adapt_lights: 'light.mbed_bulb_right' with transition 0.0 and context.id=01HM20HXRZ:al:JVBG:lght:19
2024-01-13 18:15:12.962 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] MBed Side Bulbs: Setting color_temp of light light.mbed_bulb_right
2024-01-13 18:15:12.963 DEBUG (MainThread) [custom_components.adaptive_lighting.adaptation_utils] Preparing adaptation data for light.mbed_bulb_right with service data {'entity_id': 'light.mbed_bulb_right', 'brightness': 3, 'color_temp_kelvin': 2202}
2024-01-13 18:15:12.963 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] MBed Side Bulbs: execute_cancellable_adaptation_calls with data: AdaptationData(entity_id=light.mbed_bulb_right, context_id=01HM20HXRZ:al:JVBG:lght:19, sleep_time=0.0, force=True, max_length=1, which=both, initial_sleep=False)
2024-01-13 18:15:12.984 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] MBed Side Bulbs: Scheduling 'light.turn_on' with the following 'service_data': {'entity_id': 'light.mbed_bulb_right', 'brightness': 3, 'color_temp_kelvin': 2202} with context.id='01HM20HXRZ:al:JVBG:lght:19'
2024-01-13 18:15:12.992 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected a 'light.mbed_bulb_left' 'state_changed' event: '{'min_color_temp_kelvin': 2202, 'max_color_temp_kelvin': 4000, 'min_mireds': 250, 'max_mireds': 454, 'effect_list': ['colorloop'], 'supported_color_modes': [<ColorMode.COLOR_TEMP: 'color_temp'>, <ColorMode.XY: 'xy'>], 'color_mode': <ColorMode.COLOR_TEMP: 'color_temp'>, 'brightness': 254, 'color_temp_kelvin': 2202, 'color_temp': 454, 'hs_color': (29.79, 84.553), 'rgb_color': (255, 146, 39), 'xy_color': (0.579, 0.388), 'effect': None, 'off_with_transition': False, 'off_brightness': None, 'friendly_name': 'Mbed Bulb Left Light', 'supported_features': <LightEntityFeature.EFFECT|FLASH|TRANSITION: 44>}' with context.id='01HM20HXKA3ZE1DXN1D7Y3DNST'
2024-01-13 18:15:12.993 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'off' → 'on' event for 'light.mbed_bulb_left' with context.id='01HM20HXKA3ZE1DXN1D7Y3DNST'
2024-01-13 18:15:12.993 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01HM20HXKA3ZE1DXN1D7Y3DNST'
2024-01-13 18:15:12.993 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] just_turned_off: State change 'off' → 'on' triggered by 'light.turn_on'
2024-01-13 18:15:12.993 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01HM20HXKA3ZE1DXN1D7Y3DNST'
2024-01-13 18:15:12.994 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] MBed Side Bulbs: '_update_attrs_and_maybe_adapt_lights' called with context.id='01HM20HXV2:al:JVBG:lght:1A' lights: '['light.mbed_bulb_left']', transition: '0.0', force: 'True'
2024-01-13 18:15:12.997 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] MBed Side Bulbs: filtered_lights: '['light.mbed_bulb_left']'
2024-01-13 18:15:13.000 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01HM20HXKA3ZE1DXN1D7Y3DNST'
2024-01-13 18:15:13.000 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] MBed Side Bulbs: Calling _adapt_light from _update_attrs_and_maybe_adapt_lights: 'light.mbed_bulb_left' with transition 0.0 and context.id=01HM20HXV2:al:JVBG:lght:1A
2024-01-13 18:15:13.011 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'light.turn_on('['light.mbed_bulb_right']')' event with context.id='01HM20HXRZ:al:JVBG:lght:19'
2024-01-13 18:15:13.012 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (0) _service_interceptor_turn_on_handler: call.context.id='01HM20HXRZ:al:JVBG:lght:19', is_skipped_hash='False'
2024-01-13 18:15:13.016 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] MBed Side Bulbs: Setting color_temp of light light.mbed_bulb_left
2024-01-13 18:15:13.016 DEBUG (MainThread) [custom_components.adaptive_lighting.adaptation_utils] Preparing adaptation data for light.mbed_bulb_left with service data {'entity_id': 'light.mbed_bulb_left', 'brightness': 3, 'color_temp_kelvin': 2202}
2024-01-13 18:15:13.017 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] MBed Side Bulbs: execute_cancellable_adaptation_calls with data: AdaptationData(entity_id=light.mbed_bulb_left, context_id=01HM20HXV2:al:JVBG:lght:1A, sleep_time=0.0, force=True, max_length=1, which=both, initial_sleep=False)
2024-01-13 18:15:13.026 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] MBed Side Bulbs: Scheduling 'light.turn_on' with the following 'service_data': {'entity_id': 'light.mbed_bulb_left', 'brightness': 3, 'color_temp_kelvin': 2202} with context.id='01HM20HXV2:al:JVBG:lght:1A'
2024-01-13 18:15:13.033 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'light.turn_on('['light.mbed_bulb_left']')' event with context.id='01HM20HXV2:al:JVBG:lght:1A'
2024-01-13 18:15:13.034 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (0) _service_interceptor_turn_on_handler: call.context.id='01HM20HXV2:al:JVBG:lght:1A', is_skipped_hash='False'
2024-01-13 18:15:13.269 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected a 'light.mbed_bulb_right' 'state_changed' event: '{'min_color_temp_kelvin': 2202, 'max_color_temp_kelvin': 4000, 'min_mireds': 250, 'max_mireds': 454, 'effect_list': ['colorloop'], 'supported_color_modes': [<ColorMode.COLOR_TEMP: 'color_temp'>, <ColorMode.XY: 'xy'>], 'color_mode': <ColorMode.COLOR_TEMP: 'color_temp'>, 'brightness': 3, 'color_temp_kelvin': 2202, 'color_temp': 454, 'hs_color': (29.79, 84.553), 'rgb_color': (255, 146, 39), 'xy_color': (0.579, 0.388), 'effect': None, 'off_with_transition': False, 'off_brightness': None, 'friendly_name': 'MBed Bulb Right Light', 'supported_features': <LightEntityFeature.EFFECT|FLASH|TRANSITION: 44>}' with context.id='01HM20HXRZ:al:JVBG:lght:19'
2024-01-13 18:15:13.274 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] AdaptiveLightingManager: New adapt '<state light.mbed_bulb_right=on; min_color_temp_kelvin=2202, max_color_temp_kelvin=4000, min_mireds=250, max_mireds=454, effect_list=['colorloop'], supported_color_modes=[<ColorMode.COLOR_TEMP: 'color_temp'>, <ColorMode.XY: 'xy'>], color_mode=color_temp, brightness=3, color_temp_kelvin=2202, color_temp=454, hs_color=(29.79, 84.553), rgb_color=(255, 146, 39), xy_color=(0.579, 0.388), effect=None, off_with_transition=False, off_brightness=None, friendly_name=MBed Bulb Right Light, supported_features=44 @ 2024-01-13T18:15:12.916318+00:00>' found for light.mbed_bulb_right
2024-01-13 18:15:13.275 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] No transition in last adapt for light light.mbed_bulb_right, not starting timer.
2024-01-13 18:15:13.315 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected a 'light.mbed_bulb_left' 'state_changed' event: '{'min_color_temp_kelvin': 2202, 'max_color_temp_kelvin': 4000, 'min_mireds': 250, 'max_mireds': 454, 'effect_list': ['colorloop'], 'supported_color_modes': [<ColorMode.COLOR_TEMP: 'color_temp'>, <ColorMode.XY: 'xy'>], 'color_mode': <ColorMode.COLOR_TEMP: 'color_temp'>, 'brightness': 3, 'color_temp_kelvin': 2202, 'color_temp': 454, 'hs_color': (29.79, 84.553), 'rgb_color': (255, 146, 39), 'xy_color': (0.579, 0.388), 'effect': None, 'off_with_transition': False, 'off_brightness': None, 'friendly_name': 'Mbed Bulb Left Light', 'supported_features': <LightEntityFeature.EFFECT|FLASH|TRANSITION: 44>}' with context.id='01HM20HXV2:al:JVBG:lght:1A'
2024-01-13 18:15:13.319 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] AdaptiveLightingManager: New adapt '<state light.mbed_bulb_left=on; min_color_temp_kelvin=2202, max_color_temp_kelvin=4000, min_mireds=250, max_mireds=454, effect_list=['colorloop'], supported_color_modes=[<ColorMode.COLOR_TEMP: 'color_temp'>, <ColorMode.XY: 'xy'>], color_mode=color_temp, brightness=3, color_temp_kelvin=2202, color_temp=454, hs_color=(29.79, 84.553), rgb_color=(255, 146, 39), xy_color=(0.579, 0.388), effect=None, off_with_transition=False, off_brightness=None, friendly_name=Mbed Bulb Left Light, supported_features=44 @ 2024-01-13T18:15:12.970162+00:00>' found for light.mbed_bulb_left
2024-01-13 18:15:13.319 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] No transition in last adapt for light light.mbed_bulb_left, not starting timer.
  1. Your Adaptive Lighting configuration:

I have set AL using the Lovelace and do not know how to get the configuration. Looked at README and googled but no joy. Please point me to how to do this and I will add information. However, the configuration has been working for monthes and has not been changed.

  1. Describe the bug and how to reproduce it:

When I turn the light on which used AL it always goes to 1%,

  1. Steps to reproduce the behavior:

turn light to full then turn off and turn on

funkytwig commented 5 months ago

More info

I have been using Adaptive Lighting for about 4 months and up to now it has worked great. I even worked with the comunity ot get parameters added.

I am using

Home Assistant Operating System 11.4
HA 2024.1.3
Adaptive Lighting 1.20.0

I am getting an error when I go at the top of the HACKS page.

https://community-assets.home-assistant.io/original/4X/2/a/3/2a3c0910c38ac07d0a438e36ebbd0619eb6a602f.png

Not sure exactly when this happened. Think it was a couple of days ago. I have kept things up to date but dont think it was one of these updates that caused the problem, but guess it probably was.

Basically all the lights are set to their lowest all the time. Running the date command in ther terminal indicates the date and timezone are correct.

itainoam commented 5 months ago

Also experiencing that. Used to work before.

Also mentioned in this issue: https://github.com/basnijholt/adaptive-lighting/issues/893

WatsCo commented 5 months ago

I believe the reason it's setting it to 1% is because it believe you're stuck in sleep mode, even if it's not night. There is a sleep mode switch. I'd confirm this is set to off.

image

funkytwig commented 5 months ago

Will check but it seems to only be a problem with zigbee bulbs.

schemar commented 5 months ago

I have the same issue since today without doing any updates.

I only have the issue if I set a min sunset time or a max sunset time other than None.

Setting min and max sunset times to None is a workaround for me for now.

dekimsey commented 5 months ago

I should have looked for this thread last week when the problem started :D.

Fiddling with the settings, only altering the integration's sleep mode brightness would address the issue. @WatsCo's suggestion to simply toggle sleep mode was on point! Though I'm not sure why it was enabled, assuming this controls whether the lights are currently in sleep mode (and not the sleep mode feature altogether) it's not clear to me how it got turned on in the first place. Or why it wouldn't have reset at sunrise anyhow.

I have automation that turns on/off the light and more importantly changes the lights colors during the day, so I'll report back if those trip sleep mode again. It's very possible there's an interaction here.

funkytwig commented 5 months ago

When I turn off sleep_brightness and Update it does not turn it off. When I go back in it is still checked. I have tried several times with different Inntergration Entries. The odd thing is I have 2 entries and one works and one does not. I have double checked they are the same. You can not turn off sleep mode on either, they are the same (except the lights) and one works and the other does not. Has anyone tried trying previous versions? Feels if this does not fix it the problem is related to code outside AL.

funkytwig commented 5 months ago

Relating to the above the one that worked was a new Integration Entry I created to troubleshoot the problem. The original one and the new one are both identical, and sleep mode can not be turned off for either but the old one has the problem and the new one does not.

Where are the config files can I look to see if there is something there that is not reflected in the UI?

So the workaround seems to be to create new entries and move lights over.

basnijholt commented 4 months ago

Could it be that your light doesn't correctly define min and max brightness, like:

min_color_temp_kelvin: 2202
max_color_temp_kelvin: 4000

as can be seen in homeassistant.local/developer-tools/state:

image
basnijholt commented 4 months ago

[Copy pasting this message in a few recent open issues]

I just wanted to take a moment to express my heartfelt thanks to everyone that is active in this repo. Your contributions, from answering questions to addressing issues, have been invaluable. It's amazing to see how supportive and helpful our community is!

Adaptive Lighting is all about enhancing your living spaces with smart, sunlight-responsive lighting. We've had quite a few discussions and open issues recently, and I see this as a positive sign of our community's engagement and growth. If you come across anything in the documentation that's unclear or if you have suggestions for improvement, please don't hesitate to share!. Your feedback is crucial for making Adaptive Lighting better for everyone.

On a personal note, I've recently welcomed twin boys into my family, which has been an incredible and life-changing experience. As you can imagine, my time is now more limited, and while I'm doing my best to keep up with the project, there may be delays in my responses. I appreciate your understanding and patience during this time.

Rest assured, I'm fully committed to addressing any bugs, especially those related to new Home Assistant updates, as swiftly as possible. I understand that many issues may stem from hardware limitations or misunderstandings about things like Zigbee groups. Your continued support and collaboration in helping each other out not only strengthen our community but also enhance the Adaptive Lighting experience for all.

Thank you once again for your understanding, patience, and support. Let's keep our houses well lit and adaptive for maximal enjoyment of life! 🌞🏠🌙

Viproz commented 3 months ago

Okay with some additional logging I was able to identify the exact conditions on my system that causes the issue.

For the bug to happen I need to set min_sunset to the right range of value, currently in my area if I set it to 20:30:00 it causes the issue and the light becomes dark just after sunset.

Modified code generating the logs:

    def noon_and_midnight(
        self,
        dt: datetime.datetime,
        sunset: datetime.datetime | None = None,
        sunrise: datetime.datetime | None = None,
    ) -> tuple[datetime.datetime, datetime.datetime]:
        """Return the (adjusted) noon and midnight times for the given datetime."""
        if (
            self.sunrise_time is None
            and self.sunset_time is None
            and self.min_sunrise_time is None
            and self.max_sunrise_time is None
            and self.min_sunset_time is None
            and self.max_sunset_time is None
        ):
            solar_noon = self.astral_location.noon(dt, local=False)
            solar_midnight = self.astral_location.midnight(dt, local=False)
            _LOGGER.error("BBB " + str(solar_noon) + " ////// " + str(solar_midnight))
            return solar_noon, solar_midnight

        if sunset is None:
            sunset = self.sunset(dt)
        if sunrise is None:
            sunrise = self.sunrise(dt)

        middle = abs(sunset - sunrise) / 2
        if sunset > sunrise:
            noon = sunrise + middle
            midnight = noon + timedelta(hours=12) * (1 if midnight.hour < 12 else -1)
        else:
            midnight = sunset + sunset
            noon = midnight + timedelta(hours=12) * (1 if midnight.hour < 12 else -1)
        _LOGGER.error("AAA " + str(noon) + " ////// " + str(midnight) + " ------- " + str(sunset) + " /////// " + str(sunrise) + " //// " + str(middle))
        return noon, midnight

The logs when the light is dark:

2024-04-03 22:31:28.078 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Kitchen: execute_cancellable_adaptation_calls with data: AdaptationData(entity_id=light.strip_kitchen_fridge, context_id=01HTJTHM8J:al:JNUX:ntrv:02, sleep_time=10.0, force=False, max_length=1, which=both, initial_sleep=False) 2024-04-03 22:31:28.079 ERROR (MainThread) [custom_components.adaptive_lighting.color_and_brightness] AAA 2024-04-02 12:01:44.656321+00:00 ////// 2024-04-02 00:01:44.656321+00:00 ------- 2024-04-02 18:30:00+00:00 /////// 2024-04-02 05:33:29.312643+00:00 //// 6:28:15.343678 2024-04-03 22:31:28.082 ERROR (MainThread) [custom_components.adaptive_lighting.color_and_brightness] AAA 2024-04-03 12:00:51.517689+00:00 ////// 2024-04-03 00:00:51.517689+00:00 ------- 2024-04-03 18:30:00+00:00 /////// 2024-04-03 05:31:43.035377+00:00 //// 6:29:08.482312 2024-04-03 22:31:28.084 ERROR (MainThread) [custom_components.adaptive_lighting.color_and_brightness] AAA 2024-04-04 11:59:58.549727+00:00 ////// 2024-04-04 23:59:58.549727+00:00 ------- 2024-04-04 18:30:00+00:00 /////// 2024-04-04 05:29:57.099455+00:00 //// 6:30:01.450272 2024-04-03 22:31:28.086 ERROR (MainThread) [custom_components.adaptive_lighting.color_and_brightness] AAA 2024-04-02 12:01:44.656321+00:00 ////// 2024-04-02 00:01:44.656321+00:00 ------- 2024-04-02 18:30:00+00:00 /////// 2024-04-02 05:33:29.312643+00:00 //// 6:28:15.343678 2024-04-03 22:31:28.088 ERROR (MainThread) [custom_components.adaptive_lighting.color_and_brightness] AAA 2024-04-03 12:00:51.517689+00:00 ////// 2024-04-03 00:00:51.517689+00:00 ------- 2024-04-03 18:30:00+00:00 /////// 2024-04-03 05:31:43.035377+00:00 //// 6:29:08.482312 2024-04-03 22:31:28.090 ERROR (MainThread) [custom_components.adaptive_lighting.color_and_brightness] AAA 2024-04-04 11:59:58.549727+00:00 ////// 2024-04-04 23:59:58.549727+00:00 ------- 2024-04-04 18:30:00+00:00 /////// 2024-04-04 05:29:57.099455+00:00 //// 6:30:01.450272

Notice how the computation for the last sunset is just shy of 48h after the sunset of the day before. To fix the issue in my HA I changed (1 if midnight.hour < 12 else -1) to just -1. This is probably not a proper fix (this code probably fixed another corner case?) but the fact that it works with it confirms the source of the issue.