RGBW Lightbulb, Controllable by Openhab via MQTT

I have been playing with a ZMLink (AILight) rgbw lightbulb. These normally are controlled by their own web based apps, but use ESP8266 chips on board.

I recorded this Youtube video that shows how to update the firmware and control the bulbs via MQTT. I have successfully integrated my bulb to Openhab2 this way,

https://www.youtube.com/watch?v=6GRqNXuH4HI

The bulb is controlled by a color picker with a crude rule that converts the RGB values to RGBW and publishes them to MQTT. I would be interested in help with the conversion.

rule sendRGBBulb
	when
		Item rgb_color_wheel received command
	then
		if (receivedCommand instanceof HSBType) {
			val HSBType hsb = receivedCommand as HSBType
			val red = hsb.red.intValue * 5 / 2
			val green = hsb.green.intValue  * 5 / 2
			val blue = hsb.blue.intValue  * 5 / 2
			val white = Math.min(red, Math.min(green,blue))
			val String mqtt = String::format("MY9291,%1$d,%2$d,%3$d,%4$d",red - white, green - white, blue - white, white)
			publish("broker", "/smartbulb/cmd", mqtt)
		} 
end
3 Likes