[SOLVED] If statement HUE lamp not working

Hi,
I’m stuck and going crazy
the first rule below is not working, the second is

???
Not working

rule "bedlamp aan uit"
when
    Channel "mihome:86sw2:158d0001641c68:ch1" triggered 
then
    if (E2Lbedlamp_dimmer_colortemp.state == OFF) {E2Lbedlamp_dimmer_colortemp.sendCommand(ON)} 
    if (E2Lbedlamp_dimmer_colortemp.state == ON) {E2Lbedlamp_dimmer_colortemp.sendCommand(OFF)} 
 end

Working!

rule "bedlamp aan uit"
when
    Channel "mihome:86sw2:158d0001641c68:ch1" triggered 
then
    E2Lbedlamp_dimmer_colortemp.sendCommand(ON) 
 end

How can i check if my comparison is ok?
is the state of a HUE bulp a string, constant (ON/OFF) or 0/1 ??

My Rule file read correctly, no errors related to this in openhab.log as far as i can see

Thanks for reading my problem

What type of item is E2Lbedlamp_dimmer_colortemp? If it’s not a Switch then it doesn’t store its state as ON or Off.

If it’s a Dimmer or Color Item, then you can get the state as if it were a Switch using

E2Lbedlamp_dimmer_colortemp.getStateAs(OnOffType)
2 Likes

Additional, a good way to debug these kind of issues is typically to include some logging directly after the then to check what E2Lbedlamp_dimmer_colortemp.state returns:

logInfo("BedlampTest","State of bedlamp is " + E2Lbedlamp_dimmer_colortemp.state.toString)
1 Like

Using an if-else structure can be useful

if (myItem.state == ON) {
     myItem.sendCommand(OFF)
} else {
     myItem.sendCommand(ON)
}

If the Item is ON, we turn it off. If it’s anything else - OFF, UNDEF, 22, “alpha” etc. - we turn it on.
That’s often good enough to deal with unexpected NULL states.

I think in this case though you’ll need to think about the states of a dimmer type Item, as Rich says.

Hi Rich,
Your the best!
I was comparing apples to oranges

if (E2Lbedlamp_dimmer_colortemp.getStateAs (OnOffType) == OFF)

works like a charme.

Hi Rolf,

Thanks for showing me that I can use variables, like the state of an item in a logInfo command.

I did not know that!