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

Lights turn on/off one by one, color change works fine #331

Closed
FezVrasta opened this issue Aug 19, 2018 · 34 comments
Closed

Lights turn on/off one by one, color change works fine #331

FezVrasta opened this issue Aug 19, 2018 · 34 comments
Labels

Comments

@FezVrasta
Copy link
Contributor

FezVrasta commented Aug 19, 2018

Hi I'd really like to understand why the lights turn on or off one by one rather than all together.

It used to happen even when I changed colors, but with the recent versions the color changes are synced correctly across all the lights. So you must have fixed it somehow I guess?

As you can see in the gif below, the lights should turn on all together but actually they turn on one after the other (it happens in the web UI but even on the physical bulbs)

hue

Below you find the log of what happened once I tried to turn all of them off together:

/opt/hue-emulator
❯ sudo python3 HueEmulator3.py                                                                                                                                    pi@raspberrypi
Config loaded
starting ssdp...
start ssdp broadcast
sync with lights
Starting httpd...
Starting ssl httpd...
10.0.0.6 - - [19/Aug/2018 07:49:30] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:30] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:31] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:31] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:32] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:32] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:33] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:33] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:34] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:34] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:35] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:35] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
Sending M-Search response to 10.0.0.2
10.0.0.6 - - [19/Aug/2018 07:49:36] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:36] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
10.0.0.2 - - [19/Aug/2018 07:49:36] "GET /description.xml HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:37] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:37] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
Sending M-Search response to 10.0.0.18
10.0.0.6 - - [19/Aug/2018 07:49:38] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:38] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:39] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:39] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
Sending M-Search response to 10.0.0.10
10.0.0.6 - - [19/Aug/2018 07:49:40] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:40] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
sync with lights
10.0.0.6 - - [19/Aug/2018 07:49:41] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:41] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:41] "PUT /api/web-ui-11293/groups/0/action HTTP/1.1" 200 -
in PUT method
/api/web-ui-11293/groups/0/action
b'{"on":false}'
10.0.0.6 - - [19/Aug/2018 07:49:42] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:42] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
LightRequest: http://127.0.0.1:81/api/8B5D1889A0/lights/17/state
10.0.0.6 - - [19/Aug/2018 07:49:43] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:43] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
Sending M-Search response to 10.0.0.2
LightRequest: http://127.0.0.1:81/api/8B5D1889A0/lights/8/state
10.0.0.6 - - [19/Aug/2018 07:49:44] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:44] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
LightRequest: http://127.0.0.1:81/api/8B5D1889A0/lights/7/state
10.0.0.6 - - [19/Aug/2018 07:49:45] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:45] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
LightRequest: http://127.0.0.1:81/api/8B5D1889A0/lights/13/state
10.0.0.6 - - [19/Aug/2018 07:49:46] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:46] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
LightRequest: http://127.0.0.1:81/api/8B5D1889A0/lights/2/state
10.0.0.6 - - [19/Aug/2018 07:49:47] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:47] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
LightRequest: http://10.0.0.3/api/lsP8m7WVQJLvbDh-d7L4Evdi05UiVpu14k3Y86wJ/lights/32/state
10.0.0.6 - - [19/Aug/2018 07:49:48] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:48] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
LightRequest: http://127.0.0.1:81/api/8B5D1889A0/lights/18/state
10.0.0.6 - - [19/Aug/2018 07:49:49] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:49] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
LightRequest: http://127.0.0.1:81/api/8B5D1889A0/lights/4/state
10.0.0.6 - - [19/Aug/2018 07:49:50] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:50] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
LightRequest: http://127.0.0.1:81/api/8B5D1889A0/lights/14/state
10.0.0.6 - - [19/Aug/2018 07:49:51] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:51] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
LightRequest: http://127.0.0.1:81/api/8B5D1889A0/lights/3/state
10.0.0.6 - - [19/Aug/2018 07:49:52] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:52] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
sync with lights
10.0.0.6 - - [19/Aug/2018 07:49:53] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:53] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
LightRequest: http://127.0.0.1:81/api/8B5D1889A0/lights/19/state
10.0.0.6 - - [19/Aug/2018 07:49:54] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:54] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
LightRequest: http://127.0.0.1:81/api/8B5D1889A0/lights/16/state
Sending M-Search response to 10.0.0.2
10.0.0.6 - - [19/Aug/2018 07:49:55] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:55] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
LightRequest: http://127.0.0.1:81/api/8B5D1889A0/lights/5/state
Sending M-Search response to 10.0.0.2
10.0.0.6 - - [19/Aug/2018 07:49:56] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:56] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
LightRequest: http://127.0.0.1:81/api/8B5D1889A0/lights/15/state
10.0.0.6 - - [19/Aug/2018 07:49:57] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:57] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
LightRequest: http://10.0.0.3/api/lsP8m7WVQJLvbDh-d7L4Evdi05UiVpu14k3Y86wJ/lights/30/state
Sending M-Search response to 10.0.0.2
10.0.0.6 - - [19/Aug/2018 07:49:58] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:58] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
LightRequest: http://10.0.0.3/api/lsP8m7WVQJLvbDh-d7L4Evdi05UiVpu14k3Y86wJ/lights/29/state
10.0.0.6 - - [19/Aug/2018 07:49:59] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:49:59] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
Sending M-Search response to 10.0.0.7
LightRequest: http://127.0.0.1:81/api/8B5D1889A0/lights/9/state
10.0.0.6 - - [19/Aug/2018 07:50:00] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:50:00] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
LightRequest: http://10.0.0.3/api/lsP8m7WVQJLvbDh-d7L4Evdi05UiVpu14k3Y86wJ/lights/31/state
Sending M-Search response to 10.0.0.7
10.0.0.6 - - [19/Aug/2018 07:50:01] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:50:01] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
LightRequest: http://127.0.0.1:81/api/8B5D1889A0/lights/6/state
[
    {
        "success": {
            "/groups/0/action/on": false
        }
    }
]
10.0.0.6 - - [19/Aug/2018 07:50:02] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:50:02] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
Sending M-Search response to 10.0.0.7
10.0.0.6 - - [19/Aug/2018 07:50:03] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:50:03] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
sync with lights
Sending M-Search response to 10.0.0.19
10.0.0.6 - - [19/Aug/2018 07:50:04] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:50:04] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:50:05] "GET /api/web-ui-11293/groups HTTP/1.1" 200 -
10.0.0.6 - - [19/Aug/2018 07:50:05] "GET /api/web-ui-11293/lights HTTP/1.1" 200 -
@mariusmotea
Copy link
Owner

For scenes i refactor how requests where handled but looking at your output i don't believe is a big difference. Now it send instant first two light requests for every device and then for remaining lights will wait for request to complete then go to next one. I can try to send requests without to wait for them to complete but with a delay of ~100ms because for sure devices with big number of lights can be overloaded.

@mariusmotea
Copy link
Owner

I made new commit, can you check how fast are the lights turned off now and if all are turned off? In the past i have complaints about lights that remain on or off and i don't know exactly what is the minimum possible delay without negative effects. You can play with that sleep value from above commit until you have the best result.

@FezVrasta
Copy link
Contributor Author

FezVrasta commented Aug 19, 2018

I tried your commit but it's still too slow, I reduced it to 0.05 but it was still too slow, I got rid of the sleep all together and it's better but it's still not instantaneous :-(

I wonder why can't you have the same responsivity that the DeCONZ web gui provides?

@FezVrasta
Copy link
Contributor Author

Actually, if I toggle all the lights with the global toggle, they are quite fast, if I toggle just a single room they are slow 🤔

@mariusmotea
Copy link
Owner

I apply this just for group 0. I can apply also for particular groups

mariusmotea added a commit that referenced this issue Aug 19, 2018
@mariusmotea
Copy link
Owner

I made new commit that will send requests with 100ms delay also for scenes and particular groups.

@FezVrasta
Copy link
Contributor Author

With the latest commit the UI updates instantly but the bulbs still turn on/off one by one.

@FezVrasta
Copy link
Contributor Author

May you look at how the Home Assistant DeCONZ component handles this and copy from it? From Hass I can turn on/off all my lights at once instantly, so there must be a way.

@FezVrasta
Copy link
Contributor Author

https://photos.app.goo.gl/vEtRjpYfzGAYJa189

The one on the left is DIYHue, the one on the right is Home Assistant (with a Lovelace card containing the individual bulbs, not a DeCONZ group).

DIYHue is slightly slower, and in one case one of the bulbs has a long delay.

@maxakuru
Copy link
Collaborator

What type of bulbs are you using in the group? are they all the same type?

@FezVrasta
Copy link
Contributor Author

@maxakuru the ones in the video are Ikea Tradfri GU10, I also have 6 Hue bulbs that behave in a similar way.

@FezVrasta
Copy link
Contributor Author

FezVrasta commented Aug 19, 2018

ps. actually I just tested a group of 3 Hue E27 bulbs and they seem to work very well with the latest changes.

Those 3 Hue bulbs are connected to a Hue bridge, my IKEA lights are connected on DeCONZ.

I also have 2 Hue GU10 connected to DeCONZ, I'll try them as soon my wife wakes up since they are in our bedroom 😂

@mariusmotea
Copy link
Owner

For group 0 that apply to all lights i can call also group 0 in deconz, for particular groups i don't have a perfect solution.

@maxakuru
Copy link
Collaborator

This might be a good situation to try a ThreadPoolExecutor to handle all the light requests.

It would also be useful to profile these calls so we can find the bottleneck. I could add a profiler on another branch when I get home in a couple hours.

@mariusmotea
Copy link
Owner

The big problem is the limitation on destination device. We cannot change more than one attribute per http request. If we wait for current http request to complete there will be a noticiable delay between lights change. If we send them all at once the destination device will be overloaded (this was in first place until one guy with 9 bulbs complain that not all lights are updated). Now i place an 100ms delay between requests, but i believe deconz also add an internal delay between requests.

@maxakuru
Copy link
Collaborator

In this scenario is the destination device the bulb? I’m waiting on my RaspBee module, so I’m not totally familiar with deconz yet. If the destination is the bulb, wouldn’t sending a single request to each bulb concurrently be fine? Right now I see that a thread is spawned to make each request, we could also try using async requests with requests.futures.

Let me know if I’m missing something!

@mariusmotea
Copy link
Owner

async requests with requests.futures

did not play with that. The issue for me is still Deconz because it receive the http requests and the light updates happen with extra delay.
Possible workarounds:

  • when a group i created in diyhue, in deconz must be created a new group with the lights that belong to deconz and then requests must be forwarded to that group id. Complexity is high because require this synchronization and add space for lot of exceptions because of changes on deconz side.
  • requests to group 0 to be forwarded also to group 0 on deconz and hue bridge. Complexity is low, i will try to do this today.

@mariusmotea
Copy link
Owner

i made new commit in develop branch as i cannot test and is risk to create issues. This new commit must forward group 0 requests to deconz and hue bridge. If all lights on/off actions is happening again with delay on some lights the issue is with deconz or ikea bulbs firmware.

@FezVrasta
Copy link
Contributor Author

@mariusmotea I tried your commit but I think something is wrong, the API returns an EMPTY_RESPONSE error.

@mariusmotea
Copy link
Owner

i will try to debug this

mariusmotea added a commit that referenced this issue Aug 19, 2018
@mariusmotea
Copy link
Owner

@FezVrasta i found the issue and i believe is the only one.

@FezVrasta
Copy link
Contributor Author

FezVrasta commented Aug 19, 2018

Thanks now it works, yes the "turn all on/off" now works very well, now I'd like to have the same for any kind of interaction, I'm especially interested in this because I really want to get rid of my Hue bridge that right now I use for my Ambilight + Hue TV but the performance of this project aren't good enough to provide a good experience at the moment :-(

(I even tried the Entertainment API through the app and is laggy at best...)

@mariusmotea
Copy link
Owner

Good! I will try to replicate the same for rooms but i'm not sure the tv send request to rooms because If it send requests to rooms it must apply the same color to all lights in the room. I have a Philips TV home and i can confirm this in a few days.
Regarding Entertainment API here i have good news and bad news. The bad news is that i cannot do any improvements for deconz with current api (maybe tune the delay to find the minimum values until deconz will crush (now on every 24 entertainment frames i skip 23 and send just one). Imagine that for every light i need to send 2 http request (one for xy cie color, one for brightness). Now the good news is that native lights work even better than original Hue Entertainment devices and this is because wifi protocol is faster than zig bee. If you want to have nice lights in your room just buy a few meters of WS2812B strips (5m - 300 leds ~ 20$), one or two wemos d1 mini and you can do much more than with original Philips Hue devices because you can split them in multiple virtual lights. As design you cannot made any difference between original philips hue strips and WS2812B strips in silicon tube.

Here is a demo with 1m strip (no silicon tube) with 60 leds splited in 3 virtual lights https://www.youtube.com/watch?v=5omFrvqBLII If you look better you will see there is a small delay, but this is because the CPU was in 100% by Hue Sync process. On windows i made a test and is working much faster.

@FezVrasta
Copy link
Contributor Author

FezVrasta commented Aug 19, 2018

Actually the Entertainment performance problem is noticeable even on the Hue Bridge controlled lights. I suppose you don't interact with the Entertainment API of the bridge right? (I mean, BridgeEmulator exposes the Entertainment API but internally it doesn't use it to talk with the Hue Bridge?).

If not, it may make sense to default to the Hue Bridge entertainment API for all the commands to improve the overall speed?

@FezVrasta
Copy link
Contributor Author

About the Ambilight. I used the room as a way to test a change of a lot of lights al together. I know the Ambilight is going to control them individually

@FezVrasta
Copy link
Contributor Author

@mariusmotea I think develop has a bug, the state of the lights don't seem to be synced with what BridgeEmulator exposes (light is on but on the UI it tells is off)

@mariusmotea
Copy link
Owner

Can you provide details so i can replicate this? How you changed the lights status?

@FezVrasta
Copy link
Contributor Author

I changed the status with Home Assistant

@FezVrasta
Copy link
Contributor Author

hue

also, not sure if related, but this doesn't seem right

@mariusmotea
Copy link
Owner

Ok, clear enough to investigate

mariusmotea added a commit that referenced this issue Aug 20, 2018
mariusmotea added a commit that referenced this issue Aug 20, 2018
@mariusmotea
Copy link
Owner

@FezVrasta Thanks for this report. For some reasons i did not discover this bug by myself. Is fixed now.

@juanesf
Copy link

juanesf commented Aug 23, 2018

Hi, I think it would also be useful to add a back button to both (link device and import from bridge)

@juanesf
Copy link

juanesf commented Aug 23, 2018

Thank you all for the excellent work 👏

@ghost
Copy link

ghost commented Aug 29, 2018

Issue fixed

@ghost ghost closed this as completed Aug 29, 2018
@ghost ghost added the Bug label Aug 29, 2018
grywnn pushed a commit to grywnn/diyHue that referenced this issue Apr 15, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants