basnijholt / adaptive-lighting

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

detect_non_ha_changes not working with Tradfri RGB bulb #832

Open gaborbencze opened 8 months ago

gaborbencze commented 8 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:
2023-11-05 20:50:48.954 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Living room adaptive lighting: '_update_attrs_and_maybe_adapt_lights' called with context.id='01HEGGKCBT:al:JRUX:ntrv:1J' lights: 'None', transition: '1.0', force: 'False'
2023-11-05 20:50:48.966 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Living room adaptive lighting: filtered_lights: '['light.reading_light', 'light.standing_lamp']'
2023-11-05 20:50:48.970 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01HEGDADXN:al:JRUX:ntrv:0H'
2023-11-05 20:50:48.978 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/adaptive_lighting/switch.py", line 1129, in _async_update_at_interval_action
    await self._update_attrs_and_maybe_adapt_lights(
  File "/config/custom_components/adaptive_lighting/switch.py", line 1442, in _update_attrs_and_maybe_adapt_lights
    and await self.manager.significant_change(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/adaptive_lighting/switch.py", line 2461, in significant_change
    changed = _attributes_have_changed(
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/adaptive_lighting/switch.py", line 744, in _attributes_have_changed
    if abs(current_color_temp - last_color_temp) > COLOR_TEMP_CHANGE:
           ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
  1. Your Adaptive Lighting configuration:
{
   "entry_id":"a45ce9f141f335d52a023dbef18c0a97",
   "version":1,
   "domain":"adaptive_lighting",
   "title":"Living room adaptive lighting",
   "data":{
      "name":"Living room adaptive lighting"
   },
   "options":{
      "lights":[
         "light.standing_lamp",
         "light.reading_light"
      ],
      "interval":90,
      "transition":1.0,
      "initial_transition":1.0,
      "min_brightness":1,
      "max_brightness":100,
      "min_color_temp":2000,
      "max_color_temp":5500,
      "prefer_rgb_color":false,
      "sleep_brightness":1,
      "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":"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":true,
      "autoreset_control_seconds":0,
      "only_once":false,
      "adapt_only_on_bare_turn_on":false,
      "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
   },
   "pref_disable_new_entities":false,
   "pref_disable_polling":false,
   "source":"user",
   "unique_id":"Living room adaptive lighting",
   "disabled_by":null
}
  1. Describe the bug and how to reproduce it: Enable detect_non_ha_changes with a Tradfri RGB bulb that is using the tradfri integration.

The lights are only adapted when turning on, but do not keep getting adapted. Debug logs contain the following errors every interval seconds:

2023-11-05 20:50:48.954 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Living room adaptive lighting: '_update_attrs_and_maybe_adapt_lights' called with context.id='01HEGGKCBT:al:JRUX:ntrv:1J' lights: 'None', transition: '1.0', force: 'False'
2023-11-05 20:50:48.966 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Living room adaptive lighting: filtered_lights: '['light.reading_light', 'light.standing_lamp']'
2023-11-05 20:50:48.970 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01HEGDADXN:al:JRUX:ntrv:0H'
2023-11-05 20:50:48.978 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/adaptive_lighting/switch.py", line 1129, in _async_update_at_interval_action
    await self._update_attrs_and_maybe_adapt_lights(
  File "/config/custom_components/adaptive_lighting/switch.py", line 1442, in _update_attrs_and_maybe_adapt_lights
    and await self.manager.significant_change(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/adaptive_lighting/switch.py", line 2461, in significant_change
    changed = _attributes_have_changed(
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/adaptive_lighting/switch.py", line 744, in _attributes_have_changed
    if abs(current_color_temp - last_color_temp) > COLOR_TEMP_CHANGE:
           ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

Was working fine on HA core 2023.10.5 but is no longer working in 2023.11.0 and 2023.11.1.

Looking at the attributes of these lights I see color_temp_kelvin and color_temp are both null.

min_color_temp_kelvin: 2202
max_color_temp_kelvin: 4000
min_mireds: 250
max_mireds: 454
supported_color_modes: color_temp, hs
color_mode: hs
brightness: 76
color_temp_kelvin: null
color_temp: null
hs_color: 29.883, 80
rgb_color: 255, 152, 51
xy_color: 0.566, 0.39
friendly_name: Standing lamp
supported_features: 32
  1. Steps to reproduce the behavior: See above
gaborbencze commented 8 months ago

It seems like it might be caused by this PR in HA core: https://github.com/home-assistant/core/pull/101946

kylebjordahl commented 7 months ago

@gaborbencze - thanks for finding this; my adaptive setup has been broken since that update and I was planning to sit down and dig into it today, so this was a great breadcrumb.