Calibrate light color

Hi! Didn’t find anything with search so here goes… Is there any way to calibrate lights color with home automation?

I recently got Ikea’s Trådfri setup including gateway and I did integrate it to the Home Automation. I have some color temperature adjustable bulbs and RGB bulb mixed together. I use Home Automation only for setting color temperature based on time. Setup works well no problem.

Recently I got Zigbee shield for my Raspberry Pi and I am trying to ditch Ikea’s gateway and am 99% there. I was able to pair bulbs with Home Automation no problem and eveyrthing works, except that RGB bulbs now shows huge red tint. White is reddish, yellow is reddish etc. Not sure what happens there but Ikea’s gateway must transparently compensate for this.

So solution would be manually color calibrating bulb, e.g. setting red value to 90% of requested value or something like this. But is it possible? I really did not find anything like this with search.

Thanks!

Haven’t run across anything like that. My guess is you could do this by customizing the code to your needs. Which light platform are you using with these bulbs that need color compensation? If it’s ZigBee Home Automation Light, then I believe the code that would need customization would be https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/light/zha.py. Or, I suppose it might be easier just to write a script that you call instead of the light.turn_on service that would adjust the rgb_color value before calling light.turn_on.

Thanks for the reply! Yes I was afraid that there is nothing available. I’ll try to do customization for myself for this. Home Assistant’s software architecture is a bit unfamiliar to me as is python, but looks quite straightforward after I find correct place to customize. Thanks!

Ps. It’s zha I am using indeed.

FYI, probably the best way to customize the code is to copy it into your <config>/custom_components directory. Specifically in this case, copy it to <config>/custom_components/light/zha.py. When HA tries to load the platform it will look under <config>/custom_components first. If it finds it there it will use that copy instead of the standard code. Of course, if/when you update HA you’ll need to check if there’s any changes you need to merge into your custom copy.

Thanks! That worked well. I was not able to modify zha.py as it seems to take hs values and convert them to xy and did not have energy to find out formulas how to modify those values. But I did simple hack to fluxer.py; I set rgb bulb to use rgb mode and hacked rgb mode so that red component is reduced by 15%. Other bulbs do use mired mode and that mode I left as is. As a result white all bulbs looks the same.

Interesting though, why Trådfri bulbs behave like that? Do they contain calibration information which Trådfri gateway can read and use or does gateway do just the than I hacked into flux.py? I do not have more rgb bulbs so I cannot try if there’s any differences…

https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/util/color.py has all the conversion functions you’d probably need. (It’s what the zha.py platform already uses. See the import homeassistant.util.color as color_util statement at the top.)

E.g., you could change:

        if light.ATTR_HS_COLOR in kwargs:
            self._hs_color = kwargs[light.ATTR_HS_COLOR]
            xy_color = color_util.color_hs_to_xy(*self._hs_color)
            await self._endpoint.light_color.move_to_color(
                int(xy_color[0] * 65535),
                int(xy_color[1] * 65535),
                duration,
            )

to:

        if light.ATTR_HS_COLOR in kwargs:
            self._hs_color = kwargs[light.ATTR_HS_COLOR]
            r, g, b = color_util.color_hs_to_RGB(*self._hs_color)
            xy_color = color_util.color_RGB_to_xy(r*0.85, g, b)
            await self._endpoint.light_color.move_to_color(
                int(xy_color[0] * 65535),
                int(xy_color[1] * 65535),
                duration,
            )