rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.86k stars 551 forks source link

Unable to add Devices via Local Tuya #860

Open smarthomeaf opened 2 years ago

smarthomeaf commented 2 years ago

The problem

Before I decide to upgrade my production Home Assistant to v4 of Local tuya, I decided to configure this in my test environment. The integration adds correctly and I was able to configure the APIs. Devices are also automatically dicovered, but when I click to add them I get the below error.

image image

Environment

Steps to reproduce

  1. Install integration via HACS
  2. Installed local tuya via the UI
  3. Configure the integration with correct APIs
  4. Tried to add the devices and received teh above erros

## DP dump
<!-- 
This error originated from a custom integration.

Logger: custom_components.localtuya.config_flow
Source: custom_components/localtuya/pytuya/__init__.py:247
Integration: LocalTuya (documentation, issues)
First occurred: 9:24:05 AM (6 occurrences)
Last logged: 9:35:34 AM

Unexpected exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/asyncio/locks.py", line 417, in acquire
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 490, in wait_for
    return fut.result()
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/localtuya/config_flow.py", line 533, in async_step_configure_device
    self.dps_strings = await validate_input(self.hass, user_input)
  File "/config/custom_components/localtuya/config_flow.py", line 242, in validate_input
    detected_dps = await interface.detect_available_dps()
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 539, in detect_available_dps
    data = await self.status()
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 481, in status
    status = await self.exchange(STATUS)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 460, in exchange
    msg = await self.dispatcher.wait_for(seqno)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 247, in wait_for
    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 492, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

-->

## Provide Home Assistant taceback/logs
<!--
 This error originated from a custom integration.

Logger: custom_components.localtuya.pytuya
Source: custom_components/localtuya/pytuya/__init__.py:247
Integration: LocalTuya (documentation, issues)
First occurred: 9:24:04 AM (6 occurrences)
Last logged: 9:35:34 AM

[230...c51] Failed to get status:
[406...298] Failed to get status:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/asyncio/locks.py", line 417, in acquire
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 490, in wait_for
    return fut.result()
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 539, in detect_available_dps
    data = await self.status()
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 481, in status
    status = await self.exchange(STATUS)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 460, in exchange
    msg = await self.dispatcher.wait_for(seqno)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 247, in wait_for
    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 492, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

-->
```txt

Additional information

iwjcs commented 2 years ago

The same happened here. In my case it is a new/clean installation.

I tried all the day without success in Raspberry/Raspbian and also on x64/Ubuntu OSs, with different wifi networks.

Checking the network communication packages (tcpdump), it seems that the timeout occurs instantly, in about 1 second after starting the communication between the host and the device.

Follows the screen capture:

image

image

Logger: custom_components.localtuya.config_flow Source: custom_components/localtuya/pytuya/init.py:247 Integration: LocalTuya (documentation, issues) First occurred: 7:33:50 PM (8 occurrences) Last logged: 8:31:42 PM

Unexpected exception Traceback (most recent call last): File "/usr/lib/python3.9/asyncio/locks.py", line 413, in acquire await fut asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3.9/asyncio/tasks.py", line 492, in wait_for fut.result() asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/homeassistant/.homeassistant/custom_components/localtuya/config_flow.py", line 533, in async_step_configure_device self.dps_strings = await validate_input(self.hass, user_input) File "/home/homeassistant/.homeassistant/custom_components/localtuya/config_flow.py", line 242, in validate_input detected_dps = await interface.detect_available_dps() File "/home/homeassistant/.homeassistant/custom_components/localtuya/pytuya/init.py", line 539, in detect_available_dps data = await self.status() File "/home/homeassistant/.homeassistant/custom_components/localtuya/pytuya/init.py", line 481, in status status = await self.exchange(STATUS) File "/home/homeassistant/.homeassistant/custom_components/localtuya/pytuya/init.py", line 460, in exchange msg = await self.dispatcher.wait_for(seqno) File "/home/homeassistant/.homeassistant/custom_components/localtuya/pytuya/init.py", line 247, in wait_for await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout) File "/usr/lib/python3.9/asyncio/tasks.py", line 494, in wait_for raise exceptions.TimeoutError() from exc asyncio.exceptions.TimeoutError

kerashin commented 2 years ago

Hello, exact same issue here when adding the Tuya Door Window Sensor.

image

prbtt commented 2 years ago

Same issue here with my AVATTO wall switches. Only 1 out of 6 worked... Very unfortunate. Might have to use the cloud integration afterall, this has too many bugs to be reliable for now at least.

goul commented 2 years ago

I’m having similar issues with Xavitech Smart Plugs - anecdotally feeling like I’m having more success connecting to them if they have been power cycled (physical removal/replacement of plug) recently.

prbtt commented 2 years ago

I’m having similar issues with Xavitech Smart Plugs - anecdotally feeling like I’m having more success connecting to them if they have been power cycled (physical removal/replacement of plug) recently.

Yea, Power cycle solves temporarily. But I can't be relying on that. I'm using the cloud integration for now.

nolan879 commented 2 years ago

Having the same issue. I am trying to add an inline relay on a 120v wire.

lewiatanx commented 2 years ago

The same happened here. In my case it is a new/clean installation.

I tried all the day without success in Raspberry/Raspbian and also on x64/Ubuntu OSs, with different wifi networks.

Checking the network communication packages (tcpdump), it seems that the timeout occurs instantly, in about 1 second after starting the communication between the host and the device.

I also use AUBESS mini switch and unfortunately newer productions have TUYA protocol 3.4, which is not yet supported by LocalTuya :( The previous versions work fine because they use the 3.3 protocol We need to wait for LocalTuya to handle the newer protocol

smarthomeaf commented 2 years ago

The same happened here. In my case it is a new/clean installation. I tried all the day without success in Raspberry/Raspbian and also on x64/Ubuntu OSs, with different wifi networks. Checking the network communication packages (tcpdump), it seems that the timeout occurs instantly, in about 1 second after starting the communication between the host and the device.

I also use AUBESS mini switch and unfortunately newer productions have TUYA protocol 3.4, which is not yet supported by LocalTuya :( The previous versions work fine because they use the 3.3 protocol We need to wait for LocalTuya to handle the newer protocol

Not sure I believe this is related to being 3.4 protocol. These devices work fine on local tuya 3.5. It didnt break until I upgraded to 4.0/4.0.1

prbtt commented 2 years ago

The same happened here. In my case it is a new/clean installation. I tried all the day without success in Raspberry/Raspbian and also on x64/Ubuntu OSs, with different wifi networks. Checking the network communication packages (tcpdump), it seems that the timeout occurs instantly, in about 1 second after starting the communication between the host and the device.

I also use AUBESS mini switch and unfortunately newer productions have TUYA protocol 3.4, which is not yet supported by LocalTuya :( The previous versions work fine because they use the 3.3 protocol We need to wait for LocalTuya to handle the newer protocol

Not sure I believe this is related to being 3.4 protocol. These devices work fine on local tuya 3.5. It didnt break until I upgraded to 4.0/4.0.1

For me this still happens if I downgrade. Started happening after I updated home assistant.

lewiatanx commented 2 years ago

The same happened here. In my case it is a new/clean installation. I tried all the day without success in Raspberry/Raspbian and also on x64/Ubuntu OSs, with different wifi networks. Checking the network communication packages (tcpdump), it seems that the timeout occurs instantly, in about 1 second after starting the communication between the host and the device.

I also use AUBESS mini switch and unfortunately newer productions have TUYA protocol 3.4, which is not yet supported by LocalTuya :( The previous versions work fine because they use the 3.3 protocol We need to wait for LocalTuya to handle the newer protocol

Not sure I believe this is related to being 3.4 protocol. These devices work fine on local tuya 3.5. It didnt break until I upgraded to 4.0/4.0.1

For me this still happens if I downgrade. Started happening after I updated home assistant.

For me the problem arose after adding new Aubess switches. I checked Tuya protocols with "tinytuya" and it turned out that those switches LocalTuya didn't want to add have a newer version of the software with ver protocol. 3.4 :( In the meantime, switches with protocol version 3.3 has been added without any problems, so the problem is apparently the lack of protocol ver. 3.4 by LocalTuya.

smarthomeaf commented 2 years ago

I confirmed that my devices are on 3.3.

smarthomeaf commented 2 years ago

After some persistence, I think I figured it out. I removed one of the devices from Tuya app and then re-added it. That seemed to do the Trick. I will Check my otehr 5 devices and keep everyone posted.

prbtt commented 2 years ago

After some persistence, I think I figured it out. I removed one of the devices from Tuya app and then re-added it. That seemed to do the Trick. I will Check my otehr 5 devices and keep everyone posted.

I also did that multiple times. It is a temporary fix, it will stop working eventually. At least for me that's what happened.

smarthomeaf commented 2 years ago

I see the same behavior, but if I wait a few hours the devices come back up. Here is a layout of my Test Lab and the results of my testing if it helps.

Summary - teh devices that are working correctly in Local Tuya, are not always responding to the TinyTuya Scan which i believe is looking for some sort of Heart Beat. I know the Devices are working correctly even though no responding to TinyTuya because I can control the device from any of the platforms (Local Tuya, Tuya Smart App, and Standard Tuya Integration) and status are replicated across all platforms.

If I am not mistaken, this integration leverages tinytuya somehow, and what i think is broken is tinytuya and not LocalTuya. Just thinking out loud.

roja45 commented 2 years ago

Same issue here with my AVATTO wall switches. Only 1 out of 6 worked... Very unfortunate. Might have to use the cloud integration afterall, this has too many bugs to be reliable for now at least.

I have something similar with Avatto. I have some Avatto 1 and 2 gang switches that I can add without any problems, but I have just got two new switches, and these give me this error when I try to add them. They have different pairing light colors as well, so I'm guessing a newer firmware.

2022-07-15 13:02:36 ERROR (MainThread) [custom_components.localtuya.pytuya] [eb1...gjs] Failed to get status: Traceback (most recent call last): File "/usr/local/lib/python3.10/asyncio/locks.py", line 390, in acquire await fut asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.10/asyncio/tasks.py", line 456, in wait_for return fut.result() asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/config/custom_components/localtuya/pytuya/init.py", line 539, in detect_available_dps data = await self.status() File "/config/custom_components/localtuya/pytuya/init.py", line 481, in status status = await self.exchange(STATUS) File "/config/custom_components/localtuya/pytuya/init.py", line 460, in exchange msg = await self.dispatcher.wait_for(seqno) File "/config/custom_components/localtuya/pytuya/init.py", line 247, in wait_for await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout) File "/usr/local/lib/python3.10/asyncio/tasks.py", line 458, in wait_for raise exceptions.TimeoutError() from exc asyncio.exceptions.TimeoutError 2022-07-15 13:02:36 ERROR (MainThread) [custom_components.localtuya.config_flow] Unexpected exception Traceback (most recent call last): File "/usr/local/lib/python3.10/asyncio/locks.py", line 390, in acquire await fut asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.10/asyncio/tasks.py", line 456, in wait_for return fut.result() asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/config/custom_components/localtuya/config_flow.py", line 533, in async_step_configure_device self.dps_strings = await validate_input(self.hass, user_input) File "/config/custom_components/localtuya/config_flow.py", line 242, in validate_input detected_dps = await interface.detect_available_dps() File "/config/custom_components/localtuya/pytuya/init.py", line 539, in detect_available_dps data = await self.status() File "/config/custom_components/localtuya/pytuya/init.py", line 481, in status status = await self.exchange(STATUS) File "/config/custom_components/localtuya/pytuya/init.py", line 460, in exchange msg = await self.dispatcher.wait_for(seqno) File "/config/custom_components/localtuya/pytuya/init.py", line 247, in wait_for await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout) File "/usr/local/lib/python3.10/asyncio/tasks.py", line 458, in wait_for raise exceptions.TimeoutError() from exc asyncio.exceptions.TimeoutError

roja45 commented 2 years ago

This is the output from the tuyadebug for this device, I think this may be a different issue though.

INFO:localtuya:localtuya version 1.0.0 INFO:localtuya:Python 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0] on linux INFO:localtuya:Using pytuya version '8.1.0' INFO:localtuya:Detecting list of available DPS of device eb333f82c3b6ebdc898uw4 [192.168.1.102], protocol 3.3. DEBUG:localtuya.pytuya:Sending command status (device type: type_0a) DEBUG:localtuya.pytuya:paylod=b'{"gwId":"eb333f82c3b6ebdc898uw4","devId":"eb333f82c3b6ebdc898uw4"}' DEBUG:localtuya.pytuya:DATA RECEIVED! DEBUG:localtuya.pytuya:READING AGAIN! DEBUG:localtuya.pytuya:Failed to connect to 192.168.1.103. Raising Exception. WARNING:localtuya.pytuya:Failed to get status: unpack requires a buffer of 20 bytes INFO:localtuya:Detecting list of available DPS of device eb322f82c3b6ebdc898uw4 [192.168.1.102], protocol 3.3. DEBUG:localtuya.pytuya:Sending command status (device type: type_0a) DEBUG:localtuya.pytuya:paylod=b'{"gwId":"eb333f82c3b6ebdc898uw4","devId":"eb333f82c3b6ebdc898uw4"}' DEBUG:localtuya.pytuya:DATA RECEIVED! DEBUG:localtuya.pytuya:READING AGAIN! DEBUG:localtuya.pytuya:Failed to connect to 192.168.1.102. Raising Exception. WARNING:localtuya.pytuya:Failed to get status: unpack requires a buffer of 20 bytes INFO:localtuya:Detecting list of available DPS of device eb322f82c3b6ebdc898uw4 [192.168.1.102], protocol 3.3. DEBUG:localtuya.pytuya:Sending command status (device type: type_0a) DEBUG:localtuya.pytuya:paylod=b'{"gwId":"eb333f82c3b6ebdc898uw4","devId":"eb333f82c3b6ebdc898uw4"}' DEBUG:localtuya.pytuya:DATA RECEIVED! DEBUG:localtuya.pytuya:READING AGAIN! DEBUG:localtuya.pytuya:Failed to connect to 192.168.1.102. Raising Exception. WARNING:localtuya.pytuya:Failed to get status: unpack requires a buffer of 20 bytes INFO:localtuya:TIMEOUT: No response from device eb333f82c3b6ebdc898uw4 [192.168.1.102] after 2 attempts.

vjmaz commented 2 years ago

yes I'm in the same boat team , tried to add some new 4 gang light switches which i have had as spares and no go !!! similar errors as above as many of you ... I have already added many other 8 gang light switches and 4 gang also fans and color down lights so not sure why its playing up ... please fix team i have like 9 more 4 gang light switches to add still ... and all the ones that are added already work so well on localtuya ... ...

Is it best to also have normal tuya and locatuya running on the same HA ?

Malekith83 commented 2 years ago

i think i have the same problem: i can't add my two new BSEED sockets with powermeter in localtuya. I already have three of them in operation with localtuya (with the info in the Smart Life app that a flash update of the main module to v1.1.12 is available). I updated one of the working modules to v1.1.12 as a test, and suddenly it is no longer accessible via localtuya. I suspect that this update changes to the new tuya protocol v3.4.

Do not update working modules to the latest firmware before localtuya supports protocol 3.4. But if you read this it is probably already done and too late for you :)

BR

feliperibeiro777 commented 2 years ago

I have the same problem with my new bulbs...

abcben78 commented 1 year ago

Still the same problem?

smarthomeaf commented 1 year ago

this seems to be working perfectly on my side now. I think the last update fixed this for me anyway

PatrykPetryszen commented 1 year ago

I have this problem with all my devices. Authentication to the iot works fine but cannot discover any devices. When I tried adding the device manually it didn't work. Where are the logs located so I can check if that's the same issue?

pedronunesbr commented 1 year ago

I am facing the same problem.

nlmaca commented 1 year ago

I have the same issue. Discovery will show the sensor, but will result in an error when trying to add it. Tuya version: 4.1 Error log: `Logger: custom_components.localtuya.config_flow Source: custom_components/localtuya/pytuya/init.py:704 Integration: LocalTuya (documentation, issues) First occurred: 01:02:16 (2 occurrences) Last logged: 01:06:14

Unexpected exception Traceback (most recent call last): File "/config/custom_components/localtuya/config_flow.py", line 580, in async_step_configure_device self.dps_strings = await validate_input(self.hass, user_input) File "/config/custom_components/localtuya/config_flow.py", line 245, in validate_input interface = await pytuya.connect( File "/config/customcomponents/localtuya/pytuya/init.py", line 704, in connect , protocol = await loop.create_connection( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1064, in create_connection raise exceptions[0] File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1049, in create_connection sock = await self._connect_sock( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect return await fut File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') OSError: [Errno 113] Connect call failed ('xxx.xxx.xxx.xxx', 6668)`

kev300 commented 1 year ago

Looks like a similar issue for me:

2023-01-07 11:41:40.317 ERROR (MainThread) [custom_components.localtuya.common] [bf9...0du] Connect to 192.168.1.31 failed Traceback (most recent call last): File "/config/custom_components/localtuya/common.py", line 186, in _make_connection self._interface = await pytuya.connect( File "/config/customcomponents/localtuya/pytuya/init.py", line 704, in connect , protocol = await loop.create_connection( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1064, in create_connection raise exceptions[0] File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1049, in create_connection sock = await self._connect_sock( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect return await fut File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') OSError: [Errno 113] Connect call failed ('192.168.1.31', 6668)

kingracefan commented 1 year ago

Same Here

Logger: custom_components.localtuya.config_flow Source: custom_components/localtuya/pytuya/init.py:704 Integration: LocalTuya (documentation, issues) First occurred: 10:24:07 PM (31 occurrences) Last logged: 10:32:05 PM

Unexpected exception Traceback (most recent call last): File "/config/custom_components/localtuya/config_flow.py", line 580, in async_step_configure_device self.dps_strings = await validate_input(self.hass, user_input) File "/config/custom_components/localtuya/config_flow.py", line 245, in validate_input interface = await pytuya.connect( File "/config/customcomponents/localtuya/pytuya/init.py", line 704, in connect , protocol = await loop.create_connection( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1064, in create_connection raise exceptions[0] File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1049, in create_connection sock = await self._connect_sock( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect return await fut File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') OSError: [Errno 113] Connect call failed ('192.168.1.31', 6668)

dott90 commented 1 year ago

Hi everyone, same problem. Is there any solution please?

prbtt commented 1 year ago

Hi everyone, same problem. Is there any solution please?

Mine worked after using the new protocol

dott90 commented 1 year ago

Hi everyone, same problem. Is there any solution please?

Mine worked after using the new protocol

Which one do you mean? Sorry for my stupid question.

prbtt commented 1 year ago

Hi everyone, same problem. Is there any solution please?

Mine worked after using the new protocol

Which one do you mean? Sorry for my stupid question.

I used 3.3 for 6 ch wall switch and 3.4 for 3 ch wall switch

IamHEREfromU commented 4 months ago

hi, i need help when i try to and device on tuya i receive that error:

Connection to device succeeded but no datapoints found, please try again. Create a new issue and include debug logs if problem persists.

how i can fix it? i use rasbbery pi and run HA on portainer