AMoo-Miki / homebridge-tuya-lan

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

Tuya Garage door opener #53

Open jchristianj opened 5 years ago

jchristianj commented 5 years ago

Hi! I'm about to purchase this garage door opener: https://www.amazon.com/dp/B07GGRCH23/ref=cm_sw_em_r_mt_dp_U_ea58CbW6D87JX

Will it be possible to add it to Homekit by Homebridge and your plugin on my Raspberry pi? Main point is, I would like to have it shown as a garage door in Homekit, not as a switch. It should indicate feedback of the door (open/closed) in the icon as well. Can you confirm it will be working like this?

Thanks and regards, Christian

rangerek commented 5 years ago

therte is already a thread for garage door opener here

jchristianj commented 5 years ago

Sorry, was not aware that this is the same device. Anyhow, the thread ist stuck 2 months ago. Any progress on this?

AMoo-Miki commented 4 years ago

Please give the latest rc release a shot by doing npm i -g homebridge-tuya-lan@rc. The documentation has been updated for all the new devices released with v1.4.0; please refer to the Supported Devices page.

The Setup Instructions have changed in case you need to obtain a fresh id and key.

unvalider commented 4 years ago

Hi,

I have configured and installed the latest release for this plugin in homebridge but I am hitting the following error continuously, any advice on what I am doing so wrong would be appreciated.

[TuyaAccessory] Socket had a problem and will reconnect to Garage Door (Error: ERR_PING_TIMED_OUT). This is common for v3.3 devices.

AMoo-Miki commented 4 years ago

If the device works, the ping timeout is not that important. Does it work?

AMoo-Miki commented 4 years ago

@jchristianj, my own garage door opener shows up as a garage door with Homekit's animation and everything. Having it as a switch would be so ugly.

unvalider commented 4 years ago

@AMoo-Miki , thanks for the reply. The garage door opener does not work. I've tested ping from shell and it takes 200ms first try, then drops to 10ms, so network shouldn't be an issue.

The controller does work from the native Tuya app, but not via homebridge.

AMoo-Miki commented 4 years ago

The ping timeout is different from the ping you checked; it is a Tuya thing. Add `"pingTimeout": 3600 to prevent the socket from timing out.

Also make sure that the Tuya app is not running on your phone as that will block the device from talking to this plugin.

Do you see anything in the logs that Ready to handle ... with signature? What is the signature?

unvalider commented 4 years ago

2019-09-07 06:02:53,stdout,"[9/7/2019, 6:02:53 AM] [TuyaLan] Ready to handle Garage Door (GarageDoor:3.3) with signature {\"7\":0}

I haven't had any matching logs in the last hour current time being 7:44 am (UTC).

I have completely uninstalled the Tuya app from my phone after getting the ID and keys.

AMoo-Miki commented 4 years ago

This is great.

Add this to your config file for this device: "dpAction": 7 and give it a shot.

unvalider commented 4 years ago

After applying changes to the config.json, and restarting the docker container, I get the following error: [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. Current config.json contents (related to this device) "platform": "TuyaLan", "devices": [{ "name": "Garage Door", "type": "GarageDoor", "manufacturer": "Tuya", "model": "Garage Opener", "id": "<< removed >>", "key": " << removed >>", "version": "3.3", "dpaction": 7, "pingTimeout": 3600 }]

Spotted I'd mistyped dpAction as dpaction. Fixed and trying again.

AMoo-Miki commented 4 years ago

You are better off without the version in the config unless you know your device is indeed a 3.3. The plugin figures this out for itself. If your device is really a 3.1, having the 3.3 could explain the ping timeouts and it could prevent the plugin from communicating correctly.

AMoo-Miki commented 4 years ago

I deleted your message because it had your key in it. Are you able to control the door now?

unvalider commented 4 years ago

Fixed: JSON section now reads; "platforms": [{ "platform": "TuyaLan", "devices": [{ "name": "Garage Door", "type": "GarageDoor", "manufacturer": "Tuya", "model": "Garage Opener", "id": "<< removed >>", "key": "<< removed >>", "dpAction": 7, "pingTimeout": 3600 Still receiving error message: [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices.

AMoo-Miki commented 4 years ago

ECONNRESET is normal; ignore it.

Do you see the signature line? Can you open the Home app and try to open the garage door? When you do, what messages do you see in the log?

unvalider commented 4 years ago

No change. Device is now showing in HomeKit with a red Open state - and not responding to change state actions.

AMoo-Miki commented 4 years ago

Do you see any messages in the log?

unvalider commented 4 years ago

After container restart, had the following log messages:

`2019-09-07 08:03:48,stdout,"[9/7/2019, 8:03:48 AM] [TuyaLan] Discovered Garage Door ( << id >> ) identified as GarageDoor (3.3)

2019-09-07 08:03:48,stdout,"[9/7/2019, 8:03:48 AM] [TuyaLan] Connected to Garage Door "

2019-09-07 08:04:24,stdout,[TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. `

AMoo-Miki commented 4 years ago

No Ready to handle ... with signature message?

PS, id is not important, key is the one you need to hide.

unvalider commented 4 years ago

Nothing in the logs, this is the most recent records. Just thought I'd double-check that it's even a compatible device, this is the device I purchased: https://s.click.aliexpress.com/e/LBsAra0g

Screen Shot 2019-09-07 at 6 15 27 pm

Terminal only has the ECONNRESET records, nothing else is tagged [TuyaAccessories] or [TuyaLan]

AMoo-Miki commented 4 years ago

Without the Tuya app, how do you control the device?

unvalider commented 4 years ago

My HomeBridge links to HomeKit for control. For testing purposes I removed the app to cut over to HomeKit; I haven't had issues using the device in the Tuya app.

AMoo-Miki commented 4 years ago

Gotcha. When you said you uninstalled the Tuya app, I thought maybe you had a different one. Still thinking :)

AMoo-Miki commented 4 years ago

That line that says Discovered ... can you check the entire line. Also, can you update to the latest rc release as it has some additional logging.

unvalider commented 4 years ago

Discovered line: [9/7/2019, 8:30:28 AM] [TuyaLan] Discovered Garage Door (30302582840d8e79a346) identified as GarageDoor (3.3)

Was on homebridge-tuya-lan v1.5.0-rc.3, just updated to rc.5.

Restarting now, will advise status.

AMoo-Miki commented 4 years ago

I just pushed another rc (v1.5.0-rc.6) with one extra log message. Can you please try that?

How are you powering the device? Can you power cycle it?

unvalider commented 4 years ago

Updated to rc6.

Logs: [9/7/2019, 8:44:48 AM] [TuyaLan] Discovered Garage Door (30302582840d8e79a346) identified as GarageDoor (3.3) [9/7/2019, 8:44:48 AM] [TuyaLan] Connected to Garage Door [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3)

Physically disconnecting from AC and reconnecting. Will attempt power-cycle now.

AMoo-Miki commented 4 years ago

Something odd is happening here. This device gave us the signature before and now it is refusing to give it to us.

unvalider commented 4 years ago

`[9/7/2019, 8:51:02 AM] Loaded plugin: homebridge-tuya-lan [9/7/2019, 8:51:02 AM] Registering platform 'homebridge-tuya-lan.TuyaLan' [9/7/2019, 8:51:02 AM] --- [9/7/2019, 8:51:02 AM] Loading 4 platforms... [9/7/2019, 8:51:02 AM] [TuyaLan] Initializing TuyaLan platform... [9/7/2019, 8:51:02 AM] [TuyaLan] Marked Garage Door unreachable by faulting Service.Garage Door.Target Door State [9/7/2019, 8:51:02 AM] [TuyaLan] Starting discovery... [TuyaDiscovery] Discovery started on port 6666. [TuyaDiscovery] Discovery started on port 6667. Setup Payload: X-HM://0023ISYWY6N8L Scan this code with your HomeKit app on your iOS device to pair with Homebridge: Or enter this code with your HomeKit app on your iOS device to pair with Homebridge:

┌────────────┐     
│ removed │     
└────────────┘     

[9/7/2019, 8:51:04 AM] Homebridge is running on port 51758. [9/7/2019, 8:51:05 AM] [TuyaLan] Discovered Garage Door (30302582840d8e79a346) identified as GarageDoor (3.3) [9/7/2019, 8:51:05 AM] [TuyaLan] Connected to Garage Door [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3) `

AMoo-Miki commented 4 years ago

Can you try to re-get the id and key to see if it might have changed? The device is kicking us out as soon as we send the first query which could be due to a bad key. I have heard of devices changing keys in certain conditions.

unvalider commented 4 years ago

Yep, re-installing the app now and connecting in.

unvalider commented 4 years ago

ID and key found via tuyapi cli are unchanged and match config.json.

Additionally, running the Tuya app to change status - the status changes are reflected in HomeKit - so HomeKit is reacting to changes, just changes in HomeKit i.e. open / close controller are not being sent back to the device.

AMoo-Miki commented 4 years ago

~... and I know why!~

unvalider commented 4 years ago

With Tuya App open [9/7/2019, 9:02:16 AM] Homebridge is running on port 51758. [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3) [9/7/2019, 9:03:12 AM] [TuyaLan] Ready to handle Garage Door (GarageDoor:3.3) with signature {"1":true} [TuyaAccessory] GarageDoor changed: {"1":true,"101":true} [TuyaAccessory] GarageDoor changed: {"1":false,"101":true} [TuyaAccessory] GarageDoor changed: {"1":true,"101":true} [TuyaAccessory] GarageDoor changed: {"1":false,"101":true} [TuyaAccessory] GarageDoor changed: {"1":true,"101":true} [TuyaAccessory] GarageDoor changed: {"1":false,"101":true} [TuyaAccessory] GarageDoor changed: {"1":true,"101":true} [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] GarageDoor changed: {"1":true,"101":false} [TuyaAccessory] GarageDoor changed: {"1":false,"101":false} [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] Sending Garage Door {"7":true} [TuyaAccessory] Sending Garage Door {"7":true} [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] Sending Garage Door {"7":true} [TuyaAccessory] Sending Garage Door {"7":false} [TuyaAccessory] Sending Garage Door {"7":true} [TuyaAccessory] Sending Garage Door {"7":false}

unvalider commented 4 years ago

with tuya app closed [9/7/2019, 9:12:25 AM] Homebridge is running on port 51758. [9/7/2019, 9:12:25 AM] [TuyaLan] Discovered Garage Door (30302582840d8e79a346) identified as GarageDoor (3.3) [9/7/2019, 9:12:25 AM] [TuyaLan] Connected to Garage Door [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3) [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET). This is common for v3.3 devices. [TuyaAccessory] Sending first query Garage Door (3.3)

AMoo-Miki commented 4 years ago

Wait... wasn't the signature 7 before? it is back to 1 now. Please remove the dpAction from the config.

The signature changed completely, we have a 101 now too.

unvalider commented 4 years ago

Removed dpAction; restarted docker.

Not knowing a whole lot about the internal workings, my instincts point to 101 being an isClosed parameter, 1 may be an isActive parameter.

AMoo-Miki commented 4 years ago

Your instincts are correct: 1 is for triggering the action and 101 reports the sensor. The GarageDoor doesn't handle 101 right now because I haven't had someone to fix it with. How is the device acting now?

unvalider commented 4 years ago

I've played around with it a little, and if I have "flipState": true enabled - it sticks as Not Responding until I delete homebridge/accessories/cachedAccessories . If I remove "flipState" entirely, it remains in the red text Open state - and doesn't respond when activated from HomeKit.

Additionally, it's unresponsive from HomeKit directly - using the webUI doesn't activate the controller either.

AMoo-Miki commented 4 years ago

Do you see a didn't respond with its current state in the logs?

unvalider commented 4 years ago

I don't, I do see [9/7/2019, 9:31:57 AM] [TuyaLan] Marked Garage Door unreachable by faulting Service.Garage Door.Target Door State ~~when flipState is true.

At approximately the same point in the boot cycle, I get the message [9/7/2019, 9:36:20 AM] [TuyaLan] Discovered Garage Door (30302582840d8e79a346) identified as GarageDoor (3.3) when flipState is false or removed.~~

AMoo-Miki commented 4 years ago

When the plugin starts, it marks everyone unreachable until it discovers, connects, and talks to the devices.

I just found the cause of all those connection drops and pushed a new rc. While you update to that, i will draft our current state so you can tell me if my understanding is correct.

  1. We have confirmed 1 is the correct dp. That 7 was the device being confused (which I am heard happens).
  2. The plugin succeeds in discovery
  3. The plugin connects
  4. The plugin sends the handshake: Sending first query but never hears back, either because the connection was terminated or the device simply doesn't like us enough to reply.
unvalider commented 4 years ago

Up to rc7, Restarting now.

unvalider commented 4 years ago

Device is in Not Responding state in HomeKit.

No change to status in HomeKit or HomeBridge webUI.

[9/7/2019, 9:44:40 AM] [TuyaLan] Discovered Garage Door (30302582840d8e79a346) identified as GarageDoor (3.3) [9/7/2019, 9:44:40 AM] [TuyaLan] Connected to Garage Door [TuyaAccessory] Sending first query to Garage Door (3.3) [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET) [TuyaAccessory] Sending first query to Garage Door (3.3)

AMoo-Miki commented 4 years ago

Okay, so this device is forcing a disconnection on handshake. Add "intro": false to your config; I want to see if that will stop the connection resets. Please note that there are no quotes around false.

unvalider commented 4 years ago

"devices": [ { "intro": false, "name": "Garage Door", "type": "GarageDoor", "manufacturer": "Tuya", "model": "Garage Opener", "id": "30302582840d8e79a346", "key": " << removed >>", "flipState": true, "pingTimeout": 3600 ...

AMoo-Miki commented 4 years ago

Get rid of flipState for now. pingTimeout is also not needed anymore. I don't expect any real change now:

  1. The device will be accessible in the Home app (but it will not show its status correctly)
  2. I am hoping ECONNRESET won't show up any more.
unvalider commented 4 years ago

"devices": [ { "intro": false, "name": "Garage Door", "type": "GarageDoor", "manufacturer": "Tuya", "model": "Garage Opener", "id": "30302582840d8e79a346", "key": "<< removed >>" } ]

AMoo-Miki commented 4 years ago

Config is good. How does the device act?

unvalider commented 4 years ago

Device didn't react - but the logs are now showing more information on status changes from iOS

logs [9/7/2019, 9:54:00 AM] [TuyaLan] Connected to Garage Door [9/7/2019, 9:54:00 AM] [TuyaLan] Ready to handle Garage Door (GarageDoor:3.3) with signature {} [TuyaAccessory] Sending first query to Garage Door (3.3) [TuyaAccessory] Sending Garage Door {"1":true} [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (ECONNRESET) [TuyaAccessory] GarageDoor changed: {} [TuyaAccessory] Sending first query to Garage Door (3.3) [TuyaAccessory] Sending Garage Door {"1":true} [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (Error: ERR_PING_TIMED_OUT) [TuyaAccessory] GarageDoor changed: {} [TuyaAccessory] Sending first query to Garage Door (3.3) [TuyaAccessory] Sending Garage Door {"1":true} [TuyaAccessory] Socket had a problem and will reconnect to Garage Door (Error: ERR_PING_TIMED_OUT) [TuyaAccessory] GarageDoor changed: {} [TuyaAccessory] Sending first query to Garage Door (3.3)