Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have the HueApiRateLimits of node-hue-api configurable #542

Open
seb2010 opened this issue Dec 14, 2023 · 13 comments
Open

Have the HueApiRateLimits of node-hue-api configurable #542

seb2010 opened this issue Dec 14, 2023 · 13 comments

Comments

@seb2010
Copy link
Contributor

seb2010 commented Dec 14, 2023

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
Copy link
Contributor Author

seb2010 commented Dec 14, 2023

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
Copy link
Contributor Author

seb2010 commented Dec 14, 2023

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")

@RkcCorian
Copy link

@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
Copy link

@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
Copy link

RkcCorian commented Dec 25, 2023

@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
Copy link

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

@seb2010
Copy link
Contributor Author

seb2010 commented Dec 25, 2023

@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.

@RkcCorian
Copy link

RkcCorian commented Dec 25, 2023

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

@foxriver76
Copy link
Member

foxriver76 commented Dec 25, 2023

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

@RkcCorian
Copy link

@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?!

@foxriver76
Copy link
Member

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

@RkcCorian
Copy link

RkcCorian commented Dec 25, 2023

@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... peter-murray/node-hue-api#234

@seb2010
Copy link
Contributor Author

seb2010 commented Dec 25, 2023

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants