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

AL fails to detect native HA turning on of Hue lights (eg light.turn_on service call) and marks them all as manually controlled. Workaround is to enable "detect_non_ha_changes" but that's unreliable #1021

Closed ncd7 closed 3 weeks ago

ncd7 commented 3 months ago

Home Assistant Adaptive Lighting Issue Template

Bug Reports

EDIT: this seems like a worse regression than I thought originally. AL somehow doesn't detect turning ON of a hue lights entity which represents a hue group through HA. E.g. if I turn on the lights using the Light Turn On HA service I see this in the logs.

2024-07-05 16:02:46.689 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Bedroom: Ignoring 'off' → 'on' event for 'light.nbr_window_1' with context.id='01J227VY8KS079NXXH8BCWZ3WJ' because 'light.turn_on' was not called by HA and 'detect_non_ha_changes' is False I will try to enable detect_non_ha_changes for now but I dislike having that setting on. This might have been caused by the most recent change of HA changing details of how it advertises turning lights on that is incompatible with LA's detection logic.

This seems to only be the case for light entities which are a hue group (using the official built-in Hue integration of Home Assistant).

Given this configuration

configuration (take from the attribute of the switch as I don't use YAML for AL): 
lights:   - light.north_bedroom
interval: 45
transition: 20
initial_transition: 8
min_brightness: 1
max_brightness: 100
min_color_temp: 1675
max_color_temp: 7000
prefer_rgb_color: false
sleep_brightness: 1
sleep_rgb_or_color_temp: rgb_color
sleep_color_temp: 1000 
sleep_rgb_color:   - 92   - 54   - 0 
sleep_transition: 900
transition_until_sleep: false 
take_over_control: true
detect_non_ha_changes: false
autoreset_control_seconds: 0
only_once: false
adapt_only_on_bare_turn_on: true
separate_turn_on_commands: false
send_split_delay: 0
adapt_delay: 0
skip_redundant_commands: false
intercept: true
multi_light_intercept: true
include_config_in_attributes: true

And assuming light.north_bedroom is a hue light group that controls N number of other lights. If you turn on light.north_bedroom without requesting manual control (i.e. a simple light turn on) BEFORE is empty as such: manual_control: NOW manual_control: light.1, light.2, light.3, light.4 where those lights 1, 2, 3 are the actual lights in the light.north_bedroom light group.

Was this change by design or unintentional? This looks like a really bad bug.

Thank you.

theOrakle commented 3 months ago

I experienced the same... In order to get it in working order, I had to re-enable all the low level lights exposed by Hue. This is not desired as it overwhelmed hue hub when you have a large amount of lights.

ncd7 commented 3 months ago

Actually, the bud seems to be worse than I thought. Manual control now always shows all individual lights when the light turns on even when manual control has not been requested

ncd7 commented 2 months ago

My current workaround is that each time after issuing a service call lights.turn_on, i must then set manual control to FALSE to get things to work as they used to. It's really onerous and can obviously only work if lights are turned on via some automation/service call. I'm not sure how this bug happened, perhaps it's something to do with a recent HA core update but either way it's making things rough to use :(.

thecastle20 commented 2 months ago

I'm getting the exact same thing, hue bridge and lights are being marked 'manual control' on turn on. Turning off/on the light is supposed to reset it but doesn't. Seems to be something that broke during an HA core update...

Dante12129 commented 2 months ago

I experienced the same... In order to get it in working order, I had to re-enable all the low level lights exposed by Hue. This is not desired as it overwhelmed hue hub when you have a large amount of lights.

Do you mean you have both the Hue group and the lights contained in the Hue group in the Adaptive Lighting configuration?

Dante12129 commented 2 months ago

I am seeing the same behavior. Now bare light.turn_on calls are resulting in the lights being marked as manually controlled. I've also found that calling adaptive_lighting.apply doesn't clear out those lights marked as manually controlled, only turning off or using the set_manual_control service.

ncd7 commented 2 months ago

I experienced the same... In order to get it in working order, I had to re-enable all the low level lights exposed by Hue. This is not desired as it overwhelmed hue hub when you have a large amount of lights.

Do you mean you have both the Hue group and the lights contained in the Hue group in the Adaptive Lighting configuration?

No, that would be a mistake. I ONLY have the Hue groups as it's the only sane way to do things. it had been working fine for many months but recently it is definitely very broken.

ncd7 commented 2 months ago

I'm really surprised more people aren't experiencing this. I don't have anything custom in my setup and philips hue (and using light groups) is pretty standard for HA.

brechtvhb commented 2 months ago

I am also having this problem 😥

rarnken commented 2 months ago

Same here. Anything I can do to help?

basnijholt commented 2 months ago

Can anyone verify by sharing their logs that this is actually happening as stated?

JN-Jones commented 2 months ago

Same happening here. I've the "flur_hinten" hue light group which internally consists of two light bulbs which I've both deactivated in HA. Logs for this:

2024-07-23 18:54:13.935 WARNING (MainThread) [homeassistant.helpers.frame] Detected that custom integration 'adaptive_lighting' calls async_forward_entry_setup for integration, adaptive_lighting with title: Main and entry_id: 7779c8ad148955aee214b2f07f44757c, which is deprecated and will stop working in Home Assistant 2025.6, await async_forward_entry_setups instead at custom_components/adaptive_lighting/__init__.py, line 69: hass.async_create_task(, please create a bug report at https://github.com/basnijholt/adaptive-lighting/issues
2024-07-23 18:54:13.937 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Setting up AdaptiveLighting with data: {'7779c8ad148955aee214b2f07f44757c': {'undo_update_listener': <function ConfigEntry.add_update_listener.<locals>.<lambda> at 0x7f89a40e00>}} and config_entry <ConfigEntry entry_id=7779c8ad148955aee214b2f07f44757c version=1 domain=adaptive_lighting title=Main state=ConfigEntryState.SETUP_IN_PROGRESS unique_id=Main>
2024-07-23 18:54:13.947 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] State of light.tv is None
2024-07-23 18:54:13.947 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] State of light.stehlampe is None
2024-07-23 18:54:13.947 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] State of light.bad is None
2024-07-23 18:54:13.947 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] State of light.kueche_links is None
2024-07-23 18:54:13.948 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] State of light.kueche_rechts is None
2024-07-23 18:54:13.948 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] State of light.schlafzimmer_tisch is None
2024-07-23 18:54:13.948 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] State of light.flur_hinten is None
2024-07-23 18:54:13.948 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] State of light.flur_vorne is None
2024-07-23 18:54:13.949 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Main: Set switch settings for lights '['light.bad', 'light.flur_hinten', 'light.flur_vorne', 'light.kueche_links', 'light.kueche_rechts', 'light.schlafzimmer_tisch', 'light.stehlampe', 'light.tv']'. now using data: '{'lights': ['light.tv', 'light.stehlampe', 'light.bad', 'light.kueche_links', 'light.kueche_rechts', 'light.schlafzimmer_tisch', 'light.flur_hinten', 'light.flur_vorne'], 'interval': datetime.timedelta(seconds=90), 'transition': 45.0, 'initial_transition': 1.0, 'min_brightness': 30, 'max_brightness': 100, 'min_color_temp': 2000, 'max_color_temp': 5500, 'prefer_rgb_color': False, 'sleep_brightness': 20, 'sleep_rgb_or_color_temp': 'color_temp', 'sleep_color_temp': 1000, 'sleep_rgb_color': [255, 56, 0], 'sleep_transition': 1.0, 'transition_until_sleep': False, 'sunrise_time': None, 'min_sunrise_time': datetime.time(5, 0), 'max_sunrise_time': datetime.time(7, 0), 'sunrise_offset': datetime.timedelta(0), 'sunset_time': None, 'min_sunset_time': datetime.time(20, 0), 'max_sunset_time': datetime.time(23, 0), 'sunset_offset': datetime.timedelta(0), 'brightness_mode': 'tanh', 'brightness_mode_time_dark': datetime.timedelta(seconds=5000), 'brightness_mode_time_light': datetime.timedelta(seconds=9000), 'take_over_control': True, 'detect_non_ha_changes': True, 'autoreset_control_seconds': 0, 'only_once': False, 'adapt_only_on_bare_turn_on': True, 'separate_turn_on_commands': False, 'send_split_delay': 0, 'adapt_delay': 0.0, 'skip_redundant_commands': False, 'intercept': True, 'multi_light_intercept': True, 'include_config_in_attributes': False, 'name': 'Main'}'
2024-07-23 18:54:13.950 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Main: Setting up with '['light.bad', 'light.flur_hinten', 'light.flur_vorne', 'light.kueche_links', 'light.kueche_rechts', 'light.schlafzimmer_tisch', 'light.stehlampe', 'light.tv']', config_entry.data: '{'name': 'Main'}', config_entry.options: '{'lights': ['light.tv', 'light.stehlampe', 'light.bad', 'light.kueche_links', 'light.kueche_rechts', 'light.schlafzimmer_tisch', 'light.flur_hinten', 'light.flur_vorne'], 'interval': 90, 'transition': 45.0, 'initial_transition': 1.0, 'min_brightness': 30, 'max_brightness': 100, 'min_color_temp': 2000, 'max_color_temp': 5500, 'prefer_rgb_color': False, 'sleep_brightness': 20, 'sleep_rgb_or_color_temp': 'color_temp', 'sleep_color_temp': 1000, 'sleep_rgb_color': [255, 56, 0], 'sleep_transition': 1.0, 'transition_until_sleep': False, 'sunrise_time': 'None', 'min_sunrise_time': '05:00:00', 'max_sunrise_time': '07:00:00', 'sunrise_offset': 0, 'sunset_time': 'None', 'min_sunset_time': '20:00:00', 'max_sunset_time': '23:00:00', 'sunset_offset': 0, 'brightness_mode': 'tanh', 'brightness_mode_time_dark': 5000, 'brightness_mode_time_light': 9000, 'take_over_control': True, 'detect_non_ha_changes': True, 'autoreset_control_seconds': 0, 'only_once': False, 'adapt_only_on_bare_turn_on': True, 'separate_turn_on_commands': False, 'send_split_delay': 0, 'adapt_delay': 0.0, 'skip_redundant_commands': False, 'intercept': True, 'multi_light_intercept': True, 'include_config_in_attributes': False}', converted to '{'lights': ['light.tv', 'light.stehlampe', 'light.bad', 'light.kueche_links', 'light.kueche_rechts', 'light.schlafzimmer_tisch', 'light.flur_hinten', 'light.flur_vorne'], 'interval': datetime.timedelta(seconds=90), 'transition': 45.0, 'initial_transition': 1.0, 'min_brightness': 30, 'max_brightness': 100, 'min_color_temp': 2000, 'max_color_temp': 5500, 'prefer_rgb_color': False, 'sleep_brightness': 20, 'sleep_rgb_or_color_temp': 'color_temp', 'sleep_color_temp': 1000, 'sleep_rgb_color': [255, 56, 0], 'sleep_transition': 1.0, 'transition_until_sleep': False, 'sunrise_time': None, 'min_sunrise_time': datetime.time(5, 0), 'max_sunrise_time': datetime.time(7, 0), 'sunrise_offset': datetime.timedelta(0), 'sunset_time': None, 'min_sunset_time': datetime.time(20, 0), 'max_sunset_time': datetime.time(23, 0), 'sunset_offset': datetime.timedelta(0), 'brightness_mode': 'tanh', 'brightness_mode_time_dark': datetime.timedelta(seconds=5000), 'brightness_mode_time_light': datetime.timedelta(seconds=9000), 'take_over_control': True, 'detect_non_ha_changes': True, 'autoreset_control_seconds': 0, 'only_once': False, 'adapt_only_on_bare_turn_on': True, 'separate_turn_on_commands': False, 'send_split_delay': 0, 'adapt_delay': 0.0, 'skip_redundant_commands': False, 'intercept': True, 'multi_light_intercept': True, 'include_config_in_attributes': False, 'name': 'Main'}'.
2024-07-23 18:54:13.952 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Adaptive Lighting Sleep Mode: Main: last state is <state switch.adaptive_lighting_sleep_mode_main=off; icon=mdi:sleep, friendly_name=Adaptive Lighting Sleep Mode: Main @ 2024-07-23T05:39:34.020566+02:00>
2024-07-23 18:54:13.952 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Adaptive Lighting Sleep Mode: Main: Turning off
2024-07-23 18:54:13.954 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Adaptive Lighting Adapt Color: Main: last state is <state switch.adaptive_lighting_adapt_color_main=on; icon=mdi:sun-thermometer, friendly_name=Adaptive Lighting Adapt Color: Main @ 2024-07-19T20:53:54.296184+02:00>
2024-07-23 18:54:13.955 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Adaptive Lighting Adapt Color: Main: Turning on
2024-07-23 18:54:13.956 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Adaptive Lighting Adapt Brightness: Main: last state is <state switch.adaptive_lighting_adapt_brightness_main=on; icon=mdi:brightness-4, friendly_name=Adaptive Lighting Adapt Brightness: Main @ 2024-07-19T20:53:54.297006+02:00>
2024-07-23 18:54:13.956 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Adaptive Lighting Adapt Brightness: Main: Turning on
2024-07-23 18:54:13.958 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Main: Called 'async_turn_on', current state is 'None'
2024-07-23 18:54:13.958 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Main: Called '_setup_listeners'
2024-07-23 18:54:13.958 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Main: Cancelled '_setup_listeners'
2024-07-23 18:54:13.959 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Main: '_update_attrs_and_maybe_adapt_lights' called with context.id='01J3G87MP6:al:JVQW:trn_:00' lights: 'None', transition: '1.0', force: 'True'
2024-07-23 18:54:13.962 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Main: filtered_lights: '[]'
2024-07-23 18:55:26.180 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Main: Called '_setup_listeners'
2024-07-23 18:55:26.181 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Expanded light.bad to {'light.bad_rechts', 'light.bad_links'}
2024-07-23 18:55:26.182 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Expanded light.flur_hinten to {'light.hue_ambiance_spot_4', 'light.hue_ambiance_spot_2'}
2024-07-23 18:55:26.182 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Expanded light.flur_vorne to {'light.hue_ambiance_spot_3', 'light.hue_ambiance_spot_1'}
2024-07-23 18:55:36.152 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (0) _service_interceptor_turn_on_handler: call.context.id='01J3G8A4WH2X59SGMHSX9ND3N0', is_skipped_hash='False'
2024-07-23 18:55:36.153 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (1) _service_interceptor_turn_on_handler: call='<ServiceCall light.turn_on (c:01J3G8A4WH2X59SGMHSX9ND3N0): entity_id=['light.flur_hinten'], params=>', service_data='{'entity_id': ['light.flur_hinten'], 'params': {}}'
2024-07-23 18:55:36.154 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] State of light.bad_links is None
2024-07-23 18:55:36.154 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] State of light.bad_rechts is None
2024-07-23 18:55:36.154 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] State of light.hue_ambiance_spot_1 is None
2024-07-23 18:55:36.154 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] State of light.hue_ambiance_spot_2 is None
2024-07-23 18:55:36.154 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] State of light.hue_ambiance_spot_3 is None
2024-07-23 18:55:36.155 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] State of light.hue_ambiance_spot_4 is None
2024-07-23 18:55:36.158 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] No switch found for entity_id='light.flur_hinten', skipped='['light.flur_hinten']'
2024-07-23 18:55:36.158 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (2) _service_interceptor_turn_on_handler: switch_to_eids='{}', skipped='['light.flur_hinten']'

It seems to have expanded the light group to the two deactivated entities, then skipped the turn on event for the group but because the single entities are disabled they never get turned on so AL doesn't react on anything.

brechtvhb commented 2 months ago

I see these kind of messages in the logs when turning a group of hue lights on:

2024-07-23 22:06:15.903 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Living: Ignoring 'off' → 'on' event for 'light.hue_color_spot_1_2' with context.id='01J3GK6W4Q9PCFFQ7MPKK3W2E8' because 'light.turn_on' was not called by HA and 'detect_non_ha_changes' is False 2024-07-23 22:06:15.903 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Marking 'light.hue_color_spot_1_2' as manually controlled.

ncd7 commented 2 months ago

Yes this the log pattern that I saw weeks ago when I first faced this issue, specifically I meant this part: Ignoring 'off' → 'on' event for 'light.hue_color_spot_1_2' with context.id='01J3GK6W4Q9PCFFQ7MPKK3W2E8' because 'light.turn_on' was not called by HA and 'detect_non_ha_changes' is False

That is why in the title of the issue i added the workaround of detecting non ha changes but i've found that setting to always be very unreliable with Hue (even before this issue) so I basically always disable it.

Dante12129 commented 2 months ago

Below are my logs after calling light.turn_on on 'light.dans_bedroom', with 'light.dans_bedroom' being the Hue group and the numbered lights being the individual lights within the group. I have my adaptive lighting setup for these lights on the 'light.dans_bedroom' Hue group, with none of the individual bulbs included in the configuration. I also did some digging into the Hue component's code and found this change in which the entity IDs were added to Hue group bulbs, and figured that could possibly be contributing.

2024-07-31 23:31:12.173 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (0) _service_interceptor_turn_on_handler: call.context.id='01J45ZVQ5AVX809Q9DZGK3BDCS', is_skipped_hash='False' 2024-07-31 23:31:12.173 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (1) _service_interceptor_turn_on_handler: call='<ServiceCall light.turn_on (c:01J45ZVQ5AVX809Q9DZGK3BDCS): entity_id=['light.dans_bedroom_color_lights'], params=>', service_data='{'entity_id': ['light.dans_bedroom_color_lights'], 'params': {}}' 2024-07-31 23:31:12.174 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] No switch found for entity_id='light.dans_bedroom_color_lights', skipped='['light.dans_bedroom_color_lights']' 2024-07-31 23:31:12.175 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (2) _service_interceptor_turn_on_handler: switch_to_eids='{}', skipped='['light.dans_bedroom_color_lights']' 2024-07-31 23:31:12.410 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected a 'light.dans_bedroom_3' 'state_changed' event: '{'min_color_temp_kelvin': 2000, 'max_color_temp_kelvin': 6535, 'min_mireds': 153, 'max_mireds': 500, 'effect_list': ['None', 'candle', 'fire', 'prism', 'sparkle', 'opal', 'glisten', 'sunrise', 'unknown'], 'supported_color_modes': [<ColorMode.COLOR_TEMP: 'color_temp'>, <ColorMode.XY: 'xy'>], 'effect': 'None', 'color_mode': <ColorMode.COLOR_TEMP: 'color_temp'>, 'brightness': 83, 'color_temp_kelvin': 2000, 'color_temp': 500, 'hs_color': (30.601, 94.547), 'rgb_color': (255, 136, 13), 'xy_color': (0.599, 0.382), 'mode': 'normal', 'dynamics': 'none', 'icon': 'hue:bulb-sultan', 'friendly_name': 'Dan’s Bedroom 3', 'supported_features': <LightEntityFeature.EFFECT|FLASH|TRANSITION: 44>}' with context.id='01J45ZVQCS9KN68X61XEDTAAKJ' 2024-07-31 23:31:12.410 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'off' → 'on' event for 'light.dans_bedroom_3' with context.id='01J45ZVQCS9KN68X61XEDTAAKJ' 2024-07-31 23:31:12.411 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01J45ZVQCS9KN68X61XEDTAAKJ' 2024-07-31 23:31:12.411 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] just_turned_off: delta_time='68.820095' > delay='5' 2024-07-31 23:31:12.411 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01J45ZVQCS9KN68X61XEDTAAKJ' 2024-07-31 23:31:12.412 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Bedroom: Ignoring 'off' → 'on' event for 'light.dans_bedroom_3' with context.id='01J45ZVQCS9KN68X61XEDTAAKJ' because 'light.turn_on' was not called by HA and 'detect_non_ha_changes' is False 2024-07-31 23:31:12.412 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Marking 'light.dans_bedroom_3' as manually controlled. 2024-07-31 23:31:12.418 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected a 'light.dans_bedroom_2' 'state_changed' event: '{'min_color_temp_kelvin': 2000, 'max_color_temp_kelvin': 6535, 'min_mireds': 153, 'max_mireds': 500, 'effect_list': ['None', 'candle', 'fire', 'prism', 'sparkle', 'opal', 'glisten', 'sunrise', 'unknown'], 'supported_color_modes': [<ColorMode.COLOR_TEMP: 'color_temp'>, <ColorMode.XY: 'xy'>], 'effect': 'None', 'color_mode': <ColorMode.COLOR_TEMP: 'color_temp'>, 'brightness': 83, 'color_temp_kelvin': 2000, 'color_temp': 500, 'hs_color': (30.601, 94.547), 'rgb_color': (255, 136, 13), 'xy_color': (0.599, 0.382), 'mode': 'normal', 'dynamics': 'none', 'icon': 'hue:bulb-sultan', 'friendly_name': 'Dan’s Bedroom 2', 'supported_features': <LightEntityFeature.EFFECT|FLASH|TRANSITION: 44>}' with context.id='01J45ZVQCZXF4WM1AE2CBX3PM5' 2024-07-31 23:31:12.419 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'off' → 'on' event for 'light.dans_bedroom_2' with context.id='01J45ZVQCZXF4WM1AE2CBX3PM5' 2024-07-31 23:31:12.419 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01J45ZVQCZXF4WM1AE2CBX3PM5' 2024-07-31 23:31:12.419 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] just_turned_off: delta_time='68.823957' > delay='5' 2024-07-31 23:31:12.420 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01J45ZVQCZXF4WM1AE2CBX3PM5' 2024-07-31 23:31:12.420 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Bedroom: Ignoring 'off' → 'on' event for 'light.dans_bedroom_2' with context.id='01J45ZVQCZXF4WM1AE2CBX3PM5' because 'light.turn_on' was not called by HA and 'detect_non_ha_changes' is False 2024-07-31 23:31:12.420 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Marking 'light.dans_bedroom_2' as manually controlled. 2024-07-31 23:31:12.422 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected a 'light.dans_bedroom_1' 'state_changed' event: '{'min_color_temp_kelvin': 2000, 'max_color_temp_kelvin': 6535, 'min_mireds': 153, 'max_mireds': 500, 'effect_list': ['None', 'candle', 'fire', 'prism', 'sparkle', 'opal', 'glisten', 'sunrise', 'unknown'], 'supported_color_modes': [<ColorMode.COLOR_TEMP: 'color_temp'>, <ColorMode.XY: 'xy'>], 'effect': 'None', 'color_mode': <ColorMode.COLOR_TEMP: 'color_temp'>, 'brightness': 83, 'color_temp_kelvin': 2000, 'color_temp': 500, 'hs_color': (30.601, 94.547), 'rgb_color': (255, 136, 13), 'xy_color': (0.599, 0.382), 'mode': 'normal', 'dynamics': 'none', 'icon': 'hue:bulb-sultan', 'friendly_name': 'Dan’s Bedroom 1', 'supported_features': <LightEntityFeature.EFFECT|FLASH|TRANSITION: 44>}' with context.id='01J45ZVQD69GEWGRPFDJ376EEN' 2024-07-31 23:31:12.423 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'off' → 'on' event for 'light.dans_bedroom_1' with context.id='01J45ZVQD69GEWGRPFDJ376EEN' 2024-07-31 23:31:12.423 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01J45ZVQD69GEWGRPFDJ376EEN' 2024-07-31 23:31:12.423 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] just_turned_off: delta_time='68.82189' > delay='5' 2024-07-31 23:31:12.424 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01J45ZVQD69GEWGRPFDJ376EEN' 2024-07-31 23:31:12.424 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Bedroom: Ignoring 'off' → 'on' event for 'light.dans_bedroom_1' with context.id='01J45ZVQD69GEWGRPFDJ376EEN' because 'light.turn_on' was not called by HA and 'detect_non_ha_changes' is False 2024-07-31 23:31:12.424 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Marking 'light.dans_bedroom_1' as manually controlled.

malodie commented 1 month ago

I've tested just about every scenario I can think of for this and it still sometimes just refuses to mark the light as manual.

First, I chose a single room, deleted all of my AL in the whole house, set up a brand new one, and added a single light in that room. Worked perfectly, no issues. It worked regardless of whether I triggered it from HA or the hue app. Then I removed that single light, and changed it to a group of three identical lights (hue ambience downlights). I used the room, not the individual lights (light.kitchen). Worked just fine. Even tried it a few times.

At this point, I figured maybe I just had some old config, so I set up the rest of the house. First I tried putting all lights in a single AL. Suddenly, nothing works. My living room lights, which had been fine, now suddenly never mark as manually controlled.

I then opted to separate them by room (so at least I could automate the workaround). Still, no luck.

I am running about fifty lights, all of different types, but all hue. It doesn't matter whether or not it's triggered via HA or Hue or something like my Stream Deck, it just refuses to mark them as manual.

I don't know enough about the code yet to try anything else, but if there are scenarios anyone would like me to test I am happy to provide the logs. I kept logs and screenshots of all of my above attempts, but because I cannot reliably reproduce it, I am not sure how useful it is. The only difference between the logs is the active setting of "manual" or not.

ncd7 commented 1 month ago

I've tested just about every scenario I can think of for this and it still sometimes just refuses to mark the light as manual.

First, I chose a single room, deleted all of my AL in the whole house, set up a brand new one, and added a single light in that room. Worked perfectly, no issues. It worked regardless of whether I triggered it from HA or the hue app. Then I removed that single light, and changed it to a group of three identical lights (hue ambience downlights). I used the room, not the individual lights (light.kitchen). Worked just fine. Even tried it a few times.

At this point, I figured maybe I just had some old config, so I set up the rest of the house. First I tried putting all lights in a single AL. Suddenly, nothing works. My living room lights, which had been fine, now suddenly never mark as manually controlled.

I then opted to separate them by room (so at least I could automate the workaround). Still, no luck.

I am running about fifty lights, all of different types, but all hue. It doesn't matter whether or not it's triggered via HA or Hue or something like my Stream Deck, it just refuses to mark them as manual.

I don't know enough about the code yet to try anything else, but if there are scenarios anyone would like me to test I am happy to provide the logs. I kept logs and screenshots of all of my above attempts, but because I cannot reliably reproduce it, I am not sure how useful it is. The only difference between the logs is the active setting of "manual" or not.

I think you might be describing a different issue or perhaps I'm missing something. For us the issue is the opposite. The lights are always marked as manual because the AL integration no longer detects light entities that represent hue light groups when they are turned on or off as originating from HA. So I'm a bit confused by your comment but I might be missing something.

malodie commented 1 month ago

Oh maybe I misunderstood. Yeah, I have the problem where it's refusing to mark them as manual and I cannot figure out why. Could it be related? If it is totally unrelated disregard and I'll put in an issue to take a look.

This might be more appropriate: https://github.com/basnijholt/adaptive-lighting/issues/945

thecastle20 commented 1 month ago

Attached logs from test with my hallway lights (light.hallway) which is a group of two Philips Hue bulbs using the hardware Hue based hub.

Procedure using in this log output:

  1. Turn light via dashboard app, adjust to manual setting (reduce brightness, change to soft white lighting)
  2. Turn off light with a physical switch (light.toggle via automation)
  3. Wait 30 seconds or so.
  4. Turn light back on via physical switch (light.toggle via automation)
  5. Bulb is marked manually controlled.

The service automation uses this code to turn the light on/off:

service: light.toggle data: {} target: entity_id: light.hallway

Logs.txt

thecastle20 commented 1 month ago

Looking at the light.hallway pieces specifically these appear to be the relevant parts where the light is turned on via 'light.toggle'. There is a "no switch found" which seems concerning. It seems to think the light.toggle was a non-HA event and therefore ignores the event.

Line 75: 2024-08-11 15:36:25.112 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] No switch found for entity_id='light.hallway', skipped='['light.hallway']' Line 75: 2024-08-11 15:36:25.112 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] No switch found for entity_id='light.hallway', skipped='['light.hallway']' Line 76: 2024-08-11 15:36:25.112 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (2) _service_interceptor_turn_on_handler: switch_to_eids='{}', skipped='['light.hallway']' Line 82: 2024-08-11 15:36:25.396 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] hallway_all: Ignoring 'off' ? 'on' event for 'light.hall_front' with context.id='01J4ZR4F1HJJ2SS3RV2PJAV8HK' because 'light.turn_on' was not called by HA and 'detect_non_ha_changes' is False Line 89: 2024-08-11 15:36:25.399 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] hallway_all: Ignoring 'off' ? 'on' event for 'light.hall_back' with context.id='01J4ZR4F1NT2XQYJ1X280JH5Y1' because 'light.turn_on' was not called by HA and 'detect_non_ha_changes' is False

thecastle20 commented 1 month ago

Parsing the logs for the event ID seems to show it detects only one of the bulbs rather than the group entry - which of course doesn't match the entry in adaptive lighting. This seems to confirm that this is related to groups of hue bulbs rather than individual lights.

Line 84: 2024-08-11 15:36:25.398 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected a 'light.hall_back' 'state_changed' event: '{'min_color_temp_kelvin': 2202, 'max_color_temp_kelvin': 6535, 'min_mireds': 153, 'max_mireds': 454, 'effect_list': ['None', 'candle', 'sparkle', 'glisten', 'sunrise', 'unknown'], 'supported_color_modes': [<ColorMode.COLOR_TEMP: 'color_temp'>], 'effect': 'None', 'color_mode': <ColorMode.COLOR_TEMP: 'color_temp'>, 'brightness': 130, 'color_temp_kelvin': 2202, 'color_temp': 454, 'hs_color': (29.79, 84.553), 'rgb_color': (255, 146, 39), 'xy_color': (0.579, 0.388), 'mode': 'normal', 'dynamics': 'none', 'friendly_name': 'Hall - Back', 'supported_features': <LightEntityFeature.EFFECT|FLASH|TRANSITION: 44>}' with context.id='01J4ZR4F1NT2XQYJ1X280JH5Y1' Line 85: 2024-08-11 15:36:25.398 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'off' ? 'on' event for 'light.hall_back' with context.id='01J4ZR4F1NT2XQYJ1X280JH5Y1' Line 86: 2024-08-11 15:36:25.398 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01J4ZR4F1NT2XQYJ1X280JH5Y1' Line 88: 2024-08-11 15:36:25.398 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01J4ZR4F1NT2XQYJ1X280JH5Y1' Line 89: 2024-08-11 15:36:25.399 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] hallway_all: Ignoring 'off' ? 'on' event for 'light.hall_back' with context.id='01J4ZR4F1NT2XQYJ1X280JH5Y1' because 'light.turn_on' was not called by HA and 'detect_non_ha_changes' is False

gravityrebel commented 1 month ago

I am also having issues with Hue Groups, but have not seen anything related to "manually controlled" as being a part of the issue. I have opened a separate issue to detail problems with Hue Groups that are not explicitly related to manual control. https://github.com/basnijholt/adaptive-lighting/issues/1034. Configuration works for individual lights, but is non-responsive to groups.

gravityrebel commented 1 month ago

Can anyone verify by sharing their logs that this is actually happening as stated?

@basnijholt I posted my logs in the above linked issue. Two logs, one with only groups and one with a mixed group/individual configuration.

ncd7 commented 1 month ago

I see there is a new issue https://github.com/basnijholt/adaptive-lighting/issues/1034 that might be a duplicate of this one or at least related.

ncd7 commented 1 month ago

Separately, this might also be related to https://github.com/basnijholt/adaptive-lighting/issues/1017

MizterB commented 1 month ago

I experienced the same issue on a recent Core update, and had to revert back to the June release to restore functionality.

Based on the timing and nature of this issue, it is most likely the result of this commit: https://github.com/home-assistant/core/pull/113053

This commit adds the entity_id attribute to Hue Group lights, which makes the Hue Groups functionally similar to other groups in HA. Its seems like a benign attribute change, and definitely has benefits at the HA core level.

However...it now triggers this boolean method in Adaptive Lighting, which it would not have previously: https://github.com/basnijholt/adaptive-lighting/blob/8e8c520dad81fdcf4359b1c2b6ce7665b99286a6/custom_components/adaptive_lighting/switch.py#L640

There seems to be a bunch of AL logic based on this check, which I have yet to digest. But the net of all this is: AL treats individual lights and light groups differently. As the result of an HA core change, Hue groups are being treated as a light group, rather than an individual bulb.

How to fix? I hope an AL developer can chime in.

MizterB commented 1 month ago

I believe a simple change to that method could fix this:

def _is_light_group(state: State) -> bool:
    return "entity_id" in state.attributes and not state.attributes.get("is_hue_group", False)
MizterB commented 1 month ago

I can confirm that the fix I proposed above solves the problem.

basnijholt commented 1 month ago

If a few others could confirm that this indeed solves their problem, could somebody create a PR? 😃

basnijholt commented 1 month ago

Thanks for creating the PR @MizterB! I would like to see one other person in this thread confirm this since I have no means of testing this myself.

thecastle20 commented 1 month ago

Can you publish it as a pre-release? Happy to test.

JN-Jones commented 1 month ago

Can confirm the issue has been fixed for me with the proposed change

thecastle20 commented 1 month ago

Issue still not resolved for me. The lights do adapt but there's still some manual flagging going on. Will check in detail at the weekend.

macj72x commented 1 month ago

It solved it for me, but when I updated everything started with sleep mode on. You may want to check that.

thecastle20 commented 3 weeks ago

This has fixed it; I think a full restart of Home assistant sorted it.

Also found one of my lights being marked manual was due to two hue entities (groups and single lights) from the hue hub created in HA even though it was only for a single light. Not sure when this occured but seems to be present for all light entries.

A switch automation was triggering the group light entity and the adaptive lighting entry was for the single light entity, so it was marking it manually controlled at light turn on. Changing it so adaptive lighting (and any automations) are all referencing the same entity sorted that.