I want to check if my Lamp has a specific color.
But I need a little help.
This is what I was trying:
//if (WZ_Haengelampe_Color.state as HSBType == new HSBType(new DecimalType(36), new PercentType(51), new PercentType(100)) )
//if (WZ_Haengelampe_Color.state as HSBType == 36,51,100 )
That’s not going to work, because 36,51,100 is not a valid rules literal.
You might try a stringy version. if (WZ_Haengelampe_Color.state.toString == "36,51,100" )
This looks more promising, what goes wrong with it?
In real life you might want to be testing more of a range than an exact match, what do you want to happen with 36.0001,51,100 ?
To do that you’d have to extract the parts and compare individually I think.
Character , is neither a decimal digit number, decimal point, nor “e” notation exponential mark. in Schalter
I want to Change my Lamp to this color. If the Lamp has already this color I want to turn the Lamp off.
if (WZ_Haengelampe_Color.state as HSBType == new HSBType(new DecimalType(36), new PercentType(51), new PercentType(100)) )
{
WZ_Haengelampe_Color.sendCommand(OFF)
}
else
{
WZ_Haengelampe_Color.sendCommand("36,51,100")
}
This is an interesting adventure. Using VSCode, it gives a clue that it is the == at the heart of the problem.
if (WZ_Haengelampe_Color.state as HSBType == new HSBType(...
The trouble seems to be that an HSBType object has no useful == operator, so rules DSL falls back on a simple numeric comparison - which will fail of course, because we don’t have a simple numeric. This I think is where the comma complaint comes from.
I’d guess the lack of == is because it is pretty useless in real life, as already mentioned you’d not normally get exact matches.
Anyway, in this case I think you will get away with using the === identity operator instead, to compare HSB objects instead of just value(s).
EDIT - no, this the way, the HSB type has an .equals() method
if ( (WZ_Haengelampe_Color.state as HSBType).equals(new HSBType(...)) )