I think only HSL is supported. Its strange, but CT to RGB is a decently hard problem (I could probably do it), but then you have to go RGB to HSL. I have not seen a CT to HSL implementation. Of course, the API can so CT directly which is what started the whole thing…
I have some conversions in an RGBW light strip device type. Don;t mind the mess it’s in as it is pre-release. Maybe something in there you can use.
Thanks Twack
I’m not sure if you knew this – or maybe I’m wrong. But I think the Hue implementation on ST is incorrectly labeled HSL when its really HSB. I did not know there was a difference until I did a lot of research.
Do you know how to get a method implemented into the ST Hue class? I wrote the converter from CT to RGB to HSL. The ST class is either converting HSL then to HSB, or its converting it again to xy. I have to think its easier to just tweak the REST endpoints. Especially since color temperature is such an obvious use case…!
I pulled the Device Type code from the IDE to paste here for reference… I’m trying to grasp the implications, since SmartThings doesn’t seem to be doing any significant conversion based on this code… right??
def nextLevel() {
def level = device.latestValue("level") as Integer ?: 0
if (level < 100) {
level = Math.min(25 * (Math.round(level / 25) + 1), 100) as Integer
}
else {
level = 25
}
setLevel(level)
}
def setLevel(percent) {
log.debug "Executing 'setLevel'"
parent.setLevel(this, percent)
sendEvent(name: "level", value: percent)
}
def setSaturation(percent) {
log.debug "Executing 'setSaturation'"
parent.setSaturation(this, percent)
sendEvent(name: "saturation", value: percent)
}
def setHue(percent) {
log.debug "Executing 'setHue'"
parent.setHue(this, percent)
sendEvent(name: "hue", value: percent)
}
def setColor(value) {
log.debug "setColor: ${value}"
parent.setColor(this, value)
// TODO: convert hue and saturation to hex and just send a color event
if (value.hue) {
sendEvent(name: "hue", value: value.hue)
}
if (value.saturation) {
sendEvent(name: "saturation", value: value.saturation)
}
if (value.hex) {
sendEvent(name: "color", value: value.hex)
}
if (value.level) {
sendEvent(name: "level", value: value.level)
}
if (value.switch) {
sendEvent(name: "switch", value: value.switch)
}
}
def setAdjustedColor(value) {
log.debug "setAdjustedColor: ${value}"
def adjusted = value + [:]
adjusted.hue = adjustOutgoingHue(value.hue)
adjusted.level = null // needed because color picker always sends 100
setColor(adjusted)
}
def adjustOutgoingHue(percent) {
def adjusted = percent
if (percent > 31) {
if (percent < 63.0) {
adjusted = percent + (7 * (percent -30 ) / 32)
}
else if (percent < 73.0) {
adjusted = 69 + (5 * (percent - 62) / 10)
}
else {
adjusted = percent + (2 * (100 - percent) / 28)
}
}
log.info "percent: $percent, adjusted: $adjusted"
adjusted
}
Biggest thing I see with the entire implementation is the following.
St is insisting the ST values are integers, and then they are thunked into the device as a 0 100% space for the controls.
And the color wheel isn’t capable of rendering the complete color set that the hues are.
Yeah a couple things…
-
Philips claims the REST call is done in HSB/HSV space – which is different than HSL. However, it seems that we’ve understand it to be HSL due to the way it was named in the tools.
-
It looks like setColor might support a Hex value. I didn’t know this but its good that it does.
-
The color adjustment might effectively be doing some conversion. I don’t know what that code is doing but I suspect the round trip would be way off.
-
I didn’t give much thought to editing the Hue (Connect) SmartApp before. I’ll probably have to do that and also fix the Bulb device. Here is the code inside the SmartApp if anyone is interested:
def hex = colorUtil.hslToHex(23, 56)
sendEvent(d.deviceNetworkId, [name: “color”, value: hex])
Hi all,
I have been working on Hue, mostly fixing discovery problems and other issues. I can bring some light to this thread. While not ideal this is how the integrations are working now.
setColor(hue: 100, saturation: 100, level: 100, switch: “on”, color: “#ffffff”)
level: dimming percentage.
saturation and hue: considering that this was originally coming from a slider the values are 0…99. The final value is the result of this formula:
def hue = Math.min(Math.round(color.hue * 65535 / 100), 65535)
def sat = Math.min(Math.round(color.saturation * 255 / 100), 255)
switch: “on” or “off”.
color: hex value for the color. This value is being stored in an attribute but, right now, it doesn’t affect the setColor function.
Hope this helps!
Next week I push for standardization of how we control color bulbs and I definitely for a way of making this more intuitive both for users and developers.
Hey Juan,
I noticed the changes on the device type, including the adjustedcolor fixes. Thank you very much
I’ll let you know how my testing goes
I spent a bunch of time on this and iterated a few apps. I think it is pretty good. The colors seem pretty accurate on round trip but I did not test with a light meter – its a vast improvement from before. Thank you!