I am trying in a rule to test if a dimming light is ON or OFF. The item is of type Dimmer.
Here is the code:
var OnOffType lampeState = LampeChambre.state as OnOffType
if (lampeState == OFF) {
}
It does not work. Here is the error I get when the rule is run:
2016-02-18 19:46:01.565 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Detection mouvement chambre': Cannot cast org.openhab.core.library.types.PercentType to org.openhab.core.library.types.OnOffType
While you can send ON and OFF to a Dimmer, its state is actually a PercentType. So you have to cast it to a PercentType and use if(lampeState == 0) to test for OFF and if(lampeState !=0) to test for ON.
Now for a hue light, Kai’s adviced me few weeks ago to only create a Color item and then I can use ON and OFF command. But is there a way in a rule, when having only a Color item, to know if the light is ON or OFF ? Or should I keep an additional Switch item in this case ?
I needed this ON/OFF functionality and display in my floor plan page, where I couldn’t get the hint to display other than the percent value.
So I linked another item to my lights dimmer channel (z-wave binding), just with type: switch, and that is working fine, and I can use it both in (javascript) rules and on the floor plan also.