xZetsubou / hass-localtuya

🔹 A Home Assistant integration to handle Tuya devices locally "fork from localtuya"
https://xzetsubou.github.io/hass-localtuya/
GNU General Public License v3.0
440 stars 54 forks source link

Zigbee Sub-Devices: "Connection to device succeeded but no datapoints could be found" #94

Closed phrak closed 11 months ago

phrak commented 11 months ago

Thank you so much for creating this fork! It is exactly what I needed :)

The problem

When attempting to add some (not all) Zigbee devices, some devices report that "Connection to device succeeded but no datapoints could be found".

I have re-downloaded Master branch as at the date & time of this issue.

All Zigbee devices are paired with a Mercator Ikuu Zigbee Pro Hub SGW003 as my Zigbee gateway. This is a Tuya TYGWZ-01 Ethernet Smart Gateway, also rebranded as LIDL, Silvercrest, Pearl.de, Revolt, Elesion and many more.

I can successfully auto-discover and add these Zigbee devices:

But I cannot add these devices:

Please let me know if you would like any additional logs or debug dumps.

Environment

DP dump

Provide Home Assistant traceback/logs

2024-01-04 16:24:09.240 DEBUG (MainThread) [custom_components.localtuya.config_flow] Detected DPS: {}
2024-01-04 16:24:09.268 ERROR (MainThread) [custom_components.localtuya.core.pytuya] [bf9...w5g] Failed to get status: DeviceID Not found
Traceback (most recent call last):
  File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 1191, in _decode_payload
    json_payload = json.loads(payload)
                   ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 1097, in detect_available_dps
    data = await self.status(cid=cid)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 1016, in status
    status: dict = await self.exchange(command=DP_QUERY, nodeID=cid)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 1001, in exchange
    payload = self._decode_payload(msg.payload)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 1194, in _decode_payload
    raise ValueError("DeviceID Not found")
ValueError: DeviceID Not found
2024-01-04 16:24:09.290 DEBUG (MainThread) [custom_components.localtuya.config_flow] Detected DPS: {}
2024-01-04 16:24:09.291 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf9...w5g] Connection lost: None
2024-01-04 16:24:09.301 DEBUG (MainThread) [custom_components.localtuya.config_flow] Detected DPS: {}
2024-01-04 16:24:09.302 DEBUG (MainThread) [custom_components.localtuya.config_flow] Detected DPS: {}
2024-01-04 16:24:09.304 DEBUG (MainThread) [custom_components.localtuya.config_flow] Detected DPS: {}
2024-01-04 16:24:09.304 WARNING (MainThread) [custom_components.localtuya.config_flow] Failed to configure device: [ name: IKUU Pro Hub SGW003 — id: bf9e4ec01480c0c2f5bw5g — reason: DeviceID Not found]
2024-01-04 16:24:09.305 WARNING (MainThread) [custom_components.localtuya.config_flow] Failed to configure device: [ name: Lounge Room Dimmer SSWRM-ZB — id: bfc23b74c1ac8ea473xhll — reason: ]
2024-01-04 16:24:09.305 WARNING (MainThread) [custom_components.localtuya.config_flow] Failed to configure device: [ name: 5x Backyard Light Switch — id: bf6394c88141d025e6astl — reason: ]
2024-01-04 16:24:09.305 WARNING (MainThread) [custom_components.localtuya.config_flow] Failed to configure device: [ name: Entryway Dimmer SSWRM-ZB — id: bfff51f4040bdbad008om5 — reason: ]
2024-01-04 16:24:09.305 WARNING (MainThread) [custom_components.localtuya.config_flow] Failed to configure device: [ name: Garage Door Contact Sensor — id: bf2ed4f8b4a35e0cf0ye0e — reason: ]

Additional information

I have attached a full dump from Tuya IOT of the devices attached to my gateway. You can cross-reference the product_id values above with the devices in this file. Gateway Connected Zigbee Devices.txt

I also tried adding the 5x switch with Manual DPS's 1-6. I was allowed to add the device. It successfully auto-discovered the Timer DPS's. However, I could not control any of the Switches or Timers. They all showed as "Unavailable". I have included the Diagnostic Data from this time. 5x gang Switch localtuya-d6d1c62282b4cf4e32f66d2628357f28-5x Backyard Light Switch-7a2047838f0e42bb01f0bccd73d568bd.json.txt

xZetsubou commented 11 months ago

Can you download and post the entry diagnostics it contains everything about devices data. and tell me that devices that didn't works by names.

Notes:

  1. Using manual DPS isn't always the best way to add devices, because as you can see all the DPS shows "cloud pull" which means if the devices is self didn't reports DPS, these cloud pull won't help much.
  2. Localtuya entity available logic is that if the devices reports any status it will be available otherwise it shows as "Unavailable" therefore adding manual dps doesn't mean the device reported DPSs.
  3. Auto configure all devices won't works on all sub-devices at the 1st time, you need to add 1 sub-device then use configure all sub-devices.
phrak commented 11 months ago

Thank you - Please see attached. Full Diags config_entry-localtuya-d6d1c62282b4cf4e32f66d2628357f28.json.txt

Devices that did not work are:

These are the non-working sub-devices of: bf9e4ec01480c0c2f5bw5g / "name": "IKUU Pro Hub SGW003",

Re: your notes. Thank you, I understand.

Re note 3. Yes, I have tried to add these sub-devices multiple times after 1 sub-device has already been added.

xZetsubou commented 11 months ago

Ok it seems the device named "3x Kitchen Light Switch" the device that being used as "gateway" can you enable the debug for it. Configure -> Reconfigure existed device -> 3x Kitchen Light Switch -> turn on debug for it.

After turning on the debug try controlling these sub-devices that didn't success to add physically and by turning them on / off.

then go to Settings -> System -> Logs, search for localtuya and open full logs, I want to see if these devices reports any states change to gateway.

phrak commented 11 months ago

Thank you for investigating.

I have enabled debugging for the "3x Kitchen Light Switch" (bf200a5d4c611ba1ecmaba) device as requested.

Then I manually (physically with my finger) switched SWITCH 5 of the "5x Backyard Light Switch" (bf6394c88141d025e6astl) device.

The log entry for this action is attached. Start line: 142 End line: 162 Debug 2.txt

xZetsubou commented 11 months ago

What happen if you try to add "5x Backyard Light Switch" into HA does shows "but no datapoints" error?

Can you try to add it? and check if the error shows One more thing just to make sure that no existed device causing the issue, can you delete any sub-device connected to the same gateway as "5x" device then try to re-add it.

The good thing is that the "5x" device reports the changed states. But with the "current entity available logic" it require the device to at least return any status.

phrak commented 11 months ago

It's working now! I don't think I did anything differently, other than manually pressing buttons on the 5x yesterday.

Now today, I only did "Add new device" -> Selected the "5x Backyard Light Switch" device -> Submit. And the device was successfully added as expected! 😃 After that, I removed the 5x device and re-added it again to be sure. This worked fine too.

Then, I did "Add new device" -> Selected the "Entryway Dimmer SSWRM-ZB" device, and ticked "Configure all recognized devices automatically". All 3 sub-devices that had problems earlier were added successfully, and they can all be controlled as expected.

Now, only the "IKUU Pro Hub SGW003" (bf9e4ec01480c0c2f5bw5g) device can not be added, but this is not a problem. This is the Gateway hub that does not contain any DPS's or configuration of it's own, so there is nothing for LocalTuya to do.

@xZetsubou thank you so much for your help here, I love this project!

Please let me know if you would like any additional debug or diagnostic logs to help close any residual concerns.

xZetsubou commented 11 months ago

So the issue got fixed on it own :) ?

So I guess this issue caused due a communication issues between the gateway and sub-devices and probably by toggling on/off the sub-device started to re-communicate with the gateway. While I was testing sub-devices before I noticed that when I power-off the gateway and turn it on later, I my ZigBee motion sensor doesn't return status at all until it triggered by something, I'm guessing you had the same issue not sure tho.

As for gateways unless it has extra features (yours doesn't) it's no uses for localtuya at all, so adding them is useless :) This is an example of my gateway which has some features tho it's still useless.

phrak commented 11 months ago

Actually, now that you mention it, I did do one other thing that could have made a difference. I power-cycled the Zigbee gateway between the time that I first logged the issue and the time that is started working.

Perhaps this reboot forced the gateway and switch to re-establish a good connection.

Thank you again for your help to troubleshoot this issue. Please consider adding a donation link on your home page - I'd love to buy you a beer or coffee as a small thanks!

gabrielhopkins commented 5 months ago

FWIW - I had this problem - and literally using the devices/or waiting for the case of humidity sensors worked a treat.