How can I compare a color item with a value

I would like to make sure a specific color is never used for our hue lights. In the example below I have chosen green.

I would like to know how to compare a color state to a color
(TafelColorSim and receivedCommand are of item type Color)

    logInfo("logLights","TafelColorSim rule triggered")
    logInfo("logLights","value: {}", receivedCommand)
    if (receivedCommand == '120,100,100') {
            logInfo("logLights","TafelColorSim is GREEN triggered")

The log output for this is:

2018-02-22 18:43:15.618 [INFO ] [pse.smarthome.model.script.logLights] - TafelColorSim rule triggered
2018-02-22 18:43:15.618 [INFO ] [pse.smarthome.model.script.logLights] - value: 120,100,100

I have tried: receivedCommand == ‘120,100,100’ and also receivedCommand == "120,100,100"
not sure how to compare these values… I would expect both of them to be HSBType

Hope someone can shed some light on this

There are some examples for HSBType HSBType struggles
and convert to RGB Example: Convert Color Item Values To RGB (With Explanation)

1 Like

Thank you for your reply, I still have the feeling that I do not quite understand but this:

if (receivedCommand.toString == “120,100,100” )

Did the trick :slight_smile:

Then again I am still struggling with:

logInfo("logLights","The brightness is: ", receivedCommand.getBrightness )

As that results in:

Rule 'Tafel kleuren': 'getBrightness' is not a member of 'org.eclipse.smarthome.core.library.types.HSBType'; line 168, column 46, length 31

Looking at this:
Class HSBType it does show toBrightness as a method…

Where should I find this information? Where can I find that e.g. toString and toFullString are valid methods but getBrightness and toRGB are not? I have looked at the openhab 2 documentation but might be overlooking this…

Okay I found this in the documentation:

Look at the JavaDocs for the given type. For example, the JavaDoc for HSBType shows getRed, getBlue, and getGreen methods. Thse methods can be called in Rules-DSL without the “get” part in name as in (MyColorItem.state as HSBType).red). They retrieve the state of MyColorItem and then casts it as HSBType to be able to use the methods associated with the HSBType.

So I added this line, to check and this works:

    logInfo("logLights", "#####Brightness: {} #####", (TafelColorSim.state as HSBType).brightness)

So that is the answer too:

I hate it when I answer my own questions: it means I have not been looking long enough :slight_smile: