make-all / tuya-local

Local support for Tuya devices in Home Assistant
MIT License
1.41k stars 542 forks source link

Fail to add Garza ITV103W #2443

Closed Fertx0 closed 3 weeks ago

Fertx0 commented 3 weeks ago

Description

When I try to add the Garza ITV103W device, HomeAssistant comes back with the message: "Unable to connect to your device with those details. It could be an intermittent issue, or they may be incorrect."

The log message reports: 2024-10-30 13:03:07.850 ERROR (MainThread) [custom_components.tuya_local.device] Failed to refresh device state for Test. 2024-10-30 13:04:39.079 WARNING (SyncWorker_4) [custom_components.tuya_local.device] Test protocol error 914: Check device key or version 2024-10-30 13:07:00.809 ERROR (MainThread) [custom_components.tuya_local.device] Failed to refresh device state for Test.

Steps to reproduce

  1. Install Tuya Local with HACS
  2. Reload
  3. Add Integration with Smart Life cloud-assisted device setup.
  4. Choose device: Smart Irrigation System - Choose gateway: Garza Smart Hub
  5. It finds the IP address, device id, local key, and sub device id. It is correct, double checked with platform.tuya.com and locally with python -m tinytuya
  6. After submit, it fails with the error

Expected behaviour

No response

Additional context

` homeassistant:/config# cat devices.json [ { "name": "Programador de Riego Wifi Garza", "id": "bfa64369996a901e49tvfn", "key": "XXXXXX", "mac": "", "category": "sfkzq", "product_name": "Smart irrigation systems", "product_id": "xnajzurgqo1ugohn", "biz_type": 0, "model": "401303", "sub": true, "icon": "https://images.tuyaeu.com/smart/icon/ay1530692932059RsnDv/a31dad76bed3999b3324e83d9abb4935.png", "uuid": "bfa64369996a901e49tvfn", "node_id": "AB1", "mapping": { "101": { <---> { "name": "Centro Inteligente Garza", "id": "bf72362a6f1f2ea9a3dvyq", "key": "XXXXX", "mac": "cc:8c:bf:0e:b9:ca", "uuid": "8ab0e748b10c5168", "sn": "100069232005D5", "category": "wg2", "product_name": "Garza Smart HUB", "product_id": "ixckfr3zke5fgach", "biz_type": 0, "model": "401303", "sub": false, "icon": "https://images.tuyaeu.com/smart/icon/ay1530692932059RsnDv/f105f6f1d67af0e3bd217acce5d3cf0d.png", "mapping": {}, "ip": "192.168.XXX.XXX", "version": "3.3" }

`

Confirmation

make-all commented 3 weeks ago

See discussion #522 for how to resolve your connection issues. Likely the issue is that your app is still running after scanning the QR code, and is blocking the local connection to the device. You need to force close the app, or turn off WiFi on your device.

Fertx0 commented 2 weeks ago

After digging for hours in the tuya-local and tinytuya code and trying a thousand things, I found that the problem was a misunderstanding of what Device Id and Sub Device Id means for a Tuya element connecting though a WiFi gateway.

In my case: Device ID is the "id" of the device: from the devices.json: "id": "bfa64369996a901e49tvfn", The IP address is the IP address of the WiFi gateway Local Key is the same for both, at least in my case Sub Device Id (for devices connected via gateway) is the "node_id" for the device in devices.json "node_id": "AB1",

Just in case someone finds the same problem, it took me way too long to sort it out, basically because I didn't read the documentation https://github.com/make-all/tuya-local?tab=readme-ov-file#connecting-to-devices-via-hubs

And thanks a lot for your great work with this code!