claytonjn / hass-circadian_lighting

Circadian Lighting custom component for Home Assistant
Apache License 2.0
774 stars 89 forks source link

zigbee2mqtt spamming #33

Open irgusite opened 5 years ago

irgusite commented 5 years ago

Hi,

When using circadian at each event, the mqtt server resends an "on" value of the light that seems to retrigger circadian, who resend a new value (the same as before) and makes the server resend an "on" value, and so on.

So it spams the whole server with light changes orders even when the light is at the correct value.

(I don't know if I'm clear, don't hesitate to ask me if you want another explanation, it's late for me ^^)

irgusite commented 5 years ago

Sorry, I didn't ask my question:

Would it be possible to add a condition that it doesn't resend an order if the brightness and the color of the light already are the right value? That would, I think, solve the problem :)

claytonjn commented 5 years ago

I'm actually planning on migrating my non-Hue devices to zigbee2mqtt soon, I am just waiting on the hardware to arrive (might be a few weeks still).

Are you seeing the "spamming" by monitoring MQTT, or the circadian_lighting entries in the HA log, or both?

irgusite commented 5 years ago

Yes I'm seeing it by the MQTT instance.

irgusite commented 5 years ago

I see what to do in the code and would gladly make a PR, but I just don't know how to get the light status back in python. (I'm starting deving on hass but didn't quite get the time to read through the doc ^^)

claytonjn commented 5 years ago

Can you enable debug logging for circadian_lighting and verify that it is in fact sending spam commands? Every time Circadian Lighting sends an adjustment you should see an entry "[...] light adjusted" with the values CL is setting. I want to make sure the issue does lie within Circadian Lighting and not some quirk with zigbee2mqtt.

irgusite commented 5 years ago

As a quick answer I already did it 2 weeks ago and if I remember correctly (I will confirm this later when home) it was always adjusting in debug. But I will confirm that later and put the output here :)

irgusite commented 5 years ago

Hi, so I put circadian into debug mode and let it run approximately 5 seconds on one lamp:

22:09:16 DEBUG (SyncWorker_2) [] Circadian Lighting Switch Updated 22:09:18 DEBUG (SyncWorker_9) [] light.ampoule_chambre_mqtt CT Adjusted - color_temp: 453, brightness: 173.83414695831576, transition: 1 22:09:18 DEBUG (SyncWorker_0) [] light.ampoule_chambre_mqtt CT Adjusted - color_temp: 453, brightness: 173.83414695831576, transition: 1 22:09:19 DEBUG (SyncWorker_6) [] light.ampoule_chambre_mqtt CT Adjusted - color_temp: 453, brightness: 173.83414695831576, transition: 1 22:09:19 DEBUG (SyncWorker_2) [] light.ampoule_chambre_mqtt CT Adjusted - color_temp: 453, brightness: 173.83414695831576, transition: 1 22:09:19 DEBUG (SyncWorker_5) [] light.ampoule_chambre_mqtt CT Adjusted - color_temp: 453, brightness: 173.83414695831576, transition: 1 22:09:19 DEBUG (SyncWorker_9) [] light.ampoule_chambre_mqtt CT Adjusted - color_temp: 453, brightness: 173.83414695831576, transition: 1 22:09:20 DEBUG (SyncWorker_3) [] light.ampoule_chambre_mqtt CT Adjusted - color_temp: 453, brightness: 173.83414695831576, transition: 1 22:09:20 DEBUG (SyncWorker_0) [] light.ampoule_chambre_mqtt CT Adjusted - color_temp: 453, brightness: 173.83414695831576, transition: 1 22:09:21 DEBUG (SyncWorker_4) [] light.ampoule_chambre_mqtt CT Adjusted - color_temp: 453, brightness: 173.83414695831576, transition: 1 22:09:21 DEBUG (SyncWorker_5) [] light.ampoule_chambre_mqtt CT Adjusted - color_temp: 453, brightness: 173.83414695831576, transition: 1 22:09:21 DEBUG (SyncWorker_8) [] light.ampoule_chambre_mqtt CT Adjusted - color_temp: 453, brightness: 173.83414695831576, transition: 1 22:09:22 DEBUG (SyncWorker_4) [] light.ampoule_chambre_mqtt CT Adjusted - color_temp: 453, brightness: 173.83414695831576, transition: 1 22:09:22 DEBUG (SyncWorker_6) [] Circadian Lighting off - not adjusting 22:09:22 DEBUG (SyncWorker_7) [] Circadian Lighting off - not adjusting 22:09:23 DEBUG (SyncWorker_9) [] Circadian Lighting off - not adjusting 22:09:23 DEBUG (SyncWorker_4) [] Circadian Lighting off - not adjusting 22:09:24 DEBUG (SyncWorker_6) [] Circadian Lighting off - not adjusting 22:09:24 DEBUG (SyncWorker_7) [] Circadian Lighting off - not adjusting 22:09:24 DEBUG (SyncWorker_9) [] Circadian Lighting off - not adjusting 22:09:25 DEBUG (SyncWorker_4) [] Circadian Lighting off - not adjusting 22:09:26 DEBUG (SyncWorker_3) [] Circadian Lighting off - not adjusting

(I removed some parts for clarity)

And yes, the lamp did take the right color and brightness

claytonjn commented 5 years ago

Thanks! Checking the state before adjusting should work...I'll try to get that implemented ASAP.

irgusite commented 5 years ago

Any news about the implementation? :)

claytonjn commented 5 years ago

Just got the rest of the hardware for Zigbee2MQTT a couple days ago and haven't had a chance to migrate anything over yet. I'm hoping to have some time next week to work on it.

claytonjn commented 5 years ago

Haven't gotten Zigbee2MQTT set up yet, but I just pushed out a beta release that checks light attributes before adjusting it. Let me know if it fixes the issue.

irgusite commented 5 years ago

It seems to work, At least I have no spamming as i can turn off my lights instantly. But I confirm that later when I get home to check the zigbee2mqtt intance.

Thank you very much :)

claytonjn commented 5 years ago

I made another change per some discussions on the HA forum, and I believe it makes the state check before adjustment unnecessary. Could you try out 1.0.8b when you get a change and make sure the spamming isn't happening?

irgusite commented 5 years ago

Using 1.0.8b without any problems. Just didn't get the time to check the z2m logs

gericho commented 5 years ago

same here

irgusite commented 5 years ago

I just came home and looked at the z2m instance, and I can confirm that there is no more spamming occuring :)

Thank you a lot, your integration is a must and I'm very happy to use it again :)

claytonjn commented 5 years ago

So apparently I screwed up the 1.0.8b release and it was actually the same as 1.0.6. @irgusite @gericho how did you download/install 1.0.8b? I'm curious if you got the correct files or not if it actually fixed the issue.

gericho commented 5 years ago

I downloaded it from the link above https://github.com/claytonjn/hass-circadian_lighting/releases/tag/1.0.8b

at this point I'm confused, the spamming may be caused by the availability_timeout in zigbee2mqtt configuration.yaml that was disabled yesterday... BTW thank you very much for the update, just installed on the HA server, I'll keep you updated

irgusite commented 5 years ago

I updated it from hacs. But something changed and I only changed your plug-in ^^ what happened if it wasn't expected to work?

gericho commented 5 years ago

my HACS shows only "master" branch, so the latest is the 1.0.6, I did the manual installation, so copied the files in custom_components

claytonjn commented 5 years ago

So the betas are on the dev branch and stables are on master. When I created the 1.0.8b release I was a doofus and forgot to switch the branch to dev, so it ended up being the same as release. The changes were all there on the dev branch, but the release didn't have them. I should have noticed because the order of releases was messed up, but apparently I just have too much going on 🙄

Anyway, upgrading from HACS or using that link would have downloaded the "bad" 1.0.8b which was the 1.0.6 code. It basically should have meant that the "spamming" behavior would be occurring again - the fact that it didn't baffles me. Regardless, I feel the changes are for the best so as long as there are no issues with the new 1.0.9b release, I plan on pushing everything to stable.

@gericho you can install betas in HACS by opening up Circadian Lighting, going to the menu in the upper right, and clicking "Show beta"

irgusite commented 5 years ago

1.0.9b doesn't work, the light don't change color, if I manually change it, it doesnt get back instantly, it take like 1 minute to react

gericho commented 5 years ago

I think this is by design since it triggers only ON state, right?

irgusite commented 5 years ago

Oh, yeah seems logic ^^

irgusite commented 5 years ago

Okay, so I'm not at home, but I have some weird things happening with 1.0.9b, I will look at it when I get back and report here :)

claytonjn commented 5 years ago

1.0.9b doesn't work, the light don't change color, if I manually change it, it doesnt get back instantly, it take like 1 minute to react

Yes, this is by design. That's what I changed to prevent the "infinite loop" of CL adjustments triggering more CL adjustments and also to fix the issue reported in the HA forum where you couldn't disable CL based on the state of the lights. It should also minimize occurrences of not being able to turn lights off when the CL switch is enabled.

So basically, if a light and CL switch are both on and you adjust the light, it won't get corrected until the next interval, and will use the configured/default transition. If you turn on the CL switch and there are lights on, or if you turn on a light and the CL switch is on, the lights should adjust immediately (1 sec transition). Also going in/out of "sleep" or "disabled" mode should react immediately.

@irgusite, what type of weird things are happening?