In the upgrade to OH2 guide (http://docs.openhab.org/tutorials/migration#transformations) it is mentioned that there were some changes for HSBType and Color objects.
According to this description I need to create a Color object first, however this results in an error:
17:08:28.667 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Set Kueche RGB value': An error occured during the script execution: The name 'Color' cannot be resolved to an item or type.
So, how do I convert the state of a ColorPicker to RGB values with OH2?
My current version of the rules (including some commented-out variants I tried ):
rule "Set Kueche RGB value"
when
Item kueche_led changed
then
logInfo("RGB.kueche_led", "kueche_led changed: "+ kueche_led)
//var HSBType hsb = HSBType::fromRGB(kueche_led.red, kueche_led.green, kueche_led.blue)
var hsbValue = kueche_led.state as HSBType
logInfo("RGB.kueche_led", "HSB: "+ hsbValue)
// var Color color = Color::getHSBColor(hsb.hue.floatValue / 360, hsb.saturation.floatValue / 100, hsb.brightness.floatValue / 100)
var Color color = Color::getHSBColor(hsbValue.hue.floatValue / 360, hsbValue.saturation.floatValue / 100, hsbValue.brightness.floatValue / 100)
// logInfo("RGB.kueche_led", "Color: "+ color)
redValue = hsbValue.red.intValue
greenValue = hsbValue.green.intValue
blueValue = hsbValue.blue.intValue
// redValue = color.red.intValue
// greenValue = color.green.intValue
// blueValue = color.blue.intValue
postUpdate(kueche_led_R, redValue)
postUpdate(kueche_led_G, greenValue)
postUpdate(kueche_led_B, blueValue)
RGBvalues= "Values" + redValue.toString + ";" + greenValue.toString + ";" + blueValue.toString
logInfo( "kueche_led", RGBvalues )
end
I’m facing exactly the same issue here. Have you already found a solution?
I have an Enertex KNX Led device. I have 3 items in OpenHAB as dimmers for red, green and blue. The Group Address for switching on/off within the dimmer items of OpenHAB does not work, so I had to add a separate Switch to get the LED stripe on. If the lights are switched on, I am at least able to control the Color of the LEDs via changing the three dimmers items in OpenHab. But the Color Item does not work at all.
However, the Color itme is not working. I fully followed the sample rules which you quoted as well and I saw that their might be an issue due to a Change from OpenHAB 1 to Openhab 2.
Is there anybody out there who knows how to change the rule in order to align it to OpenHAB2?
import org.openhab.core.library.types.*
var HSBType hsbValue
var String redValue
var String greenValue
var String blueValue
rule "Set RGB value"
when
Item KNX_RGB_LED changed
then
hsbValue = RGB.state as HSBType
redValue = hsbValue.red.intValue.toString
greenValue = hsbValue.green.intValue.toString
blueValue = hsbValue.blue.intValue.toString
sendCommand( LedR, redValue )
sendCommand( LedG, greenValue )
sendCommand( LedB, blueValue )
end
import org.openhab.core.library.types.*
var HSBType hsbValue
var int redValue
var int greenValue
var int blueValue
var String RGBvalues
rule "Set RGB 1 value"
when
Item fWIFI_RGB_1 changed
then
hsbValue = fWIFI_RGB_1.state as HSBType
redValue = hsbValue.red.intValue
greenValue = hsbValue.green.intValue
blueValue = hsbValue.blue.intValue
RGBvalues= redValue.toString + ";" + greenValue.toString + ";" + blueValue.toString
sendCommand( WIFI_RGB_1_RGB, RGBvalues )
logInfo( "fWIFI_RGB_1", RGBvalues )
end
First of all, kudos to the OpenHAB team. I think is a really powerfull platform which allows people with very basic programming knowledge to do our own domotic systems and play around with it. Thank you.
Regarding this issue, I am fighting with it since three weeks ago and I have tried with different options, but at the end of the day I get the same error as Sebastian_OpenHAB. I am frustrated
This morning I have tried, with a clean installation, all the rules that are posted here, but with the same result.
I am using a Raspberry pi 2 with Raspbian Jessie v.8 and OpenHAB2.
Any idea about this problem? @Sebastian_OpenHAB Did you manage to solve it?
Thank you very much.
Best Regards.
I have a similar Setup. I simply did a update and upgrade of Openhab. Afterwards all issues were gone and the version as Euphi posted worked out of the box. It took me also three weeks… I suggest to update & upgrade. This solved an additional issue for me with my Sonos rules as well.
I understand that a lot of time has passed since the publication of your message.
But maybe you can help me, could you show what should be the items, sitemap, rules for managing RGB by MQTT?
Thanks David. I used your code to control RGBLeds and WS2812 Leds and it works great
MDAR
(Stuart Hanlon, UK importer of Velbus hardware)
11
Hi Sebastian
I’m new to OpenHab2, thanks to CedricB’s Velbus binding.
I’m struggling to work out where all these rules are placed and what to do with them, which is a whole new topic
Can I ask if it’s possible to explain how the OpenHab2 colorpicker HSB value could be turned into 3 seperate 0~100 values to send to 3 different Velbus dimmers? (A separate dimmer channel for each RGB element)
I assume some kind of maths like “roundup (red value / 255)*100” would do the trick.
Likewise, converting the HSB value into a single Hex RGB (with leading Zeros where required) would be fabulous, but I guess that’s for a new topic too.
Many thanks
Stuart
MDAR Ltd
UK importer of Velbus hardware
MDAR
(Stuart Hanlon, UK importer of Velbus hardware)
12
It’s okay.
@cedricboon very kindly provided me with a rule that has done the trick
rule "Middle bedroom colour" // The unique name for the rule
when
Item MidColour changed // "MidColour" is the manually created Color item to capture ColourPicker values from HabPanel
then
var HSBType hsbValue = MidColour.state as HSBType
var int redValue = hsbValue.red.intValue
var int greenValue = hsbValue.green.intValue
var int blueValue = hsbValue.blue.intValue
Mid_Red.sendCommand(redValue) // Mid_Red is my Velbus dimmer channel item for the RED component
Mid_Green.sendCommand(greenValue) // Mid_Green is my Velbus dimmer channel item for the Green component
Mid_Blue.sendCommand(blueValue) // Mid_Blue is my Velbus dimmer channel item for the Blue component
end