RESTful sensor returns hex color, convert to something else

I have a RESTful sensor that I’ve been working on and finally got it to return values. Yay!

Now I’m trying to make use of those values. The one of the sensor states is a color in hex format (#RRGGBB). I’d like to convert that into something else, possibly RGB and/or a CSS3 named color.

Is that possible to do? Is is somehow something I can do through a template?

I current have:

value_template: '{{ states.sensor.mylight_sensors.attributes["color"] }}'

Taken from one of my other projects:
This is python, but it gets you there.

#Convert 24Bit color to RGB turple
def ColorConv(ColorT):
	R = int((ColorT/256/256)%256)
	G = int((ColorT/256)%256)
	B = int((ColorT)%256)
	RGB = '(' + repr(R) + ',' + repr(G) + ',' + repr(B) + ')'
	if Debug is True:
		print(ColorT),
		print(RGB),
	return RGB
1 Like