I am using the color picking item to command a modded Philips Living Color mini via MQTT.
items:
Color fLivCol2 "Living Color" <slider> (Dimmers_AH_Slaapkamer)
String LivCol2_RGB (LivCol2) {mqtt=">[mosquitto:home/esp8266/sb/node5/rgb:command:*:default]"}
rules:
rule "Set Living Color 2 value"
when
Item fLivCol2 changed
then
hsbValue = fLivCol2.state as HSBType
redValue = hsbValue.red.intValue
greenValue = hsbValue.green.intValue
blueValue = hsbValue.blue.intValue
RGBvalues= redValue.toString + ";" + greenValue.toString + ";" + blueValue.toString
sendCommand( LivCol2_RGB, RGBvalues )
logInfo( "fLivCol2", RGBvalues )
end
Within the Living Color a ESP8266 decodes the incoming MQTT into RGB settings. Everything works like I want to, but…
If I change the color some other way then with the color picker, the changes get not updated to the picker, which is logical at this stage. I am trying to get the return path working as well like I did with a number of only white led lights:
here the second part of the mqtt clause updates the slider in the UI. Problem is that my node reports back the RGB values, but how do I get these into the color picker HSB values?
I don’t do much with HSBType but what I would do is write a quick rule, create an HSBType and then log the toString to see the format. In all likelihood the toString will match the expected format for the RGB values to be presented when updating a Color Item.
You can test that the HSBType can accept Strings in that format by doing a postUpdate to your Color Item and see if that works.
Armed with the correct format for a String to populate a Color Item, you need to modify wither your sending code or your transform or write a Rule to parse the incoming RGB values and create a properly formatted initialization String.
I just took a peek at the source code for HSBType.java, where I found the following public static method:
/**
* Create HSB from RGB
*
* @param r red 0-255
* @param g green 0-255
* @param b blue 0-255
*/
public static HSBType fromRGB(int r, int g, int b)
You should be able to use that method in your rules to convert from a set of RGB values (and you don’t have to add any includes to your rules file to get it.)
val HSBType hsbValue = fromRGB(redValue, greenValue, blueValue)