core: light_profiles.csv stopped working

The problem

I have been using a light_profiles.csv file for a long time to set default turn on values for my zigbee lights.

Since a recent update, they no longer apply when turning lights on.

What version of Home Assistant Core has the issue?

core-2024.1.1

What was the last working version of Home Assistant Core?

core-2023.12.1

What type of installation are you running?

Home Assistant Container

Integration causing the issue

light

Link to integration documentation on our website

https://www.home-assistant.io/integrations/light/

Diagnostics information

There is no logging in the home-assistant.log file relating to light_profiles.csv or any events relating to light entities which are in the csv file for information.

Example YAML snippet

id,x,y,brightness,transition
light.lounge_floor_lightbulb_osram.default,0.526,0.387,128,3
light.hall_lightbulb_osram.default,0.526,0.387,156,3
light.chillout_floor_lightbulb_ikea.default,0.463,0.376,152,3
light.bedroom_floor_lightbulb_ikea.default,0.421,0.364,200,3

Anything in the logs that might be useful for us?

No response

Additional information

No response

About this issue

  • Original URL
  • State: open
  • Created 6 months ago
  • Reactions: 2
  • Comments: 24 (7 by maintainers)

Most upvoted comments

Hi @nmaggioni adding the relax and energize presets to light_profiles.csv and using them in a service call to a group of lights works for me in 2024.1.2 too.

I have tried downgrading to 2023.12.0 as well as 2023.12.4 and found that everything works as expected in these versions. As soon as I use any version >=2024.1.0 it breaks as described in this issue.

I then proceeded to analyze the git diff between 2023.12.4 and 2024.1.0. I have found that when I run homeassistant 2024.1.0 or 2024.1.2, remove all the changes made to homeassistant/components/light/__init__.py in #86026 and restart homeassistant, the light temperature works as expected.

Here is the patch resulting from this testing. I couldn’t upload it as a file so I’m adding it as a collapsable section.

Unfortunately I’m not familiar enough with the homeassistant codebase to draw meaningful conclusions from this just yet but hope it’ll help understanding the underlying issue. 😃

Since color_util.color_hs_to_xy was not modified in 2024.1.x and color_util.color_xy_to_temperature was newly added I assume there is an issue with it or with the logic in which it’s invoked.

Click to expand patch
diff --git a/usr/src/homeassistant/homeassistant/components/light/__init__.py.bak b/usr/src/homeassistant/homeassistant/components/light/__init__.py
index ebd3696..5ceab52 100644
--- a/usr/src/homeassistant/homeassistant/components/light/__init__.py.bak
+++ b/usr/src/homeassistant/homeassistant/components/light/__init__.py
@@ -505,14 +505,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:  # noqa:
                 )
             elif ColorMode.XY in supported_color_modes:
                 params[ATTR_XY_COLOR] = color_util.color_hs_to_xy(*hs_color)
-            elif ColorMode.COLOR_TEMP in supported_color_modes:
-                xy_color = color_util.color_hs_to_xy(*hs_color)
-                params[ATTR_COLOR_TEMP_KELVIN] = color_util.color_xy_to_temperature(
-                    *xy_color
-                )
-                params[ATTR_COLOR_TEMP] = color_util.color_temperature_kelvin_to_mired(
-                    params[ATTR_COLOR_TEMP_KELVIN]
-                )
         elif ATTR_RGB_COLOR in params and ColorMode.RGB not in supported_color_modes:
             assert (rgb_color := params.pop(ATTR_RGB_COLOR)) is not None
             if ColorMode.RGBW in supported_color_modes:
@@ -528,14 +520,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:  # noqa:
                 params[ATTR_HS_COLOR] = color_util.color_RGB_to_hs(*rgb_color)
             elif ColorMode.XY in supported_color_modes:
                 params[ATTR_XY_COLOR] = color_util.color_RGB_to_xy(*rgb_color)
-            elif ColorMode.COLOR_TEMP in supported_color_modes:
-                xy_color = color_util.color_RGB_to_xy(*rgb_color)
-                params[ATTR_COLOR_TEMP_KELVIN] = color_util.color_xy_to_temperature(
-                    *xy_color
-                )
-                params[ATTR_COLOR_TEMP] = color_util.color_temperature_kelvin_to_mired(
-                    params[ATTR_COLOR_TEMP_KELVIN]
-                )
         elif ATTR_XY_COLOR in params and ColorMode.XY not in supported_color_modes:
             xy_color = params.pop(ATTR_XY_COLOR)
             if ColorMode.HS in supported_color_modes:
@@ -550,13 +534,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:  # noqa:
                 params[ATTR_RGBWW_COLOR] = color_util.color_rgb_to_rgbww(
                     *rgb_color, light.min_color_temp_kelvin, light.max_color_temp_kelvin
                 )
-            elif ColorMode.COLOR_TEMP in supported_color_modes:
-                params[ATTR_COLOR_TEMP_KELVIN] = color_util.color_xy_to_temperature(
-                    *xy_color
-                )
-                params[ATTR_COLOR_TEMP] = color_util.color_temperature_kelvin_to_mired(
-                    params[ATTR_COLOR_TEMP_KELVIN]
-                )
         elif ATTR_RGBW_COLOR in params and ColorMode.RGBW not in supported_color_modes:
             rgbw_color = params.pop(ATTR_RGBW_COLOR)
             rgb_color = color_util.color_rgbw_to_rgb(*rgbw_color)
@@ -570,14 +547,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:  # noqa:
                 params[ATTR_HS_COLOR] = color_util.color_RGB_to_hs(*rgb_color)
             elif ColorMode.XY in supported_color_modes:
                 params[ATTR_XY_COLOR] = color_util.color_RGB_to_xy(*rgb_color)
-            elif ColorMode.COLOR_TEMP in supported_color_modes:
-                xy_color = color_util.color_RGB_to_xy(*rgb_color)
-                params[ATTR_COLOR_TEMP_KELVIN] = color_util.color_xy_to_temperature(
-                    *xy_color
-                )
-                params[ATTR_COLOR_TEMP] = color_util.color_temperature_kelvin_to_mired(
-                    params[ATTR_COLOR_TEMP_KELVIN]
-                )
         elif (
             ATTR_RGBWW_COLOR in params and ColorMode.RGBWW not in supported_color_modes
         ):
@@ -594,14 +563,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:  # noqa:
                 params[ATTR_HS_COLOR] = color_util.color_RGB_to_hs(*rgb_color)
             elif ColorMode.XY in supported_color_modes:
                 params[ATTR_XY_COLOR] = color_util.color_RGB_to_xy(*rgb_color)
-            elif ColorMode.COLOR_TEMP in supported_color_modes:
-                xy_color = color_util.color_RGB_to_xy(*rgb_color)
-                params[ATTR_COLOR_TEMP_KELVIN] = color_util.color_xy_to_temperature(
-                    *xy_color
-                )
-                params[ATTR_COLOR_TEMP] = color_util.color_temperature_kelvin_to_mired(
-                    params[ATTR_COLOR_TEMP_KELVIN]
-                )
 
         # If white is set to True, set it to the light's brightness
         # Add a warning in Home Assistant Core 2023.5 if the brightness is set to an

@RandomUser99 Glad to hear that, conversions and transitions are working as expected then. Unless somebody chimes in with other results, I’d say that the issue only concerns the default profiles and its cause should be investigated elsewhere along the turn-on process.

I could try to dig into this over the course of the next week(s), but I haven’t delved in that part of the code before so it’ll take a bit - if nobody else gets there in the meantime 😉

Thanks for finding that PR. I believe my cold/warm lights did in fact respond to changing xy in the profile, but I am not sure. It was probably undefined behavior anyway 😃 I would have expected to be able to set the color temperature of a bulb as desired, and then look up the xy-values in the bulb’s state attributes. However, all values I came up with produced all-red light.

Thanks to @nmaggioni for providing some well-defined behavior here. Maybe you can help with the remaining question: Given a desired color temperature in Kelvin, what xy-values should I set, i.e. what is the inverse of the color_xy_to_temperature conversion?

EDIT: an addition to the light_profiles.csv documentation would be even better (I am happy to contribute if I find out how).

EDIT2: Ah, I guess there would be multiple xy solutions for a given CT… Would all of them work equally? In any case, I think it would be helpful to have some sort of clue about how to set these values to achieve some desired effect. In the meantime I will play around with this converter to find some suitable values 😃

I don’t see any how of my changes that would affect light profiles.

There is color temp related change recently #86026

After some more testing it looks like the light_profiles.csv file is being read and processed as the brightness and transition are being applied (proven by changing the values), but the xy_color is not being applied.