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

Add support for ICTC-G-1 controller #5

Closed
wants to merge 2 commits into from
Closed

Add support for ICTC-G-1 controller #5

wants to merge 2 commits into from

Conversation

EPMatt
Copy link
Contributor

@EPMatt EPMatt commented Jan 6, 2020

The ICTC-G-1 wireless dimmer from IKEA is out of production but it's still being sold around.
It works differently from the other controllers but I managed to integrate it quite well, although sometimes the dimming function is not totally fluent and could be a little slow. This is probably caused by the large quantity of messages sent by the dimmer itself and the whole zigbee2mqtt/hass/appdaemon software roundtrip.
Succesfully tested with delay : 150 in the app configuration.

@xaviml
Copy link
Owner

xaviml commented Jan 6, 2020

Hi @EPMatt ,

First of all, thank you for your support and for bringing this new device integration to this repository. I casually was changing the code when you submitted the PR, so I integrated your functionality on it. I had to change the base code so new devices can be integrated in a much easier way. Unfortunately, I do not have a ICT-G-1 device to test it, but I tried to copy the same logic as you did. I got rid off the self.rotating since it was used because the action was called twice, but that was fixed and now is only called once.

Would you be able to check the code and let me know if it works as expected?

Thank you very much!

@EPMatt
Copy link
Contributor Author

EPMatt commented Jan 7, 2020

Hi @xaviml, nice work on the app refactor!
I tested your code for the ICTC-G-1 controller and it doesn't work really well; moving the dimmer causes the light to start flashing.
Unfortunately this is a problem with the controller itself, since it sends lots of messages, some of which are duplicate.
e.g. just slightly rotating the dimmer to the right I get this whole bunch of messages:

{"brightness":0,"linkquality":147,"rate":70,"level":0,"battery":60,"action":"rotate_right"}
{"brightness":0,"linkquality":147,"rate":70,"level":0,"battery":60,"action":""}
{"brightness":0,"linkquality":68,"rate":195,"level":0,"battery":60,"action":"rotate_right"}
{"brightness":0,"linkquality":68,"rate":195,"level":0,"battery":60,"action":""}
{"brightness":0,"linkquality":147,"rate":195,"level":0,"battery":60,"action":"rotate_right"}
{"brightness":0,"linkquality":147,"rate":195,"level":0,"battery":60,"action":""}
{"brightness":0,"linkquality":68,"rate":195,"level":0,"battery":60,"action":"rotate_right"}
{"brightness":0,"linkquality":68,"rate":195,"level":0,"battery":60,"action":""}
{"brightness":20,"linkquality":147,"rate":195,"level":0,"battery":60,"action":"rotate_right"}
{"brightness":20,"linkquality":147,"rate":195,"level":0,"battery":60,"action":""}
{"brightness":32,"linkquality":147,"rate":195,"level":0,"battery":60,"action":"rotate_stop"}
{"brightness":32,"linkquality":147,"rate":195,"level":0,"battery":60,"action":""}
{"brightness":32,"linkquality":68,"rate":195,"level":0,"battery":60,"action":"rotate_stop"}
{"brightness":32,"linkquality":68,"rate":195,"level":0,"battery":60,"action":""}
{"brightness":32,"linkquality":147,"rate":195,"level":0,"battery":60,"action":"rotate_stop"}
{"brightness":32,"linkquality":147,"rate":195,"level":0,"battery":60,"action":""}
{"brightness":32,"linkquality":68,"rate":195,"level":0,"battery":60,"action":"rotate_stop"}
{"brightness":32,"linkquality":68,"rate":195,"level":0,"battery":60,"action":""}

It looks like in IKEA Zigbee implementation the dimmer directly sets the bulb brightness by sending it in the payload to the light. But since we deal with just the action to change the bulb brightness, we end with many duplicates.

So messages trigger the state function and lots of threads are generated, each of them accessing the light and changing its brightness. The unregulated concurrent access to the light causes each thread to read a random brightness value and change it, without any specific order, resulting in the bulb to randomly change brightness.

self.rotating was used to make sure that just one thread was able to execute the action and edit the bulb brightness (but with more debug I realized that in some rare cases, e.g. when two threads are working almost simultaneously, the latter reads self.rotating=False, still not updated by the first thread, and triggers the hold() function).

I could try to reimplement the self.rotating check on the new code so we can integrate the controller and get rid of most concurrency issues (but unfortunately not all of them).

@xaviml
Copy link
Owner

xaviml commented Jan 7, 2020

Hi @EPMatt,

Thanks for your detailed reply. I observed that there was a bug related to the "hold" action. The problem was that if "hold" was called one after the other, each thread would go through the loop. Now I fixed it, so the hold function of the "rotate_right" should be called once and then it will called released when "rotate_stop". Let me know if this fixed the problem.

@EPMatt
Copy link
Contributor Author

EPMatt commented Jan 8, 2020

Hi @xaviml,
thanks for the fix, the integration works almost perfectly now. I verified that the hold() function is called only once for each rotation of the controller and the light dimming is quite fluent.
There are still troubles with turning off the lamp: it looks like some random messages are sent after a rotate_left_quick, due to the dimmer movement, e.g. a few rotate_left and rotate_stop, causing the lamp to dim and not to turn off.
I'll take a deeper look tomorrow and let you know if I can fix this issue.
We're almost there!

@xaviml
Copy link
Owner

xaviml commented Jan 8, 2020

Okay @EPMatt. If needed, you can create new functions (with an "action" decorator) to the LightController that can be called from the device integration. Good luck with it!

@EPMatt
Copy link
Contributor Author

EPMatt commented Jan 8, 2020

Thanks @xaviml! I'm closing this PR and opening a new one with the fix.

@EPMatt EPMatt closed this Jan 8, 2020
@EPMatt EPMatt deleted the ictc-g-1-support branch January 8, 2020 10:45
@EPMatt EPMatt mentioned this pull request Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants