AMoo-Miki / homebridge-tuya-lan

Homebridge plugin for IoT devices that use Tuya Smart's platform
MIT License
204 stars 52 forks source link

'No Response' from Raspberry Pi Zero W. #25

Closed joshroys closed 5 years ago

joshroys commented 5 years ago

Hey there,

I've been using the homebridge-tuya-lan plugin for Homebridge on my MacOS computer and it was working like a charm. In order to run it 24/7 more efficiently, I purchased a Raspberry Pi Zero W to install the software on.

I followed the instructions online to install Homebridge and the homebridge-tuya-lan plugin. The devices all appear to be connecting properly but when adding them to Home on my phone, I get 'No Response'.

Screenshot 2019-03-09 at 00 19 54 image0

I am using the correct IDs and Keys for the devices.

Would we be able to fix this?

Thank you!

macjbraun commented 5 years ago

I’m having a similar problem. I had been fine on a Pi 3 and decided to go with a Pi zero. When homebridge starts it marks all 4 of my outlets as unreachable as per the homebridge log. If I change state using homebridge-config-ui-x or the SmartLife app or power cycle them the plugs start responding in homebridge. I had to install a different version of node for the zero. https://www.thepolyglotdeveloper.com/2018/03/install-nodejs-raspberry-pi-zero-w-nodesource/

joshroys commented 5 years ago

Which version did you end up using on the Pi Zero, macjbraun?

macjbraun commented 5 years ago

v9.7.1

Sent from my iPhone

On Mar 10, 2019, at 4:01 PM, joshroys notifications@github.com wrote:

Which version did you end up using on the Pi Zero, macjbraun?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

joshroys commented 5 years ago

Alright, thanks. I’ll try it when I’m home.

macjbraun commented 5 years ago

The node version didn’t fix the issue. I was just noting the configuration difference between the pi 2 and the pi zero.

joshroys commented 5 years ago

Ah, okay. Sorry I misunderstood you there.

I don’t really know if it’s a problem with the plugin or we’re missing something out maybe?

AMoo-Miki commented 5 years ago

The plugin marks the device as unreachable as soon as Homebridge starts up. It will remove that unreachable flag only after it actually makes contact with your device and is ready to handle it.

This is how the log of a healthy setup would look like:

Registering platform 'homebridge-tuya-lan.TuyaLan
[TuyaLan] Initializing TuyaLan platform...
[TuyaLan] Marked Front Door Light 1 unreachable by faulting Service.Front Door Light 1.On
[TuyaLan] Starting discovery...
[TuyaAccessory] Discovery started.
[TuyaLan] Discovered Front Door Light 1 (02200193ecfadc8c8b47)
[TuyaLan] Connected to Front Door Light 1
[TuyaLan] Ready to handle Front Door Light 1 with signature {"1":false,"2":0}

The logging info can be overwhelming so add | grep -i tuya to the end of whatever you use to see your Homebridge logs; for me it is sudo journalctl -f -n 3000 -u homebridge | grep -i tuya. Compare your logs with mine from above and lemme know what is not happening; with that info, I will be able to find a solution for this problem.

Good luck.

macjbraun commented 5 years ago

~ $ sudo journalctl -f -n 3000 -u homebridge | grep -i tuya Mar 12 21:00:20 pi2 homebridge[1410]: [2019-3-12 21:00:20] [TuyaLan] Ready to handle Plug 1 with signature {"1":true,"2":0} Mar 13 09:32:30 pi2 homebridge[1410]: [TuyaAccessory] Sending Plug 2 {"1":true} Mar 13 18:18:09 pi2 homebridge[4306]: [2019-3-13 18:18:09] Loaded plugin: homebridge-tuya-lan Mar 13 18:18:09 pi2 homebridge[4306]: [2019-3-13 18:18:09] Registering platform 'homebridge-tuya-lan.TuyaLan' Mar 13 18:18:09 pi2 homebridge[4306]: [2019-3-13 18:18:09] [TuyaLan] Initializing TuyaLan platform... Mar 13 18:18:09 pi2 homebridge[4306]: [2019-3-13 18:18:09] [TuyaLan] Marked Plug 3 unreachable by faulting Service.Plug 3.On Mar 13 18:18:09 pi2 homebridge[4306]: [2019-3-13 18:18:09] [TuyaLan] Marked Plug 1 unreachable by faulting Service.Plug 1.On Mar 13 18:18:09 pi2 homebridge[4306]: [2019-3-13 18:18:09] [TuyaLan] Marked Plug 2 unreachable by faulting Service.Plug 2.On Mar 13 18:18:09 pi2 homebridge[4306]: [2019-3-13 18:18:09] [TuyaLan] Marked Plug 4 unreachable by faulting Service.Plug 4.On Mar 13 18:18:11 pi2 homebridge[4306]: [2019-3-13 18:18:11] [TuyaLan] Starting discovery... Mar 13 18:18:12 pi2 homebridge[4306]: [TuyaAccessory] Discovery started. Mar 13 18:18:14 pi2 homebridge[4306]: [2019-3-13 18:18:14] [TuyaLan] Discovered Plug 3 (06200046dc4f2236ff94) Mar 13 18:18:14 pi2 homebridge[4306]: [2019-3-13 18:18:14] [TuyaLan] Discovered Plug 1 (06200046bcddc2ea1337) Mar 13 18:18:14 pi2 homebridge[4306]: [2019-3-13 18:18:14] [TuyaLan] Discovered a device that has not been configured yet (eb19f9984f51da9a44mahl). Mar 13 18:18:15 pi2 homebridge[4306]: [TuyaAccessory] Closed connection with Plug 1 Mar 13 18:18:15 pi2 homebridge[4306]: [TuyaAccessory] Closed connection with Plug 3 Mar 13 18:18:15 pi2 homebridge[4306]: [2019-3-13 18:18:15] [TuyaLan] Connected to Plug 3 Mar 13 18:18:15 pi2 homebridge[4306]: [2019-3-13 18:18:15] [TuyaLan] Connected to Plug 1 Mar 13 18:18:15 pi2 homebridge[4306]: [2019-3-13 18:18:15] [TuyaLan] Discovered Plug 4 (06200046dc4f22370dfa) Mar 13 18:18:15 pi2 homebridge[4306]: [TuyaAccessory] Closed connection with Plug 4 Mar 13 18:18:15 pi2 homebridge[4306]: [2019-3-13 18:18:15] [TuyaLan] Connected to Plug 4 Mar 13 18:18:15 pi2 homebridge[4306]: [2019-3-13 18:18:15] [TuyaLan] Discovered Plug 2 (06200046dc4f22370de3) Mar 13 18:18:15 pi2 homebridge[4306]: [TuyaAccessory] Discovery ended. Mar 13 18:18:15 pi2 homebridge[4306]: [TuyaAccessory] Closed connection with Plug 2 Mar 13 18:18:15 pi2 homebridge[4306]: [2019-3-13 18:18:15] [TuyaLan] Connected to Plug 2

Sent from my iPhone

On Mar 13, 2019, at 4:45 PM, Miki notifications@github.com wrote:

sudo journalctl -f -n 3000 -u homebridge | grep -i tuya

AMoo-Miki commented 5 years ago

I have just created an ability to skip the greetings stage and enter a device into a usable state. Please update the plugin with npm i -g AMoo-Miki/homebridge-tuya-lan. Then add a parameter to your device's config as "intro": false and restart Homebridge.

While this would force a device to register with Homebridge, I am not happy with its side effects (not getting correct initial values). I have added some extra logging to see why things are not working the way they should. Please look at your logs for [TuyaLan] Connected to ...; with the new code changes, immediately after that, you should see a few [TuyaAccessory] Message from ..... Please paste the first 2-3 of them. Mine looked like this:

[TuyaAccessory] Message from Front Door Light 1: {"cmd":10,"data":{"devId":"02200093ecfabc8c3b74","dps":{"1":false,"2":0}}}
...
...
[TuyaAccessory] Message from Front Door Light 1: {"cmd":8,"data":"3.1d3ad1071a029c027A1nFOq7/kSeRrE9az89+TH3JwXJebIuyJnrl+brGhj3H9Pqc2YlycYtgDPinNKTpXm99b9rz8rd2PjQPYA/12BzM8xW2CHADWPuMtkb7miY="}
macjbraun commented 5 years ago

It is working now. Mar 14 07:30:48 pi2 homebridge[1053]: [TuyaAccessory] Message from Plug 3: {"cmd":10,"data":{"devId":"06200046dc4f2236ff94","dps":{"1":true,"2":0}}} Mar 14 07:30:49 pi2 homebridge[1053]: [TuyaAccessory] Message from Plug 2: {"cmd":10,"data":{"devId":"06200046dc4f22370de3","dps":{"1":true,"2":0}}}

I have noticed that I am not getting this message anymore [TuyaLan] Discovered a device that has not been configured yet (eb19f9984f51da9a44mahl).

I am very pleased with this plugin. I bought 4 of these TUYA devices and I’m happy I can control my ECO plugs and my Arduino devices along with Homekit compatible devices in one app.

macjbraun commented 5 years ago

Here is debug after operating one. Mar 14 07:50:23 pi2 homebridge[1053]: [TuyaAccessory] Sending Plug 1 {"1":true} Mar 14 07:50:23 pi2 homebridge[1053]: [TuyaAccessory] Message from Plug 1: {"cmd":7,"data":""} Mar 14 07:50:23 pi2 homebridge[1053]: [TuyaAccessory] Message from Plug 1: {"cmd":8,"data":"3.1a16989a05676ada8v3/S5d5m2T4n0RJQF/mdFoSwFQ1rvFNsROGWMU/088Ez2nLC7jCLLl1mioC0kUhOCX57PEj9JqDUOytgymlUdocpn4hF2G5Xl5kaY9u5NkI="}

joshroys commented 5 years ago

I added "intro": false to the config and it still doesn't work. I don't see the 'Message from'.

[2019-3-14 18:21:06] [TuyaLan] Discovered Desk Strip (51751206b4e62d4b2739)
[2019-3-14 18:21:06] [TuyaLan] Connected to Desk Strip
[2019-3-14 18:21:07] [TuyaLan] Discovered Ceiling Light (80058244cc50e3c5aa1a)
[2019-3-14 18:21:07] [TuyaLan] Discovered Bed Strip (51751206b4e62d4b2743)
[TuyaAccessory] Discovery ended.
[2019-3-14 18:21:07] [TuyaLan] Connected to Ceiling Light
[2019-3-14 18:21:07] [TuyaLan] Connected to Bed Strip
joshroys commented 5 years ago

I'm now getting this error:

[2019-3-14 18:46:46] [TuyaLan] Ready to handle Ceiling Light with signature {}
HAP Warning: Characteristic 00000008-0000-1000-8000-0026BB765291 not in required or optional characteristics for service 00000043-0000-1000-8000-0026BB765291. Adding anyway.
/usr/local/lib/node_modules/homebridge-tuya-lan/lib/BaseAccessory.js:153
        const [, h, s, b] = value.match(/^.{6}([0-9a-f]{4})([0-9a-f]{2})([0-9a-f]{2})$/i) || [0, 255, 255];
                                  ^

TypeError: Cannot read property 'match' of undefined
    at RGBTWLightAccessory.convertColorFromTuyaToHomeKit (/usr/local/lib/node_modules/homebridge-tuya-lan/lib/BaseAccessory.js:153:35)
    at RGBTWLightAccessory._registerCharacteristics (/usr/local/lib/node_modules/homebridge-tuya-lan/lib/RGBTWLightAccessory.js:32:106)
    at TuyaAccessory.BaseAccessory.device.once (/usr/local/lib/node_modules/homebridge-tuya-lan/lib/BaseAccessory.js:22:18)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at TuyaAccessory.emit (events.js:214:7)
    at Socket._socket.on (/usr/local/lib/node_modules/homebridge-tuya-lan/lib/TuyaAccessory.js:93:22)
    at emitNone (events.js:111:20)
    at Socket.emit (events.js:208:7)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1173:10)

Is there something wrong with my configuration file?

joshroys commented 5 years ago

Any updates with this, @AMoo-Miki?

AMoo-Miki commented 5 years ago

@macjbraun, I am glad things are working for you.

@joshroys, that HAP warning is troubling; that message shouldn't appear at all but since it is a warning, let's worry about that later. Please update the plugin with npm i -g AMoo-Miki/homebridge-tuya-lan and restart Homebridge. I have fixed an issue caused by skipping intro which was throwing that match error for you.

joshroys commented 5 years ago

I am now using an old laptop since I found another use for my Raspberry Pi and it is all working now. I did have to use the "intro": false parameter, however.

Thanks for the help!