Hue binding - mass update not always working

Hi guys,

I have a problem with a mass update of multiple lamps at once. I added in total 15 lamps to a group. When I’m switching this group ON or OFF some lamps are not tackled properly. I recognized that the openHab state is set properly because all lamps always receive a correct update. I detected this with some dummy rules like:

rule "f2_floor_lamp_update"
when 
     Item f2_floor_lamp received command
then
	logInfo("playground", "f2_floor_lamp recieve command " + receivedCommand)
end

Next I debugged the hue binding. Here I figured out after setting the bindings log status to DEBUG with:

log:set DEBUG org.eclipse.smarthome.binding.hue  

that for these lamps which are not updated correctly the following sequence is not logged:

2018-11-28 22:30:43.349 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Status update for Hue light 1 detected.
2018-11-28 22:30:43.350 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.350 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.350 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.350 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.350 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.350 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.351 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.351 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.351 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.351 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.351 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.352 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.352 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.352 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.352 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.352 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1
2018-11-28 22:30:43.352 [DEBUG] [binding.hue.handler.HueBridgeHandler] - Sending lightStateChanged for light 1

Any ideas what’s going wrong here? Is that related to a missing delay which I should configure somewhere in the hue binding?

Thanks for any kind of help or hints!

Cheers
Dennis

Hi Dennis,

A quote from the Hue API documentation:

We can’t send commands to the lights too fast. If you stick to around 10 commands per second to the /lights resource as maximum you should be fine.

We have to wait for the group feature to be implemented in the binding or use a workaround till then.

Hi Christoph,

thanks a lot for these infos! To circumvent this problem I have created a dummy item which i treat as group. Within a new rule I added a short delay after a bunch of 8 items. Now it works fine :slight_smile:

Attached the code of this rule if someone needs it:

rule "GMainLivingEnvironmentLamps"
when 
	Item GMainLivingEnvironmentLamps_dummyitem received command or
    Item GMainLivingEnvironmentLamps_dummyitem_alternative received command
then
    val i = 0
	GMainLivingEnvironmentLamps.allMembers.forEach [ item | 
        item.sendCommand(receivedCommand)
        i = i+1
        
        if (i % 8 == 0) {
            Thread::sleep(1000)
        }
	]	
end

Cheers
Dennis

Does anyone know if this is still an issue?

I have approx 20 hue lights that I give a certain state (on;off;dimmed) in the morning. I see that openhab sends the correct command, the lights are just not on.
Sending the commands a second time usually works.

I have this issue to.

An other workaround is to define the group (called room or zone) in your HUE bridge and then use the API call to do something with this group. Just 1 command from OH to HUE bridge and the bridge takes care of the rest.

You have an example for this?

I’m away for work. I’ll show an example next week

If I remember correctly you have to install the HTTP binding.

The regarding the HUE: First have a look at the HUE-API. You need 3 things.
The first thing is the IP address of you HUE-Bridge. I work with a fixed IP but it should also work with a hostname. The IP of my HUE is 192.168.2.99

Second you need to create a ‘user’ which is allowed to use the API
https://developers.meethue.com/develop/get-started-2/.
My user-name is “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”

Finally you have to find out the ID of the group (the group you’ve defined with the HUE app.
https://developers.meethue.com/develop/hue-api/groupds-api/
In the example below the ID of the group is “8” .
Now you have all the info you need.

I first define the URL I have to use, based on the IP, user and group.
Then I define the body of the API.
on = true/false
bri = brightness of the lights (only when on=true)
transitiontime = time to go from current state to new state. In my example = 0 = direct.
Finally I write a line to my log-file, for debugging purposes.

The rule then becomes:

rule "Carport Lights ON at IPCam Motion"
when
    Item IPCam_LineCrossingAlarm received update ON
    then
    if (Sun_PhaseName.state!="DAYLIGHT") {
	    val url = "http://192.168.2.99/api/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/groups/8/action"
        val String body = '{"on":true, "bri":254, "transitiontime":0}'
        logInfo("HUE API call carport", "Send command '{}' to {}", body, url)
        sendHttpPutRequest(url, "application/json", body, 10000)
   }
end