Closed ozzyobr closed 4 years ago
I thought this could be related to a timing/delay issue, since if you touch the wall switch giving it enough time it works fine. So, after digging on the code following the log structure, I was able to find some locations where "I think" it is calling the api.
I’ve added some “delay”, thinking that if we send commands “slowly” it would work as the same way of the wall switch. Obviously, that did not solve the problem, it only added a delay to it. Oh well, at least I’ve learned something new.
One question, once you touch the wall switch we get an “update” from the API, why do we need to send data back to the api? Shouldn’t we just update Homebridge with the new status?
Remember newbie here, learning on the fly
OK, also found that Sonoff 4CH R2 is also impacted by this.
Apparently, when you press a button in ewelink (or on the switch) it will
looks like I'm talking to myself... 🤔
@howanghk I think I've found the solution but I would like to hear your opinion :)
Every time we receive an update from ewelink through platform.wsc.onmessage we process it, update the accessory state and send a message back to ewelink telling it to update the device state again. In a nutshell we are setting state in ewelink after getting a message from ewelink telling us to update our state and we don't need to do that.
The multi switch is going crazy (check the youtube video in the original post) because when we touch a channel, ewelink sends a message to the plugin and the plugin tells ewelink to execute the same command, that is to turn on/off the same device/channel again. The problem will happen if you touch a second channel in the same device quickly.
Sequence of events:
Action 1: touch device A ch 1 to on Result: ch 1 light turns on
Action 2: plugin gets a message to update status of A ch 1 to on (ch1=on, ch2=off,ch3=off) Result: device A ch 1 state is updated in homebridge
Action 3: touch device A ch 2 to on Result: ch 2 light turns on
Action 4: plugin sends a message to ewelink to update status of A ch 1 to on (ch1=on, ch2=off,ch3=off) Result: ch 1 light turns on, ch 2 light turns off
Action 5: plugin gets a message to update status of A ch 2 to on (ch1=on, ch2=on,ch3=off) Result: device A ch 2 state is updated in homebridge
Action 6: plugin sends a message to ewelink to update status of A ch 2 to on (ch1=on, ch2=on,ch3=off) Result: ch 1 light turns on, ch 2 light turns on
In order to solve the problem I created a new boolean “global variable” to know if we are dealing with an external update or not.
So when a call is made to updatePowerStateCharacteristic I set the variable to “true” meaning it is an external call. When eWeLink.prototype.setPowerState is called it will check if the variable is true, and will not send it back to ewelink.
This resolved all the issues, all my ewelink devices work like a charm (2 and 3 gang, the 4ch pro, mini, basic) including ewelink scenarios to cross turn on and off devices.
I’ve also reconnected Alexa to ewelink and it is working. Now I can use eWelink, Alexa, Homebridge and Home app at the same time.
I know this is not a great way to do it and I should pass it as a parameter but I’m working on it. I was not able to understand how eWeLink.prototype.setPowerState is called after eWeLink.prototype.updatePowerStateCharacteristic.
Let me know if you want to talk about this, looking forward giving back to the community.
no aswer? 😒
I would be interested in seeing your solution!
I would be interested in seeing your solution!
Awesome! I'm swamped with work this week, I'll come back to it during the weekend. thanks!
I would be interested in seeing your solution!
Awesome! I'm swamped with work this week, I'll come back to it during the weekend. thanks!
I'm going through this package line by line trying to improve how some things work. I'd be interested to see how you have solved this issue as it is troubling me. I am not great at coding, but given a template I can sometimes make some changes.
I have (finally!) found a solution myself which seems to work. I'd still be interested to see your fix.
Thanks for replying... I'm looking at it now.
The way I implemented it earlier (and it worked perfectly) was to define a " global" variable and set it to true when we get an external update and test it in the setPowerState. That works and it is easy to implement, the problem is that it is not the best way.
Options I found:
What is your solution? (maybe we work on this together - zoom session maybe, I've a fork https://github.com/ozzyobr/homebridge-ewelink)
(I also purchased a 3gang switch just to test this, wife was not happy with me messing with the lights all the time, LOL)
@ozzyobr how can i contact you?
This issue is fixed on https://github.com/thepotterfamily/homebridge-ewelink-beta
First, thanks for the plugin, it is awesome
I've searched and I was not able to find another issue like this, so I'm creating a new one.
Background:
What I did:
The funny thing is: if I touch the buttons slowly (like with a second after each touch) they work just fine :roll_eyes: Video: https://youtu.be/bUEYP57nBZ8 Log (restarted before recording the video): secondvideo_log.log
Configuration file
I hope this is something I'm doing wrong, I'm really looking forward to make this work with my new apple devices :)
PS: not a coder, but can donate :moneybag: to help with the development, just let me know