rospogrigio / localtuya

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

Connection to device failed #631

Open dsybers opened 2 years ago

dsybers commented 2 years ago

The problem

When I try to add a temperature/humidity sensor through the localtuya integration I get an error referring to the log. Also, the devices are not always visible in the detected devices list. I use the Tuya app on my phone to first set up the devices, they work without issue here (even though loading of the device options when selected in the list takes a while)

Environment

Provide Home Assistant taceback/logs

This error originated from a custom integration.

Logger: custom_components.localtuya.config_flow Source: custom_components/localtuya/pytuya/init.py:637 Integration: LocalTuya integration (documentation, issues) First occurred: 16:15:41 (1 occurrences) Last logged: 16:15:41

Unexpected exception Traceback (most recent call last): File "/config/custom_components/localtuya/config_flow.py", line 279, in async_step_basic_info self.dps_strings = await validate_input(self.hass, user_input) File "/config/custom_components/localtuya/config_flow.py", line 185, in validate_input interface = await pytuya.connect( File "/config/customcomponents/localtuya/pytuya/init.py", line 637, in connect , protocol = await loop.create_connection( File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1056, in create_connection raise exceptions[0] File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1041, in create_connection sock = await self._connect_sock( File "/usr/local/lib/python3.9/asyncio/base_events.py", line 955, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 502, in sock_connect return await fut File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 537, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') OSError: [Errno 113] Connect call failed ('192.168.0.132', 6668)

smithbill17 commented 2 years ago

I think this is the same issue I am now getting after a new setup of the LocalTuya Integration (v3.2.3) on HomeAssistant v2021.11.5

2021-11-26 15:56:48 ERROR (MainThread) [custom_components.localtuya.common] [683...9b1] Connect to 192.168.68.114 failed
Traceback (most recent call last):
File "/config/custom_components/localtuya/common.py", line 139, in _make_connection
self._interface = await pytuya.connect(
File "/config/custom_components/localtuya/pytuya/__init__.py", line 637, in connect
_, protocol = await loop.create_connection(
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1056, in create_connection
raise exceptions[0]
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1041, in create_connection
sock = await self._connect_sock(
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 955, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 502, in sock_connect
return await fut
File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 537, in _sock_connect_cb
raise OSError(err, f'Connect call failed {address}')
ConnectionResetError: [Errno 104] Connect call failed ('192.168.68.114', 6668)

Strangely it's always the same 4 SmartPlugs, no matter how many times I restart HomeAssistant.

But I'm wondering if this has something to do with the fact I have a 2nd HomeAssistant running in a VirtualBox VM also with LocalTuya Integration. However, it's working fine for all my SmartPlugs. Although when I was setting up this VM HomeAssistant, I was also getting this error (on the same 4 SmartPlugs) when I was trying to add them to the integration. But I discovered if I rebooted my other HomeAssistant, then I could add them to the VM HomeAssistant okay. But now that I've got all my SmartPlugs added to the VM HomeAssistant and all working, the same 4 SmartPlugs have stopped working (and logging the above error) on my original HomeAssistant.

Is there some reason why LocalTuya Integration won't work with two entirely separate installations on the network? Why would 11 out of 15 SmartPlugs work fine on both installations, but the same 4 SmartPlugs log the above error?

The 4 SmartPlugs in question work fine in SmartLife app.

smithbill17 commented 2 years ago

I've confirmed that if I shutdown HomeAssistant on one of my installations and restart the other one, then the 4 SmartPlugs I have a problem with, start working okay on the restarted HomeAssistant, but when I start up the HomeAssistant that was shutdown, then the 4 SmartPlugs don't work on there.

If I swap over which HomeAssistant I shutdown and which one I restart, then the 4 SmartPlugs stop working one the other HomeAssistant.

So what is the problem with having two HomeAssistants each with their own LocalTuya Integration?

And why does it only affect the same 4 SmartPlugs (which are present on the network & can be controlled with SmartLife or the one working HomeAssistant).

smithbill17 commented 2 years ago

This appears to be the same issue as #624 Hopefully, with multiple people experiencing the same issue, it'll get fixed soon.

dsybers commented 2 years ago

I'm not using more than one HA server/instance, so it's possibly a similar issue but the second HA instance is not a common cause between us. I discovered the sensors go to sleep mode most of the time, maybe it has something to do with this?

cyberdie commented 2 years ago

Same problem here. My HA log is full of this errors. But devices (3 lights) work as expected.

` Logger: custom_components.localtuya.common Source: custom_components/localtuya/pytuya/init.py:240 Integration: LocalTuya integration (documentation, issues) First occurred: 30 de noviembre de 2021 09:41:04 (9919 occurrences) Last logged: 12:47:08

[125...da1] Connect to 192.168.1.216 failed [bfd...zap] Connect to 192.168.1.108 failed [020...bcd] Connect to 192.168.1.243 failed Traceback (most recent call last): File "/usr/local/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/local/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 "/config/custom_components/localtuya/common.py", line 149, in _make_connection status = await self._interface.status() File "/config/custom_components/localtuya/pytuya/init.py", line 472, in status status = await self.exchange(STATUS) File "/config/custom_components/localtuya/pytuya/init.py", line 451, in exchange msg = await self.dispatcher.wait_for(seqno) File "/config/custom_components/localtuya/pytuya/init.py", line 240, in wait_for await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout) File "/usr/local/lib/python3.9/asyncio/tasks.py", line 494, in wait_for raise exceptions.TimeoutError() from exc asyncio.exceptions.TimeoutError `