codetheweb / homebridge-tuya-outlet

A plugin for Homebridge for Tuya-based outlets
15 stars 11 forks source link

Plugin can't load accesory #18

Closed stehof2 closed 6 years ago

stehof2 commented 6 years ago

Hi,

I hope someone can/will help me figure this out, I installed the Tuyapi and the plugin homebridge-tuya-outlet on my Raspberry.

I used Charles to sniff the connection, the first problem that I had here is that there is no connection found with a=s.m.dev.list in it, but when I looked into tuya.m.device.get I found the same parameters such as UUID, LocalKey, DevID etc.

I added:

{ "accessory": "TuyaOutlet", "name": "Tuya Outlet", "devId": "xxxxxxxxxxxxxxxxxxx", "localKey": "xxxxxxxxxxxxxxx" } to my config.json and launched HomeBridge, that gives me the following output:

(node:14663) UnhandledPromiseRejectionWarning: Error: resolveIds() timed out. Is the device ID correct and is the device powered on? at timeout (/usr/lib/node_modules/homebridge-tuya-outlet/node_modules/tuyapi/index.js:121:11) at Timeout.setTimeout [as _onTimeout] (/usr/lib/node_modules/homebridge-tuya-outlet/node_modules/p-timeout/index.js:19:13) at ontimeout (timers.js:498:11) at tryOnTimeout (timers.js:323:5) at Timer.listOnTimeout (timers.js:290:5) (node:14663) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:14663) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Should I search for another package in Charles with the parameters or is there somethin else wrong?

codetheweb commented 6 years ago

Documentation has not yet been updated, but currently the most reliable method of getting it to work is passing in a third parameter: the IP of the device. A config would look like this:

{ "accessory": "TuyaOutlet",
  "name": "Tuya Outlet",
  "devId": "xxxxxxxxxxxxxxxxxxx",
  "localKey": "xxxxxxxxxxxxxxx",
  "ip": "xxx.xxx.xxx.xxx" }
stehof2 commented 6 years ago

@codetheweb Thanks for the quick response, I will test it this evening and let you know the outcome ;-)

stehof2 commented 6 years ago

Well I tried to add the IP of the device found under SmartLife>Menu>Device Info, my config looks like this now:

{
    "bridge": {
        "name": "Thuis",
        "username": "1A:2B:3C:4D:5E:6F",
        "port": 51826,
        "pin": "003-09-217"
    },

    "description": "Test lamp",

    "accessories": [{
            "accessory": "TuyaOutlet",
        "name": "Tuya Outlet",
            "devId": "xxxxxxxxxxxxxxxxxxx",
            "localKey": "xxxxxxxxxxxxxxxxxxx",
        "ip": "94.210.121.217"
      }],

    "platforms": [{
        "platform": "eWeLink",
        "name": "eWeLink",
        "authenticationToken": "xxxxxxxxxxxxxxxxxxx",
        "apiHost": "eu-api.coolkit.cc:8080",
        "webSocketApi": "eu-pconnect3.coolkit.cc"
    }]
}

When I open the HomeKit app all devices of eWeLink as the Tuya outlet keeps saying that they are updating and eventually they get the red explanation mark with not responding...

Any ideas?

codetheweb commented 6 years ago

That appears to be your public IP.

You need to pass it the local IP of your device (it probably starts with 192. or 10.). The easiest way to find this is probably by running an IP scan with a tool like Angry IP Scanner. Then, try plugging in IPs whose hostname starts with ESP_ to your Homebridge config until it works.

stehof2 commented 6 years ago

Thanks again for your help, I found the right IP address, apparently I also found the wrong Local Key why it still didn't work till I filled out the right one, it's working now.

But I found a little point of improvement, it is working now from the HomeKit Apple app, you can turn it on, the on/off switch will change, but when you turn on or off the light by switching the touch button on the wall outlet itself, the homebridge doesn't get the command to set the toggle button in Homekit to on/off. Or is there a quick fix for? When I use the SmartLife app, then it's working correctly, I can also make an new issue if you like ;-)

I also like to say that you're doing a good job and I like to thank you for that ;-) !!

codetheweb commented 6 years ago

Yes, the issue you described above is caused by the outlet returning an encrypted status packet when someone has physically pushed the on/off button (normally status packets are unencrypted). This is a known issue over at tuyapi, so once it's fixed there it will also be fixed here.

Glad everything's working. :)

Milkman0 commented 6 years ago

@stehof2 where's the correct local key found? I have tried to grab it from Charles multiple times, but the key doesn't work for me I even tried loading the tuya app in a rooted Android emulator and extracted the key from there with the same result.

Milkman0 commented 6 years ago

nevermind. Something wrong with typed values. I had to use WinSCP the config.json and copy paste the text over to for it to work.

codetheweb commented 6 years ago

👍