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

Lights turned on using device_id target are not adapted #891

Open jackwilsdon opened 9 months ago

jackwilsdon commented 9 months ago

Home Assistant Adaptive Lighting Issue Template

Bug Reports

If you need help with using or configuring Adaptive Lighting, please open a Q&A discussion thread here instead.

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:
2024-01-01 14:26:26.751 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration adaptive_lighting which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-01-02 10:11:17.111 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (0) _service_interceptor_turn_on_handler: call.context.id='01HK4TFXFN3DHT6X8GQMVRRVT5', is_skipped_hash='False'
2024-01-02 10:11:17.111 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (1) _service_interceptor_turn_on_handler: call='<ServiceCall light.turn_on (c:01HK4TFXFN3DHT6X8GQMVRRVT5): device_id=['7f0959e90d660d9d442b4e4943c68e19'], params=>', service_data='{'device_id': ['7f0959e90d660d9d442b4e4943c68e19'], 'params': {}}'
2024-01-02 10:11:17.112 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] No entity_ids or area_ids found in service_data: {'device_id': ['7f0959e90d660d9d442b4e4943c68e19'], 'params': {}}
2024-01-02 10:11:17.112 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (2) _service_interceptor_turn_on_handler: switch_to_eids='{}', skipped='[]'
2024-01-02 10:11:17.113 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] No entity_ids or area_ids found in service_data: {'device_id': ['7f0959e90d660d9d442b4e4943c68e19']}
2024-01-02 10:11:17.366 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected a 'light.kitchen_ceiling_lights' 'state_changed' event: '{'min_color_temp_kelvin': 2000, 'max_color_temp_kelvin': 6535, 'min_mireds': 153, 'max_mireds': 500, 'effect_list': ['blink', 'breathe', 'okay', 'channel_change', 'candle', 'fireplace', 'colorloop', 'finish_effect', 'stop_effect', 'stop_hue_effect'], 'supported_color_modes': ['color_temp', 'xy'], 'color_mode': <ColorMode.XY: 'xy'>, 'brightness': 255, 'color_temp_kelvin': None, 'color_temp': None, 'hs_color': (0.0, 100.0), 'rgb_color': (255, 0, 0), 'xy_color': (0.701, 0.299), 'effect': None, 'icon': 'mdi:ceiling-light', 'friendly_name': 'Kitchen Ceiling Lights', 'supported_features': <LightEntityFeature.EFFECT|FLASH|TRANSITION: 44>}' with context.id='01HK4TFXFN3DHT6X8GQMVRRVT5'
2024-01-02 10:11:17.366 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'off' → 'on' event for 'light.kitchen_ceiling_lights' with context.id='01HK4TFXFN3DHT6X8GQMVRRVT5'
2024-01-02 10:11:17.366 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01HK4TFXFN3DHT6X8GQMVRRVT5'
2024-01-02 10:11:17.366 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] just_turned_off: delta_time='20.133753' > delay='5'
2024-01-02 10:11:17.367 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01HK4TFXFN3DHT6X8GQMVRRVT5'
2024-01-02 10:11:17.367 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Adaptive Lighting: Ignoring 'off' → 'on' event for 'light.kitchen_ceiling_lights' with context.id='01HK4TFXFN3DHT6X8GQMVRRVT5' because 'light.turn_on' was not called by HA and 'detect_non_ha_changes' is False
2024-01-02 10:11:17.367 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Marking 'light.kitchen_ceiling_lights' as manually controlled.
  1. Your Adaptive Lighting configuration:

From .storage/core.config_entries:

{
    "lights": [
        "light.kitchen_ceiling_lights"
    ],
    "interval": 90,
    "transition": 45.0,
    "initial_transition": 1.0,
    "min_brightness": 1,
    "max_brightness": 100,
    "min_color_temp": 2000,
    "max_color_temp": 4000,
    "prefer_rgb_color": false,
    "sleep_brightness": 1,
    "sleep_rgb_or_color_temp": "rgb_color",
    "sleep_color_temp": 1000,
    "sleep_rgb_color": [
        255,
        56,
        0
    ],
    "sleep_transition": 1.0,
    "transition_until_sleep": false,
    "sunrise_time": "None",
    "min_sunrise_time": "None",
    "max_sunrise_time": "None",
    "sunrise_offset": 0,
    "sunset_time": "None",
    "min_sunset_time": "None",
    "max_sunset_time": "None",
    "sunset_offset": 0,
    "brightness_mode": "default",
    "brightness_mode_time_dark": 900,
    "brightness_mode_time_light": 3600,
    "take_over_control": true,
    "detect_non_ha_changes": false,
    "autoreset_control_seconds": 0,
    "only_once": false,
    "adapt_only_on_bare_turn_on": false,
    "separate_turn_on_commands": true,
    "send_split_delay": 0,
    "adapt_delay": 0.0,
    "skip_redundant_commands": false,
    "intercept": true,
    "multi_light_intercept": true,
    "include_config_in_attributes": true
}
  1. (If using Zigbee2MQTT), provide your configuration files (remove all personal information before posting):
    • devices.yaml
    • groups.yaml
    • configuration.yaml ⚠️; Warning REMOVE ALL of the PERSONAL INFORMATION BELOW before posting ⚠️;
      • mqtt: server:
      • mqtt: user:
      • mqtt: password:
      • advanced: pan_id:
      • advanced: network_key:
      • anything in log_syslog if you use this
    • Brand and model number of problematic light(s)

4.  Describe the bug and how to reproduce it:

Turn on a light using `target.device_id` instead of `target.entity_id`, note that the color and brightness are not adapted:

service: light.turn_on target: device_id:

Turning on the light with entity_id correctly adapts the color and brightness:

service: light.turn_on
target:
  entity_id: light.kitchen_ceiling_lights

These lines line from the log seems to indicate that Adaptive Lighting thinks something other than HA turned on the light (seemingly because it isn't checking for device_id?):

2024-01-02 10:11:17.112 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] No entity_ids or area_ids found in service_data: {'device_id': ['7f0959e90d660d9d442b4e4943c68e19'], 'params': {}}
2024-01-02 10:11:17.113 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] No entity_ids or area_ids found in service_data: {'device_id': ['7f0959e90d660d9d442b4e4943c68e19']}
2024-01-02 10:11:17.367 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Adaptive Lighting: Ignoring 'off' → 'on' event for 'light.kitchen_ceiling_lights' with context.id='01HK4TFXFN3DHT6X8GQMVRRVT5' because 'light.turn_on' was not called by HA and 'detect_non_ha_changes' is False
jackwilsdon commented 9 months ago

It seems like this is due to _get_entity_list only checking entity_id and area_id: https://github.com/basnijholt/adaptive-lighting/blob/3118e6f308b13927049c764f8131bf7d62ea56f6/custom_components/adaptive_lighting/switch.py#L2197-L2221

I guess this could be extended to return all light entities for all devices in the device_id list from the device registry? I wouldn't mind opening a PR for this.