iRayanKhan / homebridge-tuya

A Homebridge plugin to control Tuya devices locally.
MIT License
395 stars 165 forks source link

Outlet turns on then off #31

Closed AdmiralMichael closed 4 years ago

AdmiralMichael commented 5 years ago

I just recently purchase some CE Smart outlets from Costco and learned they are just Tuya rebrands. They work well with this plugin except for one intermittent quirk.

Sometimes when triggered the outlet with turn on the immediately turn off. So far this happens when activated with the Home app or Siri.

I currently run Homebridge in a docker container on an Ubuntu host. The plugs are in a separate vlan but my friend has the same intermittent issue and he doesn't use vlan, same outlets though. He runs homebridge in a docker container on Raspbian. I have them setup with DHCP reservations and have entered the IP in the config.json file.

Not sure where to go from here.

codetheweb commented 5 years ago

This has happened to me as well a few times, although I can't reproduce it with any consistency.

If you're able to reproduce it, please provide the logs around the time it happens (start Homebridge in debug mode with DEBUG=* homebridge).

I think it's probably a bug in TuyAPI, but not sure how to best track it down. Any suggestions are welcome.

AdmiralMichael commented 5 years ago

So I just ran into this issue and the only thing I can find in the log that relates to anything Tuya is

 [12/24/2018, 9:41:13 AM] [TuyaPlatform] [Tuya Smart Plug 2] On set
 [12/24/2018, 9:41:13 AM] [TuyaPlatform] [Tuya Smart Plug 3] On set
codetheweb commented 5 years ago

@AdmiralMichael it almost looks like Homebridge is asking for it to be switched on and off...

What's the context of those log lines? Anything above or below?

skullthug commented 5 years ago

I just recently finished setting these up on my Homebridge and have discovered this same issue as well. I'm using 2 different variations of Tuya rebrands I got off Amazon ages ago.

EDIT: Here's what the debug view spits out when I finish launching Homebridge and attempt to toggle one of the outlets

EventedHTTPServer [::ffff:192.168.1.251] HTTP request: /characteristics +20s HAPServer [CC:22:3D:E3:CE:30] HAP Request: PUT /characteristics +1ms Accessory [Homebridge] Processing characteristic set: [{"aid":21,"iid":10,"value":1}] +2ms Accessory [Homebridge] Setting Characteristic "On" to value 1 +0ms TuyAPI Payload: 192.168.1.53 +15s TuyAPI { devId: '00200465a020a62b75b5', TuyAPI uid: '', TuyAPI t: '1546400049', TuyAPI dps: { '1': true } } +1ms TuyAPI Send attempt 1 +21ms TuyAPI Sending this data: 000055aa000000000000000700000087332e31353934356561663762333231393937666c7554673575775a465273413259524e3741494634725359486d756351616e616235434e72596b4450732b4435434a45614b385663686c674557534c466963546279696e7430484e747851574c3047642f4776745a6279366552314c6954326378696c4554654641614d383d000000000000aa55 +3ms TuyAPI Connect 192.168.1.53 +2ms TuyAPI Socket connected. +75ms TuyAPI Error event from socket. 192.168.1.53 { Error: read ECONNRESET at TCP.onread (net.js:622:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' } +6ms TuyAPI Error event from socket. +3ms TuyAPI Socket closed: 192.168.1.53 +5ms TuyAPI Send attempt 2 +998ms TuyAPI Sending this data: 000055aa000000000000000700000087332e31353934356561663762333231393937666c7554673575775a465273413259524e3741494634725359486d756351616e616235434e72596b4450732b4435434a45614b385663686c674557534c466963546279696e7430484e747851574c3047642f4776745a6279366552314c6954326378696c4554654641614d383d000000000000aa55 +1ms TuyAPI Connect 192.168.1.53 +1ms TuyAPI Socket connected. +206ms TuyAPI Received data back: 192.168.1.53 +67ms TuyAPI 000055aa00000000000000070000000c00000000789370910000aa55 +0ms TuyAPI undefined 192.168.1.53 undefined 7 +2ms TuyAPI Disconnect +1ms EventedHTTPServer [::ffff:192.168.1.23] Sending HTTP event '21.10' with data: {"characteristics":[{"aid":21,"iid":10,"value":true}]} +1s EventedHTTPServer [::ffff:192.168.1.251] Muting event '21.10' notification for this connection since it originated here. +7ms EventedHTTPServer [::ffff:192.168.1.103] Sending HTTP event '21.10' with data: {"characteristics":[{"aid":21,"iid":10,"value":true}]} +1ms EventedHTTPServer [::ffff:192.168.1.251] HTTP Response is finished +6ms TuyAPI Socket closed: 192.168.1.53 +21ms

AdmiralMichael commented 5 years ago

I am going to have to recheck my log. The one I found isn’t that detailed. Where did u find that logfile? What’s the file name?

codetheweb commented 5 years ago

@AdmiralMichael you can get a detailed debug log with DEBUG=* homebridge.

@skullthug looks like it's having trouble communicating with your device; is anything else trying to access it in the background (other scripts, devices, etc)? I've found that the app itself usually needs to be force-quit.

AdmiralMichael commented 5 years ago

I thought I did that. I will have to check and report back.

skullthug commented 5 years ago

@codetheweb I think you might be right. I had disabled the tuya plugin after my post due to the issue, but decided to try it again one more time last night, and found it was more reliable. I'm assuming because Smart Life was probably not fully loaded on my phone, like it was during the previous time, and maybe not competing for control? ¯_(ツ)_/¯ That's my best theory so far.

twistedindustries commented 5 years ago

I just implemented this and I am getting the same issue sometimes. I've turned on logging and hopefully I can help. It only seems to happen after not using the device after awhile. Here is a log where 10.0.1.13 and 10.0.1.14 are both outlets told to turn off. 10.0.1.14 turned off as it should but 10.0.1.13 turned off and immediately turned back on.

EventedHTTPServer [::ffff:10.0.1.3] HTTP request: /characteristics +5s HAPServer [CC:11:3F:D3:AE:20] HAP Request: PUT /characteristics +0ms Accessory [Homebridge] Processing characteristic set: [{"aid":5,"iid":10,"value":false},{"aid":4,"iid":10,"value":false}] +0ms Accessory [Homebridge] Setting Characteristic "On" to value false +0ms TuyAPI Payload: 10.0.1.13 +5s TuyAPI { devId: '80881651840d8e538c10', TuyAPI uid: '', TuyAPI t: '1546893805', TuyAPI dps: { '1': false } } +0ms TuyAPI Send attempt 1 +0ms TuyAPI Sending this data: 000055aa000000000000000700000087332e31663439623436633030303736623334316449574a4d6344525850384f37464c71794b6c6f4f4756654d6637616e48366736413635684179596e796574637a2f474263384c73413574636b7a7131677666564e5861714e71303737696f6179583430746558345468794c51426d724d6231463363464e374d49414e383d000000000000aa55 +0ms TuyAPI Connect 10.0.1.13 +0ms Accessory [Homebridge] Setting Characteristic "On" to value false +0ms TuyAPI Payload: 10.0.1.14 +0ms TuyAPI { devId: '50642000840d8e5279ec', TuyAPI uid: '', TuyAPI t: '1546893805', TuyAPI dps: { '1': false } } +0ms TuyAPI Send attempt 1 +1ms TuyAPI Sending this data: 000055aa000000000000000700000087332e3139336264333632643934343537303738337a434a4536484b375a6d3066367277445458476544315233492f3661686d4163616e2b6a476d7479664f495630782f547371325373326664786f493733304d45684f6d4543435272755230443449774f69795335684835702f614a46756d42764f6c5763786e6c4658303d000000000000aa55 +0ms TuyAPI Connect 10.0.1.14 +0ms TuyAPI Socket connected. +103ms TuyAPI Socket connected. +1ms TuyAPI Received data back: 10.0.1.13 +57ms TuyAPI 000055aa00000000000000070000000c00000000789370910000aa55 +0ms TuyAPI undefined 10.0.1.13 undefined 7 +0ms TuyAPI Disconnect +0ms EventedHTTPServer [::ffff:10.0.1.8] Sending HTTP event '5.10' with data: {"characteristics":[{"aid":5,"iid":10,"value":false}]} +163ms EventedHTTPServer [::ffff:10.0.1.3] Muting event '5.10' notification for this connection since it originated here. +0ms TuyAPI Socket closed: 10.0.1.13 +1ms TuyAPI Received data back: 10.0.1.14 +0ms TuyAPI 000055aa00000000000000070000000c00000000789370910000aa55 +0ms TuyAPI undefined 10.0.1.14 undefined 7 +0ms TuyAPI Disconnect +0ms EventedHTTPServer [::ffff:10.0.1.8] Sending HTTP event '4.10' with data: {"characteristics":[{"aid":4,"iid":10,"value":false}]} +1ms EventedHTTPServer [::ffff:10.0.1.3] Muting event '4.10' notification for this connection since it originated here. +0ms EventedHTTPServer [::ffff:10.0.1.3] HTTP Response is finished +0ms TuyAPI Socket closed: 10.0.1.14 +1ms

twistedindustries commented 5 years ago

Testing with the cli I can confirm that this is more than likely a tuya-api issue. I am going to debug when I can and see if I can't find it.

twistedindustries commented 5 years ago

Another observation I've noticed that might be helpful is that the wifi connection to the device will get reset when this bug happens. I also noticed that opening the Home app seems to cause devices to lose their wifi connection where the Smart Life app doesn't seem to. Another note, the Smart Life app seems to block homebridge if opened.

AdmiralMichael commented 5 years ago

I've noticed some devices losing the wifi connection as well. Unfortunately I use these outlets for Christmas decorations so I don't really use them right now, other then just sitting plugged in (so I dont have to remove from home bridge or see no response error) its harder for me to see the bug.

I do have them part of a leave home scene and noticed some of the status LEDs turn off (no network connection) after its triggered. But I can't confirm it's doing the on/off bug. Just want to update on what I've noticed.

nitantsoni commented 5 years ago

I have a lot of similar issues with Homebridge and TuyaAPI. I am using the Tuya Powerstrips and they often reset when I turn ON/OFF things too quickly or sometimes just randomly.

Found this closed issue, which looks related - https://github.com/codetheweb/tuyapi/issues/84

For now I have just given up on Homekit support and will try to dig deeper, when I get the chance.

MrTomAsh commented 5 years ago

My Koogek Smart Plug randomly turns off and then back on again (about three times a day).

Sometimes when I leave it off it can turn on by random.

Looks like a similar issue.

codetheweb commented 5 years ago

I've been refactoring and slimming down TuyAPI in a branch here; hopefully this cleaner code will solve strange issues like this one.

twistedindustries commented 5 years ago

I've actually made a lot of head way as far as this issue goes by enabling persistent connections. I'm sure it's a bit hacky since I had to make a small change to the TuyaAPI code in the connect function changing this: this.emit('error', new Error('Error from socket')); to this: this.emit('disconnected'); or else I got errors.

Since doing that I've been running for days and haven't had any of the glitches show up on any device.

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.

9SL9 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.

Problem is you have updated your repo more recently than AMoo has his. Looks like we're out of luck for Tuya devices.

codetheweb commented 5 years ago

@9SL9 I recently updated the README with a link to a different project that's supposed to work well. You may want to try that instead.

iRayanKhan commented 4 years ago

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