Sending value to Color picker

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:

items:

Dimmer  home_voorhuis_woonkamer_wwledstrip1 "Kast (WK)[%d %%]" <slider>	(Dimmers_VH_Woonkamer)	{
	mqtt=">[mosquitto:home/esp8266/sb/node1/mosfet1:command:*:default],
	<[mosquitto:home/esp8266/nb/node1/mosfet1:state:default]"}

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.

thx for your help Rico!

based on your input I did the following

command R - G - B given in Openhab APP

rule:

rule "Set Living Color 2 value"
 when
 Item fLivCol2 changed
 then
   hsbValue = fLivCol2.state as HSBType
   logInfo( "fLivCol2", fLivCol2.toString )
   logInfo( "hsbValue", hsbValue.toString )
   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_RGB", RGBvalues )
end

result in openhab.log:

2017-01-11 20:40:42.528 [INFO ] [.openhab.model.script.fLivCol2] - fLivCol2 (Type=ColorItem, State=344.162427,98.252379,99.830798)
2017-01-11 20:40:42.530 [INFO ] [.openhab.model.script.hsbValue] - 344.162427,98.252379,99.830798
2017-01-11 20:40:42.543 [INFO ] [.openhab.model.script.fLivCol2_RGB] - 100;1;27
2017-01-11 20:40:44.923 [INFO ] [.openhab.model.script.fLivCol2] - fLivCol2 (Type=ColorItem, State=233.604052,98.766384,99.830798)
2017-01-11 20:40:44.925 [INFO ] [.openhab.model.script.hsbValue] - 233.604052,98.766384,99.830798
2017-01-11 20:40:44.943 [INFO ] [.openhab.model.script.fLivCol2_RGB] - 1;11;100
2017-01-11 20:40:45.993 [INFO ] [.openhab.model.script.fLivCol2] - fLivCol2 (Type=ColorItem, State=120.609137,99.344641,99.830798)
2017-01-11 20:40:45.995 [INFO ] [.openhab.model.script.hsbValue] - 120.609137,99.344641,99.830798
2017-01-11 20:40:46.004 [INFO ] [.openhab.model.script.fLivCol2_RGB] - 0;100;1

as I can see the input from the Color element gets translated into RGB values. Now I have to do some thinking how to do it the other way around…

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)
1 Like

Scott, thx I will look into that. Currently fighting with Java errors and crashes so if that is resolved I will make a new start.