Introduction
I wanted to find a way to define favorite “colors” that I could later apply to any light. Then I discovered the Light component supports a light_profiles.csv. The documentation is sparse, but I manged to figure it out.
Researching
Each row (disregarding the first row — header) has to contain exactly 4 or 5 cells (separated by comma): profile name (string), color_x (float), color_y (float), brightness (byte), transition (positive integer, optional).
Cool, now I want to setup some light profiles myself. So I thought of doing these steps:
- Set the light to the desired color and intensity.
- Inspect the light attributes to find the xy values.
- Write them down into
config/light_profiles.csv
.
However, I found some issues:
- Recent Home Assistant versions don’t display the raw values anymore at the bottom of the light entity dialog.
- Okay, that’s an easy workaround. Just go to Developer Tools and view the entire entity state in there.
- But my light has
color_temp
, but notxy_color
.- What If I try to access it directly from a template? Hmm…
state_attr('…', 'xy_color')
returnsNone
, so it doesn’t work. - Surely there should be some way to convert colors in Home Assistant template. Well, doesn’t seem like so.
- But Home Assistant internally has color-conversion functions! Can we access those from the template? Well, doesn’t seem possible.
- If it were possible, can I directly convert mired to xy? Well, first I have to convert mired to temperature in kelvin, and then convert that to either hs or rgb, and then convert that to xy. That’s a lot of steps.
- What If I try to access it directly from a template? Hmm…
- Okay, I spent enough time searching for it, and I’m stuck.
TL;DR / Questions
How can I easily convert from color_temp
(in mired) to xy? (With the objective of adding to light_profiles.csv
.)
If the color profiles are defined in xy, would they work on lights that have color_temp
only? (Doesn’t seem to work.)
Is there any (better) way to save a set of favorite colors/intensities so I can apply them to different lights? (Scenes are interesting, but they record the precise state of a light, and the state is tied to that specific light. If light profiles sounds like the solution, but doesn’t seem to work well nor is easy-to-setup.)