Bug in documentation for capability "ColorControl" indicating a HSL system, but is HSV color system

In the documentation for the capability "Color Control" it is stated that the function receives a colormap with the members hue, saturation, and level, indicating that this is a HSL color system. :

setColor(colormap)
`colormap` required (COLOR_MAP) - Color map settings [hue*:(0 to 100), saturation*:(0 to 100), level:(0 to 100)]

However, what the setColor(colormap) function receives when trying to manipulate the color either through a dashboard tile, or directly in the device page is a color corresponding with the HSV, i.e. hue, saturation and value color system. Converting between HSL and HSV requires more than just interchanging L and V.

I strongly recommend that the developer documentation is updated to reflect this. And it would be nice with some built in features for converting between the two color formats, as RGB bulbs seems to use both of them.

Here is some code that I wrote to do this if anyone is interested:

def hslToHsv(hue, saturation, level)
{
	level = (level/100) * 2

	saturation = (saturation/100) * ((level <= 1) ? level : 2 - level)

	def value = (level + saturation) / 2

	def sat = (2 * saturation) / (level + saturation)

	def retMap = ["hue": hue, "saturation": (sat*100).intValue(), "value": (value*100).intValue()]

	return retMap
}

def hsvToHsl(hue, saturation, value)
{
	def level = (2 - (saturation/100)) * (value/100)

	def sat = (saturation/100) * (value/100)

	sat = sat / ((level <= 1) ? level : 2 - level)

	level = level / 2

	def retMap = ["hue": hue, "saturation": (sat*100).intValue(), "level": (level*100).intValue()]

	return retMap
}
1 Like

The documentation is correct in that level is what this key must be called. However, it represents the "B" or "V" in HSB/HSV, not the "L" in HSL, and so I understand why this may be confusing if you are not aware that the hub's native color model is not HSL (as this name might imply). The capability docs have been modified to clarify this point, since I'm not sure if/where else it is noted.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.