sidoh / esp8266_milight_hub

Replacement for a Milight/LimitlessLED hub hosted on an ESP8266
MIT License
943 stars 220 forks source link

Any way to set multiple lights in a single http request? #839

Open furahivszuri opened 5 days ago

furahivszuri commented 5 days ago

Hello,

I control 15 Milight bulbs set up around a room. Some are RGBW, some RGB_CCT. I wrote a page that allows me to program them. Basically a simple JSON config lets you set all bulbs to the same color, each to a different color or even animations (with either all bulbs animating at the same time, or each bulb individually). I don't sync to music or anything crazy, so precise timings are not important, but quick changes are

I originally ran it with Milight controllers, and for the most part it worked

I recently moved to an esp8266 controller with ESPMH, and I've noticed that it's relatively easy to send too many http requests in a short time to the hub. The web server stops responding after a while.

I've tried many tings, like sending or not sending blockOnQueue, awaiting each request (which I am currently doing fro a browser), that ends up being too slow; sending a few requests staggered and awaiting them, etc...

The thing is for many of these animations, I'll really have 3 or 4 different colors, so if i could send a request like "PUT gateways/1/rgbw/1, gateways/1/rgbw/2, gateways/1/rgb_cct/1" with a body of {"hue":240,"saturation":60,"level":100,"status":"on"} , tht would save me a lot of requests

Even better if a single request could set all the lights at once (like set 1 and 2 to yellow, 3 and 4 to blue, 5 and 6 to red). I get there is only one radio, so they will actually execute sequentially, that's fine, a single request for all the lights is easier to await compared to one per light, the overhead adds up quickly

Failing that, any recommendations on how to tune the software and my requests for best performance?

Thanks

sidoh commented 5 days ago

There's not currently a way to do this with the API, but I'm open to adding one! There was at some point a way to fan out eg:

PUT /gateways/1,2,3/rgbw,rgb_cct/1,2

but that would send the cartesian product of all of those (so 3*2*2 in this case). ~It's possible that still works actually, but looking at the code~ I think I broke that ages ago during a migration (I just checked, it's broken). If it's useful in that form it's a relatively simple fix (these TokenIterators here need to have the third argument set to ,) .

Think I'd rather add a separate endpoint like PUT /gateways or PUT /gateways/batch or something like that which accepts an array of IDs in the body as you're suggesting. Also not very hard to add that! lib/WebServer is the place to look if you're interested in taking a crack at it.

furahivszuri commented 5 days ago

Thanks! I'll have a look and give it a try myself!

If I don't stop myself though, I might end up trying to add the whole animation engine (maybe in a fork, I'm not sure that code would be super useful to everyone else)