Rule: Types of Light Commands, Phantom Event

  • Platform information:
    • openHAB version: 3.3.0

I have following script:

The aim of this script is to set a Philips Hue Lamp to Blue for 4 seconds and then go back to the state the lamp was before (ON or OFF, same color etc.)

The script works sometimes, sometimes not: the lamp does not switch off when it was off, or has the wrong color. No Idea why. Details see below in the logs.
I think I have typing errors, as it is JavaScript I have no idea if I have the right types. Or I have some fundamental knowledge gap about the Events in the Hue System.


  • What is wrong?

What I am seeing:

  • If the Lamp was switched ON before, everything goes ok.
  • If the Lamp was switched OFF before, it also works. Also the color gets restored to the state before. But :hot_face: when switching it ON from elsewhere in the Hue System, e.g. by a manual switch, the Lamp gets an Event from somewhere to set it to blue. I call this Event a «Phantom Event» .
var farbeVorher;
var statusVorher; 

var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
var thread = Java.type('java.lang.Thread’)/

// store previous state 
farbeVorher = itemRegistry.getItem('Glas_Farbe').getState();
statusVorher = itemRegistry.getItem("Glas_Switch").getState(); 

// set to blue for 4 s;
events.sendCommand('Glas_Switch', 'ON');
events.sendCommand('Glas_Farbe', '210,100,100');

// restore previous state 
events.sendCommand('Glas_Switch', statusVorher); 
events.sendCommand('Glas_Farbe', farbeVorher);

Logs of the Error Path:

# gets reset as expected to old color 309,99,0... 
2022-11-24 07:23:59.624 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Glas_Farbe' received command 309,99,0
2022-11-24 07:23:59.628 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Glas_Farbe' predicted to become 309,99,0
2022-11-24 07:23:59.641 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Glas_Farbe' changed from 210,98,43 to 309,99,0
2022-11-24 07:24:06.447 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Glas_Switch' changed from ON to OFF

# after manual switch ON: 

# ...unexpected event to change to blue 210,100,100 ... 
2022-11-24 07:24:56.678 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Glas_Farbe' changed from 309,99,0 to 210,98,100
2022-11-24 07:24:56.686 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Glas_Switch' changed from OFF to ON

ref. Philips Hue - Bindings | openHAB

Is that a typo or should one be Glas_Switch ?

…yes, I corrected it. (You were very quick, thanks!) Though - there is another Problem :frowning:
I update the description.

What we can’t see there is what the light really did.
By which I mean, autoupdate has as usual made a prediction for us.
We cannot be sure the lamp really went to 309,99,0

We can see a “real” OFF report seven seconds later - there was no command to that Item, so no autoupdate.

Alright, so you were expecting to turn on at the colour of the last command you sent - 309,99,0

There is an assumption in that - because 309,99,0 is the equivalent of OFF.
Are you sure your light takes any notice of colour components when instructed to turn off?
I’m guessing it doesn’t.

I think you’ll have to amend your rule to “restore old colour” at some non-zero brightness, and then a short pause before commanding OFF