howanghk / homebridge-ewelink

Homebridge plugin to control Sonoff relays with OEM firmware
MIT License
81 stars 46 forks source link

UUID error #19

Open ghost opened 5 years ago

ghost commented 5 years ago

Hi. Great plugin. I got one problem. When controlling from only Home app (HomeKit) there is no problems. If I turn off the lights from the wall switch and back to Home app, its generate this error and Homebridge is disconnected. Why?

[3/14/2019, 6:16:08 PM] [eWeLink] Adding accessory for deviceId [100025d1feCH1]. [3/14/2019, 6:16:08 PM] [eWeLink] Found Accessory with Name : [Bedroom light CH 1], Manufacturer : [T1 UK3C], Status : [off], Is Online : [true], API Key: [879db2c8-04fd-4e79-b795-aa9a9c29c088] /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:266 throw new Error("Cannot add a bridged Accessory with the same UUID as another bridged Accessory: " + existing.UUID); ^

Error: Cannot add a bridged Accessory with the same UUID as another bridged Accessory: 9ae95042-520b-4c7c-93f3-55c0d8bee4f3 at Bridge.Accessory.addBridgedAccessory (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:266:13) at Bridge.Accessory.addBridgedAccessories (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:292:10) at Server._handleRegisterPlatformAccessories (/usr/local/lib/node_modules/homebridge/lib/server.js:473:16) at Server. (/usr/local/lib/node_modules/homebridge/lib/server.js:41:10) at API.emit (events.js:197:13) at API.registerPlatformAccessories (/usr/local/lib/node_modules/homebridge/lib/api.js:159:8) at eWeLink.addAccessory (/usr/local/lib/node_modules/homebridge-ewelink-max/index.js:391:14) at eWeLink.updatePowerStateCharacteristic (/usr/local/lib/node_modules/homebridge-ewelink-max/index.js:414:18) at /usr/local/lib/node_modules/homebridge-ewelink-max/index.js:234:54 at Array.forEach ()

howanghk commented 5 years ago

Hi @eiriksk , thanks for reporting the issue. As I do not have a multi-channel device, I cannot test and reproduce the problem on my own. This project is open source and have a relaxed license that you are free to modify the code and share your work. You can look into the source code, it's written in Javascript which is fairly easy to understand and write. It would be great if you can fix the bug and send me a pull request.

ghost commented 5 years ago

But do the Homebridge and Ewelink give the same UUID? When using the Ewelink app or switch it throws this error..: Error: Cannot add a bridged Accessory with the same UUID as another bridged Accessory: If I only use Homekit app there is no problems. This problem also appear when using a basic switch.

howanghk commented 5 years ago

can you try installing homebridge-ewelink-max@0.1.10 and see if it works for you?

ghost commented 5 years ago

Thanks, that fixed the problem. What was the issue? Only problem now is that "state" in Home app is not changing from "ON" to "OFF or "OFF" to "ON". You have click once on the icon to update its status. This problem is only when using the Wall switch or button on Basic switch.

howanghk commented 5 years ago

0.1.10 was an old version that do not include the new code that tries to support multi-channel devices properly. Thanks for your feedback, I will look into the code again and see what was causing the problem.

ghost commented 5 years ago

Let me know, if you find a solution ;)

ghost commented 5 years ago

Did you figure out why Home app is not updating when using wall switch?

howanghk commented 5 years ago

The Home app should update accordingly when you change the state on the device: https://github.com/howanghk/homebridge-ewelink/blob/9940ac20224c5e35e0ba8d12af16a4266cc659e5/index.js#L225-L239

ghost commented 5 years ago

Ok this line of code was missing in this version: 1.10. Not working. It then gives this error

TypeError: Cannot read property 'get' of undefined at eWeLink.getPowerState (/usr/local/lib/node_modules/homebridge-ewelink-max/index.js:459:20) at Characteristic. (/usr/local/lib/node_modules/homebridge-ewelink-max/index.js:334:26) at Characteristic.emit (events.js:197:13) at Characteristic.getValue (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Characteristic.js:164:10) at Bridge. (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:762:20) at Array.forEach () at Bridge.Accessory._handleGetCharacteristics (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:726:8) at HAPServer.emit (events.js:197:13) at HAPServer._handleCharacteristics (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/HAPServer.js:926:10) at HAPServer. (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/HAPServer.js:209:39)

howanghk commented 5 years ago

Hi @eiriksk , the code for handling websocket update message was there since the beginning, before I create this fork. And the error you mentioned is a duplicate of #16. As I cannot reproduce the issue on my own, it is unlikely I can fix it anytime soon. It seems you do have the incentive to get the plugin working, it would be great if you can look into the code, fix the bug and submit a pull request. This plugin contains code written by 7 different people, you can be the 8th contributor!

divemasterjm commented 5 years ago

Hi ive got same problem with sonoff ch4 r2, try installing homebridge-ewelink-max@0.1.10 and works for me, im not a programer but i can do the test you need to solve the problem an have posibility to install newer versions

UlisesAR commented 4 years ago

Hi. Good day.

When I clear persistant devices, and remove all accessories, everything works (Start on Boot or calling homebridge command directly) but, the moment I turn-on or turn-off a Sonoff T2 Ch1 or Ch2, the Plug-in will try to add devices again and send the error message "Cannot add a bridged Accessory with the same UUID as another bridged Accessory" stopping the homebridge functionality and not be able to start it again unless I remove persist info and Accessories info (Deleting all settings with it).

Has anyone found a workaround to fix this behaviour?

Thanks in advance!

howanghk commented 4 years ago

Hi divemasterjm and UlisesAR, please install the latest version (0.1.19 as of time of writing) and see if the problem still happen to you?

npm install -g homebridge-ewelink-max@latest
UlisesAR commented 4 years ago

Hi divemasterjm and UlisesAR, please install the latest version (0.1.19 as of time of writing) and see if the problem still happen to you?

npm install -g homebridge-ewelink-max@latest

I will do it and update my experience after tests. With the reinstall is enough or, should I remove all Persist and Accessories directories to do a "fresh start"?

UlisesAR commented 4 years ago

Hi divemasterjm and UlisesAR, please install the latest version (0.1.19 as of time of writing) and see if the problem still happen to you?

npm install -g homebridge-ewelink-max@latest

I will do it and update my experience after tests. With the reinstall is enough or, should I remove all Persist and Accessories directories to do a "fresh start"?

Hi. This is what I did.

pi@raspberrypi:~ $ sudo systemctl status homebridge ● homebridge.service - Node.js HomeKit Server Loaded: loaded (/etc/systemd/system/homebridge.service; enabled; vendor preset: enabled) Active: activating (auto-restart) (Result: exit-code) since Mon 2020-01-13 11:55:24 CST; 2s ago Process: 5303 ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=143) Main PID: 5303 (code=exited, status=143)

dhutchison commented 4 years ago

I've seen this too and it looks like it is related to this: https://github.com/homebridge/homebridge/issues/619

Although from a quick skim of the code it looks like it references the correct approach. Checking the cachedAccessories file for homebridge does show I've ended up with a duplicate of the accessory. Clearing out /homebridge/accessories/cachedAccessories should temporarily resolve it, but I'll keep an eye out if it reappears.

homebridge_1  | [5/3/2020, 6:07:58 PM] [eWeLink] Initializing eWeLink platform...
homebridge_1  | [5/3/2020, 6:07:58 PM] [eWeLink] Intialising eWeLink
homebridge_1  | [5/3/2020, 6:07:58 PM] [eWeLink] Found 0 group(s)
homebridge_1  | [5/3/2020, 6:07:58 PM] Loading 1 accessories...
homebridge_1  | [5/3/2020, 6:07:58 PM] [eWeLink] Sonoff USB CH 1 Configure Accessory
homebridge_1  | [5/3/2020, 6:07:58 PM] [eWeLink] Sonoff USB CH 2 Configure Accessory
homebridge_1  | [5/3/2020, 6:07:58 PM] [eWeLink] Sonoff USB CH 3 Configure Accessory
homebridge_1  | [5/3/2020, 6:07:58 PM] [eWeLink] Sonoff USB CH 4 Configure Accessory
homebridge_1  | [5/3/2020, 6:07:58 PM] [eWeLink] Sonoff USB CH 1 Configure Accessory
homebridge_1  | [5/3/2020, 6:07:59 PM] Error: Cannot add a bridged Accessory with the same UUID as another bridged Accessory: 94c4a029-f9d6-4177-9e2d-73c673df4fd8
homebridge_1  |     at Bridge.Accessory._this.addBridgedAccessory (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:413:15)
homebridge_1  |     at /usr/local/lib/node_modules/homebridge/src/server.ts:308:19
homebridge_1  |     at Array.filter (<anonymous>)
homebridge_1  |     at Server.restoreCachedPlatformAccessories (/usr/local/lib/node_modules/homebridge/src/server.ts:268:69)
homebridge_1  |     at Server.start (/usr/local/lib/node_modules/homebridge/src/server.ts:156:10)
homebridge_1  |     at cli (/usr/local/lib/node_modules/homebridge/src/cli.ts:78:10)
homebridge_1  |     at Object.<anonymous> (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22)
homebridge_1  |     at Module._compile (internal/modules/cjs/loader.js:1156:30)
homebridge_1  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
homebridge_1  |     at Module.load (internal/modules/cjs/loader.js:1000:32)
homebridge_1  |     at Function.Module._load (internal/modules/cjs/loader.js:899:14)
homebridge_1  |     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
homebridge_1  |     at internal/main/run_main_module.js:18:47
sunkee30 commented 4 years ago

I thing it need to use back ewelink app to rename all your device in different name before you start your homebridge. If you start once before rename, you also need to clear "cachedAccessories" before you start homebridge again.

howanghk commented 4 years ago

Hi all, the issue should be fixed in the latest version 0.1.21, please update and try again.

npm install -g homebridge-ewelink-max@latest

You may also need to clear existing accessories cache (remove the accessories directory in homebridge folder).