iRayanKhan / homebridge-tuya

A Homebridge plugin to control Tuya devices locally.
MIT License
394 stars 164 forks source link

Can’t get WiFi breakers to work #39

Closed hajopaj closed 4 years ago

hajopaj commented 5 years ago

Has anyone have any experience with these tuya WiFi breakers?

img_0185

I’m getting a "no answer" in my home app on iOS while all my other devices are working fine and all ip’s and keys and addresses match the devices they should...

Config.json looks like this:

{ "accessories" : [ ], "bridge" : { "username" : "CD:22:3D:E3:CE:41", "name" : "Homebridge", "pin" : "031-45-788", "port" : 0 }, "platforms" : [ { "platform" : "TuyaPlatform", "name" : "TuyaPlatform", "devices" : [ { "id" : "84622486600194ae6499", "key" : "287f539b98a61de5", "name" : "Stehlampe alt", "ip" : "192.168.178.63" }, { "id" : "84622486600194ae77fd", "key" : "877649743c5ef828", "name" : "Lampe Box", "ip" : "192.168.178.22" }, { "id" : "0620012384f3eba64ea4", "key" : "7feaf531a4b4a9f8", "name" : "Schreibtischlampe", "ip" : "192.168.178.68" }, { "id" : "06200123ecfabc1c5cac", "key" : "f1104e9dca4760e9", "name" : "Drucker", "ip" : "192.168.178.35" }, { "id" : "06200123ecfabc1cb3f7", "key" : "31b77d11376b142a", "name" : "Wickeltisch Lampe", "ip" : "192.168.178.26" }, { "id" : "06200123ecfabc1cb870", "key" : "1719e1a50573c547", "name" : "Stehlampe", "ip" : "192.168.178.23" }, { "id" : "6cf5b5422dac85e2eb21ux", "key" : "847c690b0a6c37c2", "name" : "Esszimmertisch 1", "ip" : "192.168.178.31" }, { "id" : "6ca0fa68a6c570c1dasyfh", "key" : "f03e19f644e5ae4c", "name" : "Esszimmertisch 2", "ip" : "192.168.178.32" } ] } ] } <<<

The last two devices are the ones not responding. I added "type" : "generic" to both of them but still no change

Anyone can help?

codetheweb commented 5 years ago

I assume they work correctly with the app?

Are you able to ping those IP addresses from the machine running Homebridge?

hajopaj commented 5 years ago

Yes, they work correctly with the app and I can ping both devices without any losses

codetheweb commented 5 years ago

What's the output of DEBUG=* homebridge when you toggle the unresponsive devices a few times?

hajopaj commented 5 years ago

img_0186 First this

hajopaj commented 5 years ago

img_0187 Then that

codetheweb commented 5 years ago

Gave it a quick search and I don't think the error is this plugin's fault. People have suggested changing parameters on avahi as well as making sure that there's not an orphan Homebridge process running from the same config folder on the same host.

You may also want to try deleting the persist/ and accessories/ folders in your Homebridge config location.

hajopaj commented 5 years ago

I tried changing the cache size in Avahi and deleting both folders. Afterwards I got a "no answer" from all of my devices in home app and still could not toggle the devices although they are displayed (but also always were) in my Homebridge-config-ui.

hajopaj commented 5 years ago

Debug is the same as before...

codetheweb commented 5 years ago

I'm sorry, but if you're still getting the same error in the first screenshot I can't help as it's more a Homebridge problem. You may want to open an issue here.

hajopaj commented 5 years ago

I did some more "research" and I noticed that in the sharedprefs data in Nox there is a difference in the "dps" parts of the preferences.xml file. For the not working switches it says:

"dps": {"1":false,"101":"0","102":0}

and for all the working ones it says:

"dps":{"1":false,"11":0}

Could it be that I just have to add some "options" and "dps" to config.json? - And if yes, any idea how are they supposed to look?

Seems kind of probable to me since debug says everything is working fine...

Am 21.01.2019 um 01:13 schrieb Max Isom notifications@github.com:

I'm sorry, but if you're still getting the same error in the first screenshot I can't help as it's more a Homebridge problem. You may want to open an issue here.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

codetheweb commented 5 years ago

As you're not getting an error that seems related to TuyAPI, I would be surprised if that was the problem.

You could try controlling your device with tuya-cli using the same parameters that are in your config.json. If that works, it's very unlikely that the source of problems is this plugin. If not, we'll have to do some more investigation.

hajopaj commented 5 years ago

img_0189 This is what I am getting from tuya-cli. The first device is one of the not responding ("no answer" in home app but working in tuya app) and the second is one working in both. When I use the set command with the not responding device I get this but nothing happens with the breaker. img_0190

codetheweb commented 5 years ago

It's possible you have the wrong key for your device, as data would then not be encoded or decoded correctly (so set and get both fail).

You might want to try acquiring the keys again. Are you doing it with tuya-cli list-app or some other method?

hajopaj commented 5 years ago

I checked again but I aquired the code with Tuya-cli and it seems to be right. As you can see in the second picture I was able to send the set command but nothing happened. I am sure I used the correct keys since I directly copied them out of Tuya-cli. No ideal why it won‘t switch anything...

Am 28.01.2019 um 02:00 schrieb Max Isom notifications@github.com:

It's possible you have the wrong key for your device, as data would then not be encoded or decoded correctly (so set and get both fail).

You might want to try acquiring the keys again. Are you doing it with tuya-cli list-app or some other method?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

codetheweb commented 5 years ago

Hmm... do you have other devices of the same model that work?

hajopaj commented 5 years ago

No I don’t have any other devices of that make. They don’t have a brand name as you can see on the picture but I thought if they run with tuya smart, I can make them run with Homebridge-tuya as well...

I also thought about flashing the devices with tasmota. - do you think that could make it work? I have to use another plugin as far as I understood or could they still work with Homebridge-tuya then?

Am 30.01.2019 um 00:04 schrieb Max Isom notifications@github.com:

Hmm... do you have other devices of the same model that work?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

codetheweb commented 5 years ago

If you flash them with tasmota (still an experimental process, I don't know much about it and haven't tried it myself), you'll have to use a different plugin as homebridge-tuya only supports devices with Tuya firmware.

hajopaj commented 5 years ago

Any other idea what else I could possibly do? Since I don‘t get any errors I don‘t know what to fix...

Am 30.01.2019 um 23:15 schrieb Max Isom notifications@github.com:

If you flash them with tasmota (still an experimental process, I don't know much about it and haven't tried it myself), you'll have to use a different plugin as homebridge-tuya only supports devices with Tuya firmware.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

codetheweb commented 5 years ago

Try running this (after modifying the parameters) with DEBUG=* node test.js and post the output:

const TuyAPI = require('tuyapi');

const device = new TuyAPI({
  id: 'xxxxxxxxxxxxxxxxxxxx',
  key: 'xxxxxxxxxxxxxxxx',
  ip: 'xxx.xxx.xxx.xxx'});

device.get({schema: true}).then(data => {
  console.log(data);
});
hajopaj commented 5 years ago

pi@raspberrypi:~ $ DEBUG=* node test.js internal/modules/cjs/loader.js:605 throw err; ^

Error: Cannot find module 'tuyapi' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15) at Function.Module._load (internal/modules/cjs/loader.js:529:25) at Module.require (internal/modules/cjs/loader.js:657:17) at require (internal/modules/cjs/helpers.js:20:18) at Object. (/home/pi/test.js:1:78) at Module._compile (internal/modules/cjs/loader.js:721:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10) at Module.load (internal/modules/cjs/loader.js:620:32) at tryModuleLoad (internal/modules/cjs/loader.js:560:12) at Function.Module._load (internal/modules/cjs/loader.js:552:3)

Am 31.01.2019 um 20:29 schrieb Max Isom notifications@github.com:

DEBUG=* node test.js

hajopaj commented 5 years ago

Do I have to run something else since I am using Homebridge with Raspbian?

Am 31.01.2019 um 20:29 schrieb Max Isom notifications@github.com:

Try running this (after modifying the parameters) with DEBUG=* node test.js and post the output:

const TuyAPI = require('tuyapi');

const device = new TuyAPI({ id: 'xxxxxxxxxxxxxxxxxxxx', key: 'xxxxxxxxxxxxxxxx', ip: 'xxx.xxx.xxx.xxx'});

device.get({schema: true}).then(data => { console.log(data); }); — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

codetheweb commented 5 years ago

Sorry, forgot to add that you'll need to install TuyAPI.

Do npm i tuyapi -g (or sudo npm i tuyapi -g) and try again.

hajopaj commented 5 years ago

Installed it and did a restart but I’m still getting the same error.

Am 01.02.2019 um 16:05 schrieb Max Isom notifications@github.com:

Sorry, forgot to add that you'll need to install TuyAPI.

Do npm i tuyapi -g (or sudo npm i tuyapi -g) and try again.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

codetheweb commented 5 years ago

Hmm, unless you changed your NPM configuration I think that should have worked.

You can also try installing it to your current directory with npm i tuyapi (without the -g flag).

hajopaj commented 5 years ago

Got this:

pi@raspberrypi:~ $ DEBUG=* node test.js TuyAPI Payload: { gwId: '6ca0fa68a6c570c1dasyfh', devId: '6ca0fa68a6c570c1dasyfh' } +0ms TuyAPI Send attempt 1 +24ms TuyAPI Sending this data: 000055aa000000000000000a0000004a7b2267774964223a2236636130666136386136633537306331646173796668222c226465764964223a2236636130666136386136633537306331646173796668227d000000000000aa55 +2ms TuyAPI Connect 192.168.178.32 +3ms TuyAPI Socket connected. +136ms TuyAPI Received data back: 192.168.178.32 +21ms TuyAPI 000055aa000000000000000a00000021000000016a736f6e206f626a206461746120756e76616c6964d25378690000aa55 +0ms TuyAPI decrypt 192.168.178.32 ¸Cš}õ:ɉ­ œÿ±Tzp L>!, 10 +8ms TuyAPI Disconnect +2ms (node:5928) UnhandledPromiseRejectionWarning: ¸Cš}õ:ɉ­ œÿ±Tzp L>!, (node:5928) 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:5928) [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. TuyAPI Socket closed: 192.168.178.32 +11ms pi@raspberrypi:~ $

Am 02.02.2019 um 19:43 schrieb Max Isom notifications@github.com:

Hmm, unless you changed your NPM configuration I think that should have worked.

You can also try installing it to your current directory with npm i tuyapi (without the -g flag).

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

codetheweb commented 5 years ago

Ok, your device is returning a packet that when translated into ASCII says json obj data unvalid.

The packet you're sending looks fine, so the next step would be for you to capture a session of app activity with Wireshark and send it to me so I can compare the packets TuyAPI is sending with the packets the app sends.

hajopaj commented 5 years ago

img_0191 img_0192 img_0193 img_0194 img_0195 img_0196 img_0197

hajopaj commented 5 years ago

I don’t know what you can read out of these... I used the capture filter "host 192.168.178.32" Is there a way to capture more packages as I’m noticing that these don’t change in any particular way?

codetheweb commented 5 years ago

Thanks for the screenshots, but they're all fundamentally the same packet the device is broadcasting to advertise its IP.

Try setting the filter to your phone's IP.

hajopaj commented 5 years ago

I’m sorry, but when I set the "host" filter to my iPhones ip and switch the breakers over the tuya app there is not anything to see in wireshark. I only get "HomeKit" stuff, nothing else. And literally nothing, no matter what I do with my phone...browsing, apps. Do I have to change something else with the filter?

codetheweb commented 5 years ago

You might be sniffing on the wrong interface. I think you need to be sniffing on a wireless interface that's connected to the same network your device is.

codetheweb commented 5 years ago

(I'm copy/pasting this into every open issue and PR.)

This plugin is now deprecated, as I don't have enough time to maintain it along with other TuyAPI related projects. Please use AMoo-Miki's homebridge-tuya-lan plugin instead. (Or, you can continue to use this plugin, but I will not be giving support or adding any new devices.)

I'm sorry about this, but this plugin is taking a disproportionate amount of my time that I believe is better spent making TuyAPI more stable and adding more tools to the ecosystem.

iRayanKhan commented 4 years ago

Closing; inactive thread. If you need support please re-open this issue.