What formula does HE use for HSL to RGB?

What formula does HE use to convert HSL values to RGB? I have an hsl of (55,94,100) and hubitat says that is RGB (15,83,255). Every single online converter and formula I've found says it is (255,255,255) so what formula is HE using?

image

The problem seems to be because of the scale HE uses. Hue is normally expressed in degrees (0-360) but HE measures it 0-100, so what's the conversion you guys use? I can't imagine it's just a linear conversion? On top of this I believe the minute L = 100 it's white... but in HE L is 100% and it seems it doesn't apply somehow?

I think it is what you imagined. I believe that they use a percentage for all 3 values. For example, in order to program my LEDs to red, the HSL is (0, 100, 50) and for white it is (0, 0, `100)

But the level my device currently says is 100%. Always. Because that’s really the dimmer value. HSL the L is “lightness” not “dimmer level.” From what I can tell I can read the H and the S but the L is hidden?

What I’m trying to do is determine the current rgb color of the bulb. Do I have to do it from the temperature?

How are you converting to HSL? Hubitat has an hsvToRGB() method (for HSV), but I'm not aware of anything built in for HSL. HSV and HSB are the same, but HSL is different, so if you are getting unexpected results, that is likely where this is coming from.

You are correct about the other piece: Hubitat's default hue model scales values from 0-100 as opposed to 0-360 (some drivers offer a "high-res hue" option that is 0-360), and as far as I've seen, that is indeed a linear conversion (just multipled or divded by 3.6).

If the question is indeed about Hubitat's built-in HSV conversion, what I've seen with that matches what I've found with online converters. One example--though I didn't run this one through Hubitat to check (55 * 3.6 = 192.5 ~= 193, so that's what I'm using here):

Note that I am not a color model expert, but the above is some of what I learned when trying to convert from CIE "xy" color to Hubitat's HSV model. This is, apparently, difficult to do accurately and is something I'm still trying to figure out (I can get it to reliably reproduce conversions I've found online--and to match what Home Assistant reports for the same devices, which apparently no one is complaining about--but many are still poor approximations for the actual colors produced by the bulbs I'm writing the driver for, so not really useful in the real world). Hopefully some of it is helpful to you, too. :slight_smile:

1 Like

My finding was that Hubitat uses HSV even though it appears to be labeled HSL in the attributes (which creates confusion with the SwitchLevel dimmer related attribute for level). And that hue is expressed in the range of 0..100 instead of 0..360, presumably for legacy ST consistency.

With those things taken into consideration, I used the conversion formulas from the wikipedia entry for HSV and HSL and then later confirmed that the Hubitat conversion libraries give the same results when performing conversions.

More chatter here from a previous discussion: Shelly RGBW2 doesn't respond to Hue commands

2 Likes

If you want to use rgb values to create whites.. Check out my community rgbgenie code.. I used rgb led strips to give full color temperature white control with no white element..

In this video.. I have a RGB only strip

It's kind of tedious, but I just convert between HSV, HSL, and RGB, maybe multiple times and depending on what info is available at a given time.

For example, Shelly bulbs report their color in terms of RGB and expect updates in RGB. Hubitat uses HSV. Other inputs may give HSL.

So, for example if I need to handle a setHue command, I may need to query RGB from the device or use the cached RGB attribute and parse values out. Then convert it to HSV to get the current saturation and V values, then setColor with those values plus the new hue, which ultimately converts the new values back to RGB before setting them on the bulb.

If anything, it gave a good excuse to experiment with unit testing on Hubitat. :wink:

Thank you! I didn't notice HE uses HSV. The reason I was saying HSL is because that's what the UI kind of implies:
image

All I'm trying to do is take the current color of a bulb and display it as an RGB color in a custom dashboard I'm building (I'm at the point where, unfortunately, I've given up on the built-in dashboards and decided this was as good an opportunity as any to learn React).

Thanks all, once I realized it was HSV not HSL, all good (colorsys is an awesome JS library for converting various color formats fyi).

I'm slowly getting this new dashboard idea to come together:

2 Likes