make-all / tuya-local

Local support for Tuya devices in Home Assistant
MIT License
1.28k stars 503 forks source link

Holman WX1 Tap Timer won't Add to configuration #1951

Open jeeshofone opened 4 months ago

jeeshofone commented 4 months ago

Describe the bug When adding the WX1 Tap Timer to Home Assistant via either cloud or manual mechanisms the device does not add. I am adding the device via the hub after it is paired to Tuya. I can control the device with Tuya Cloud App. I am not leaving the IP address blank. To Reproduce Steps to reproduce the behavior including the device the issue was observed with:

Receive error:

Unable to connect to your device with those details. It could be an intermittent issue, or they may be incorrect.

Screenshot 2024-05-26 at 8 05 24 PM Screenshot 2024-05-26 at 9 06 47 PM

Expected behavior A clear and concise description of what you expected to happen.

Additional context Add any other context about the problem here. Discussed in https://github.com/make-all/tuya-local/discussions/1309

TinyTuya Setup Wizard [1.13.2]

    Existing settings:
        API Key=<redacted>
        Secret=<redacted>
        DeviceID=<redacted>
        Region=eu

    Use existing credentials (Y/n):

Download DP Name mappings? (Y/n):

Device Listing

[
    {
        "name": "WX1 Tap Timer",
        "id": "<redacted>",
        "key": "<redacted>",
        "mac": "",
        "category": "kg",
        "product_name": "WX1 Tap Timer",
        "product_id": "zrsgzc8jktsricjj",
        "biz_type": 0,
        "model": "WX1TT",
        "sub": true,
        "icon": "https://images.tuyaeu.com/smart/icon/ay1556838860681oKmdO/ab17f6e4e677bba7d3868a7a57cfe5b7.png",
        "uuid": "<redacted>",
        "node_id": "111",
        "mapping": {},
        "parent": "<redacted>"
    },
    {
        "name": "Wi-Fi Socket",
        "id": "<redacted>",
        "key": "<redacted>",
        "mac": "",
        "category": "cz",
        "product_name": "Wi-Fi Socket",
        "product_id": "hzsl8cxxtpd0x56b",
        "biz_type": 0,
        "model": "Emate Socket",
        "sub": true,
        "icon": "https://images.tuyaeu.com/smart/icon/ay1556838860681oKmdO/a475d09a86f87279a5fb63d3e8bcba84.png",
        "uuid": "<redacted>",
        "node_id": "11B",
        "mapping": {
            "1": {
                "code": "switch_1",
                "type": "Boolean",
                "values": {}
            }
        },
        "parent": "<redacted>"
    },
    {
        "name": "Wi-Fi Hub",
        "id": "<redacted>",
        "key": "<redacted>",
        "mac": "7c:f6:66:c9:09:68",
        "uuid": "ec6019439941fa66",
        "sn": "1000376290074E",
        "category": "wg2",
        "product_name": "Wi-Fi Hub",
        "product_id": "lzjw7vgzngzrzy74",
        "biz_type": 0,
        "model": "EMateGateWay",
        "sub": false,
        "icon": "https://images.tuyaeu.com/smart/icon/ay1556838860681oKmdO/e47c08d07b3801b3ea8890b3f548bc7f.png",
        "mapping": {}
    },
    <other devices redacted>
]

>> Saving list to devices.json
    6 registered devices saved

>> Saving raw TuyaPlatform response to tuya-raw.json

Poll local devices? (Y/n):

Scanning local network for Tuya devices...
    2 local devices discovered

Polling local devices...
    [Gwen                     ] 10.10.0.118        - No Response
    [Kogan Bladeless Purifier ] 10.40.0.13         - [On]  - DPS: {'1': True, '2': '1', '3': 'close', '8': True, '9': 23, '10': 20, '11': '0', '12': 0, '13': 0, '102': False, '103': False, '106': '2', '107': False}
    [Kogan Smart Portable Air ] Error: No IP found
    [WX1 Tap Timer            ] Error: No IP found
    [Wi-Fi Hub                ] 10.40.0.180        - No Response
    [Wi-Fi Socket             ] Error: No IP found

>> Saving device snapshot data to snapshot.json

>> Saving IP addresses to devices.json
    3 device IP addresses found

Done.

(tiny) will@Wills-MacBook-Pro-4 tiny % python -m tinytuya scan

TinyTuya (Tuya device scanner) [1.13.2]

[Loaded devices.json - 6 devices]

Scanning on UDP ports 6666 and 6667 and 7000 for devices for 18 seconds...

Kogan Bladeless Purifier Fan Heater   Product ID = 3permbmoa6lq7zvu  [Valid Broadcast]:
    Address = 10.40.0.13   Device ID = <redacted> (len:22)  Local Key = <redacted>  Version = 3.3  Type = default, MAC = 50:8a:06:f0:15:c1
    Status: {'1': True, '2': '1', '3': 'close', '8': True, '9': 23, '10': 20, '11': '0', '12': 0, '13': 0, '102': False, '103': False, '106': '2', '107': False}
Wi-Fi Hub   Product ID = keyth3n5me5jqu95  [Valid Broadcast]:
    Address = 10.40.0.180   Device ID = <redacted> (len:22)  Local Key = <redacted>  Version = 3.3  Type = default, MAC = 7c:f6:66:c9:09:68
    Access rejected by 10.40.0.180 (check key): Invalid JSON Response from Device: devid not found
Scan completed in 18.055 seconds

Scan Complete!  Found 2 devices.
Broadcasted: 2
Versions: 3.3: 2

>> Saving device snapshot data to snapshot.json

If the bug involves a device, then please include device diagnostics from Settings / Devices & Services / Tuya Local (your device) / "1 device"

2024-05-26 21:14:31.158 DEBUG (MainThread) [custom_components.tuya_local.device] Refreshing device state for Test
2024-05-26 21:14:31.158 INFO (MainThread) [custom_components.tuya_local.device] Setting protocol version for Test to 3.3
2024-05-26 21:14:31.235 DEBUG (MainThread) [custom_components.tuya_local.device] Retrying after exception <class 'AttributeError'> Network Error: Device Unreachable (0/3)
2024-05-26 21:14:31.235 INFO (MainThread) [custom_components.tuya_local.device] Setting protocol version for Bedroom Air Conditioner to 3.4
2024-05-26 21:14:31.287 DEBUG (SyncWorker_11) [custom_components.tuya_local.device] Test refreshed device state: {"Error": "Invalid JSON Response from Device", "Err": "900", "Payload": "devid not found"}
2024-05-26 21:14:31.287 WARNING (SyncWorker_11) [custom_components.tuya_local.device] Test protocol error 900: Invalid JSON Response from Device

Additionally:

2024-05-26 19:35:17.437 DEBUG (MainThread) [custom_components.tuya_local.config_flow] Hub count: 0
2024-05-26 19:35:20.114 DEBUG (MainThread) [custom_components.tuya_local.config_flow] Scanning network to get IP address for bfbd1b453049b3af8fvcvd.
2024-05-26 19:35:20.116 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 88, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp_session/__init__.py", line 199, in factory
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 295, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 71, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 73, in wrapper
    return await method(view, request, data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 368, in async_configure
    result = await self._async_configure(flow_id, user_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 414, in _async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 518, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/tuya_local/config_flow.py", line 375, in async_step_search
    local_device = await self.hass.async_add_executor_job(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/tuya_local/config_flow.py", line 603, in scan_for_device
    return tinytuya.find_device(dev_id=id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/tinytuya/core.py", line 641, in find_device
    client.bind(("", UDPPORT))
OSError: [Errno 98] Address in use```

however this issue is with the cloud add is gone once i uninstalled rospogrigio/localtuya

If applicable, add screenshots to help explain your problem.

make-all commented 4 months ago

You seem to be getting the same error from tinytuya standalone as you are getting from this integration. Most likely it is a problem with the configuration parameters you are using. The details are slightly different for a hub.

jeeshofone commented 4 months ago

Hi @make-all - thanks for that - what information of the configuration parameters can I provide to assist.

I first try only adding only the hub ending in vcvd: Screenshot 2024-05-27 at 9 14 04 AM

Logs

2024-05-27 09:13:59.059 WARNING (SyncWorker_10) [custom_components.tuya_local.device] Test protocol error 900: Invalid JSON Response from Device

Then I try adding the hub with the sub device on the WX1 (ending in izo5): Screenshot 2024-05-27 at 9 15 26 AM

2024-05-27 09:14:47.747 WARNING (SyncWorker_50) [custom_components.tuya_local.device] Test protocol error 900: Invalid JSON Response from Device

Then I try adding the WX1 as the main device without the hub:

Screenshot 2024-05-27 at 9 14 53 AM

2024-05-27 09:15:19.927 ERROR (MainThread) [custom_components.tuya_local.device] Failed to refresh device state for Test.
TheSimTek commented 4 months ago

Never got it to work. Be interested in how others have successfully integrated this into a local tuya setup.

jeeshofone commented 4 months ago

@Brazen00 added it in https://github.com/make-all/tuya-local/pull/979 - I wonder if they could help us out?

make-all commented 4 months ago

Based on what is tested in the new config flow, device id should be the device id of your hub, and sub device id should be the uuid of the sub device.

jeeshofone commented 4 months ago

Based on what is tested in the new config flow, device id should be the device id of your hub, and sub device id should be the uuid of the sub device.

That was one method I tried in the above troubleshooting description

I have tried it again tonight and found that with the latest version, the process never finishes (I let it go for 5min) This is the only relevant line in the logs 2024-06-04 01:02:15.398 INFO (MainThread) [custom_components.tuya_local.device] Setting protocol version for Test to 3.3

Screenshot 2024-06-04 at 1 13 13 AM I used the UUID of the sub device (same as the sub device id for the sub device id and the device id as the id of the hub. The hub also has a switched outlet device in it. I tested it again the same way with identical results. Also made sure the Tuya app was closed.

The device does work when testing in the Tuya app alone.

jeeshofone commented 3 months ago

Would anyone be able to suggest next steps for debugging here?