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")
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
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
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ā¦
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