HSBType comparison

Hi,

I want to compare the HSBType of an Item with another HSBType (is it equal)? So I did something along the lines

rule "Example"
when
Item Something changed
then
if ((Hue_Example.state as HSBType).equals(someotherHSBvariable)) { do something }
end

However this does not work. So I wanted to log the contents of the Hue_Example.state.

var HSBType temp=Hue_Example.state as HSBType
var temp2=temp.toString
loginfo(“test”,temp2)

But this results in

22:26:42.547 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘HueWZScenes’: An error occured during the script execution: The name ‘loginfo(,)’ cannot be resolved to an item or type.

What am I missing? Hue_Example is an Item associated with a hue color channel:

Hue_Example (Type=ColorItem, State=61,100,68, Label=null, Category=light, Groups=[gWzHue])

Should “Hue_Example as HSBType” not cast this to HSB?

I think you may need to use Hue_Example.state as below to get the actual HSBType. Hue_Example is an Item or Group object, not a HSBType object.

rule "Example"
when
Item Something changed
then
if ((Hue_Example.state as HSBType).equals(someotherHSBvariable)) { do something }
end

Totally correct. Typo on my end. I am using .state and it is not working.

Turns out I was doing most things correctly. Using logInfo instead of loginfo helps tremendously.

The .equal does not work since the hue bridge seems to randomly change some setting. E.g. I am setting th me brightness to 69 and a few seconds later openHAB notices a change to 68. I wrote my own comparison rule which allows for some small deviations and all is fine now. Case closed. :slight_smile: