ioBroker.hue icon indicating copy to clipboard operation
ioBroker.hue copied to clipboard

Have the HueApiRateLimits of node-hue-api configurable

Open seb2010 opened this issue 6 months ago • 13 comments

Hello,

I am migrating from another adapter which was able to trigger light-group statechanged at the same time. When digging into the code I think I identified the root cause why iobroker.hue is not behaving the same is that iobroker.hue does not set any custom HueApiRateLimits parameters when connecting to the v3 API. Therefor, the API uses the default wait-time between requests of 1000ms (https://github.com/peter-murray/node-hue-api/blob/081da8354c761d3405ddf240ed53d83e01ee7a6c/src/api/HueApiRateLimits.ts).

You can pass custom RateLimits as a third connection-parameter as it seems. Format should be like this: https://github.com/peter-murray/node-hue-api/blob/081da8354c761d3405ddf240ed53d83e01ee7a6c/src/api/HueApiRateLimits.ts

Is it possible to include the option to set custom RateLimits in the adapter?

Unfortunately I am not knowledgable enough on typescrtipt and the whole git-procedure, so I cannot support with actual code-changes here.

Hope you consider this. KR SEB

seb2010 avatar Dec 14 '23 07:12 seb2010

I already tried to manipulate the local code on my node-modules folder, both the connection string as well as the Defaults in the API files. But without success, yet.

seb2010 avatar Dec 14 '23 07:12 seb2010

I think the api itself does configure the minTime of the Ratelimits itself within the file node-hue-api/lib/api/Groups.js overriding probably what you are passing with the createlocal connection string.

My workaround is to set the minTime-value in this file to another value. This works like desired and fires the events for multiple groups with the shorter delay (previously 1000ms). To overcome future updates I added a schedule job to do: exec("sed -i 's/minTime: 1000/minTime: 50/g' /opt/iobroker/node_modules/node-hue-api/lib/api/Groups.js")

seb2010 avatar Dec 14 '23 20:12 seb2010

@seb2010 : I'm migrating currently from hue-extended adapter. I observed that when I switch on/off multiple light, that it is dramatically slower, so a waiting time of aprox. 1 second between each single light. Is this connected to your issue?

RkcCorian avatar Dec 25 '23 14:12 RkcCorian

@seb2010 : Now I understood you speak about commands for multiple groups. If I'm right I have the same issue just with multiple lights. Comming from hue-extended adapter this behaviour feels like stone age in terms of performance.

RkcCorian avatar Dec 25 '23 14:12 RkcCorian

@foxriver76 : Hi Foxriver. Is there a chance to get the Hue-Extended performance soon into this adapter as well? I'm on the way to migrate currently but stuck here as I have so many lights to be swich together (switch on a dedicated ligth setting as well as switching off everything for the night). With sripts I figured out that a waiting time btw. different lights of 150ms works perfect for me. Many many thanks in advance!!! Before I forget it... many thanks for your work and also merry christmas 🎄

RkcCorian avatar Dec 25 '23 14:12 RkcCorian

@seb2010 : Any idea how to workaround even for lights, instead of groups? Many many thanks in advance!!!

RkcCorian avatar Dec 25 '23 14:12 RkcCorian

@seb2010 : Any idea how to workaround even for lights, instead of groups? Many many thanks in advance!!!

@RkcCorian : problem is, that the library used by the hue adapter is not maintained by the same developer. This library sets the timeout intervals for each command. You can most probably work around the issue by issuing a similar modification to this libraries code.

seb2010 avatar Dec 25 '23 15:12 seb2010

@seb2010 : Hmmm... many thanks! Unfortunately I do not know what exactly has to be issued to whom. 😬

RkcCorian avatar Dec 25 '23 15:12 RkcCorian

Rate limit comes from node-hue-api and is currently not configurable. My time resources for this adapter are currently limited but I am happy over PRs. Feel free to create a issue/PR at https://github.com/peter-murray/node-hue-api to make the limit configurable should not be a problem but as far as I know it sticks to the official rate limits (12 calls per second) https://github.com/peter-murray/node-hue-api#rate-limiting

foxriver76 avatar Dec 25 '23 15:12 foxriver76

@seb2010 , @foxriver76 : Many thanks! Now I realized that I also used in my ALIAS everywhere the group names, even for those where I have a 1 to 1 relation btw. group and light, so I could change for some of them. So which means I have currently the exact same issue like seb2010. @seb2010 : Can you pls. explain more in details your workaround as I would like to try the same?!

RkcCorian avatar Dec 25 '23 15:12 RkcCorian

As best practice I can only say, use groups over controlling single lights whenever possible to keep requests low.

foxriver76 avatar Dec 25 '23 16:12 foxriver76

@seb2010 : I managed it, just had to restart the adapter. Stupid question... with "exec("sed -i 's/minTime: 1000/minTime: 50/g' /opt/iobroker/node_modules/node-hue-api/lib/api/Groups.js")" the resulting waiting time is now 50ms? Or what is the resulting time? @foxriver76 : Enclosed the issue... https://github.com/peter-murray/node-hue-api/issues/234

RkcCorian avatar Dec 25 '23 16:12 RkcCorian

@RkcCorian : yes, by modifying the Groups.js file in the node.hue-api module folder, you will end up with a delay between subsequent commands for light-groups of 50ms. At my box, the default delay between light commands is 60ms (Lights.js, same folder). I am not sure how and where you observed a delay between individual single light commands... It should be fine for your case (<150ms)

seb2010 avatar Dec 25 '23 21:12 seb2010