rospogrigio / localtuya

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

Unexpected exception: [Errno 113] Connect call failed ('192.168.0.203', 6668) #1426

Open niemenjoki opened 1 year ago

niemenjoki commented 1 year ago

The integration detects my smart plug but won't connect to it. The plug is visible and I'm able to control it with the Tuya Smart app.

Logger: custom_components.localtuya.config_flow
Source: custom_components/localtuya/pytuya/__init__.py:1183
Integration: LocalTuya (documentation, issues)
First occurred: 00:44:34 (12 occurrences)
Last logged: 01:00:32

Unexpected exception: [Errno 113] Connect call failed ('192.168.0.203', 6668)
Traceback (most recent call last):
  File "/config/custom_components/localtuya/config_flow.py", line 595, 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
    interface = await pytuya.connect(
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 1183, in connect
    _, protocol = await loop.create_connection(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1076, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1060, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 969, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 501, in sock_connect
    return await fut
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 541, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('192.168.0.203', 6668)
kavaleff commented 1 year ago

Similar error while trying to add a Temp&Hum sensor. Sensor visible in App and Tuya IOT platform. Latest HA 2023.6.1

This error originated from a custom integration.

Logger: custom_components.localtuya.config_flow Source: custom_components/localtuya/pytuya/init.py:1182 Integration: LocalTuya integration (documentation, issues) First occurred: 10:10:15 (4 occurrences) Last logged: 10:24:15

Unexpected exception: [Errno 110] Connect call failed ('192.168.2.18', 6668) Unexpected exception: [Errno 113] Connect call failed ('192.168.2.18', 6668) Traceback (most recent call last): File "/config/custom_components/localtuya/config_flow.py", line 595, 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 interface = await pytuya.connect( ^^^^^^^^^^^^^^^^^^^^^ File "/config/customcomponents/localtuya/pytuya/init.py", line 1182, in connect , protocol = await loop.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1085, in create_connection raise exceptions[0] File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1069, in create_connection sock = await self._connect_sock( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/base_events.py", line 973, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect return await fut ^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 674, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') TimeoutError: [Errno 110] Connect call failed ('192.168.2.18', 6668)

jnpetersen commented 1 year ago

I'm getting the same error:

Unexpected exception: [Errno 113] Connect call failed ('192.168.20.229', 6668)
Traceback (most recent call last):
  File "/config/custom_components/localtuya/config_flow.py", line 595, 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
    interface = await pytuya.connect(
                ^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 1182, in connect
    _, protocol = await loop.create_connection(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1085, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1069, in create_connection
    sock = await self._connect_sock(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 973, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 674, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('192.168.20.229', 6668)

I did notice that for this one device I'm having issues adding using localtuya that the local_key appears to have special characters in it versus what I remember really only being letters and numbers. I hope that helps in finding a fix for this.

In my instance, there are these special characters ~, <, +, and !.

STUKguy commented 1 year ago

Im getting the same issue, did anyone find a resolution?

niemenjoki commented 1 year ago

Im getting the same issue, did anyone find a resolution?

I never found a solution. I threw the plug into my bin of unused tech and decided to never buy another Tuya product again.

STUKguy commented 1 year ago

Im getting the same issue, did anyone find a resolution?

I never found a solution. I threw the plug into my bin of unused tech and decided to never buy another Tuya product again.

Strangely this is the only Tuya device I have had an issue with, every other sensor I have connected fine.

yxb2018 commented 11 months ago

It is used normally in version 5.0, and the same problem occurs when updating the latest version 5.2.1

Logger: custom_components.localtuya.config_flow Source: custom_components/localtuya/pytuya/init.py:1182 Integration: LocalTuya integration (documentation, issues) First occurred: 05:01:33 (10 occurrences) Last logged: 05:29:26

Unexpected exception: [Errno 113] Connect call failed ('10.0.0.185', 6668) Traceback (most recent call last): File "/config/custom_components/localtuya/config_flow.py", line 595, 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 interface = await pytuya.connect( ^^^^^^^^^^^^^^^^^^^^^ File "/config/customcomponents/localtuya/pytuya/init.py", line 1182, in connect , protocol = await loop.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1085, in create_connection raise exceptions[0] File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1069, in create_connection sock = await self._connect_sock( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/base_events.py", line 973, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect return await fut ^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 674, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') OSError: [Errno 113] Connect call failed ('10.0.0.185', 6668)

STUKguy commented 11 months ago

It is used normally in version 5.0, and the same problem occurs when updating the latest version 5.2.1

Logger: custom_components.localtuya.config_flow Source: custom_components/localtuya/pytuya/init.py:1182 Integration: LocalTuya integration (documentation, issues) First occurred: 05:01:33 (10 occurrences) Last logged: 05:29:26

Unexpected exception: [Errno 113] Connect call failed ('10.0.0.185', 6668) Traceback (most recent call last): File "/config/custom_components/localtuya/config_flow.py", line 595, 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 interface = await pytuya.connect( ^^^^^^^^^^^^^^^^^^^^^ File "/config/customcomponents/localtuya/pytuya/init.py", line 1182, in connect , protocol = await loop.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1085, in create_connection raise exceptions[0] File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1069, in create_connection sock = await self._connect_sock( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/base_events.py", line 973, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect return await fut ^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 674, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') OSError: [Errno 113] Connect call failed ('10.0.0.185', 6668)

Yeah I ended relegating this door sensor to fish tank feeder duty, waiting for sonoff door sensors to come down in price.

Onellan commented 11 months ago

I have 10 Tuya devices and ALL of them fail to get added to TuyaLocal with this error. I was wondering whether I had a network issue till I found this thread.

jnpetersen commented 11 months ago

So, the past few days I’ve been trying to figure out and diagnose the issue… I can’t seem to figure it out. I ended up finding that Node-Red (which I have already running) has a localtuya add on, which I tried out using the same device id and local key and it works just fine. I then created an entity in node-red that shows up as a home assistant entity so I could control the device I need still with other automations or through the home assistant portal.

I’m going to see about looking through both sets of code to see if I see any differences, but thought I’d give people a heads up if they really need to get something working. I know its a few extra steps, but its working, and it got me thinking that maybe I might change my most needed switches to this route so if home assistant stops working, my automations can still run.

sourceomatic commented 11 months ago

I have 10 Tuya devices and ALL of them fail to get added to TuyaLocal with this error. I was wondering whether I had a network issue till I found this thread.

Are you me? I'm in the same boat.

And to make things more annoying, I'm new to HA and HAOS... plus, I have two VLANs (a regular one for PCs, and a dedicated IOT VLAN), which complicates things a bit. Not knowing what traffic wasn't making it to where, I tried every networking trick-in-the-book I know (admittedly, I'm no routing & bridging engineer), and was about to pull my hair out.

The very presence of the exception in the logs, and this thread's existence, makes me think I'm marginally less useless than I was starting to believe. Yay, modicum of self-esteem!!

frgazor commented 9 months ago

I'm another one with this problem

I have 2 aubess power sockets. One works fine and one is giving me headaches.

Port 6668 is open on problematic device:

Nmap scan report for wlan0 (192.168.2.188) Host is up (0.0025s latency). Not shown: 65534 closed tcp ports (conn-refused) PORT STATE SERVICE 6668/tcp open irc

LocalTuya actually will connect sometimes if I leave settings window alone for a while and then send the settings, but device or entities will not be created.

Editing of device is possible, but again, no device or entities will be visible.

image

frgazor commented 9 months ago

Manually edited core.config_entries and added proper values for second socket, restarted HomeAssistant and no more Unexpected exception: [Errno 113] Connect call failed ('192.168.2.188', 6668) for me.

Always be careful when editing core.config_entries as you are not supposed to do that. I had to fix all LocalTuya entries after HA restart.

t0mc1k commented 8 months ago

I had the same problem with the WIFI bulb. It worked like this: Add the device to the tuya app and pair it in IOT tuya The device must be on - online When adding to LocalTuya in HA: Name - must be the same as the device name in IOT tuya Correct IP address (will find itself) Device ID (you can find it in IOT tuya) LocalKey (you can find it in IOT tuya - cloud - api explorer - device management - Query Device Details in Bulk)

and click Submit Further configuration depends on the device.

Engineer200 commented 7 months ago

I'm sick too. Does this error occur if the device name is not set in Latin, but in Arabic or Chinese layout?

Lyle101 commented 7 months ago

我的涂鸦智能插排第一次添加时也出现了,我的解决办法:将涂鸦插排插头从电源插座上拔下来,重新插上去(重新上下电),然后重新添加就可以了

Klikini commented 6 months ago

I think there's some more information about the cause of this in #1513 (non-alphanumeric characters in the password)

GillesMattioli commented 6 months ago

I had the same problem with the WIFI bulb. It worked like this: Add the device to the tuya app and pair it in IOT tuya The device must be on - online When adding to LocalTuya in HA: Name - must be the same as the device name in IOT tuya Correct IP address (will find itself) Device ID (you can find it in IOT tuya) LocalKey (you can find it in IOT tuya - cloud - api explorer - device management - Query Device Details in Bulk)

and click Submit Further configuration depends on the device.

Hey , Don't Find the Local Key

dzabel commented 5 months ago

The special characters are not the problem with my t&h sensor, but the fact that it is only sporadically "online" and apparently does not propagate all the information. I was able to add my t&h seonsor using this guide: https://community.simon42.com/t/ha-tuya-local-sensor-einbinden-klapt-nicht/7038/7

Following this article, the modification in localtuya part of my core.config_entries looks:

            "<my_device_id>": {
              "friendly_name": "T&H Sensor",
              "host": "192.168.x.x",
              "local_key": "<my_local_key>",
              "protocol_version": "3.4",
              "enable_debug": false,
              "manual_dps_strings": "1,2,3",
              "entities": [
                {
                  "friendly_name": "Box_Temperatur",
                  "unit_of_measurement": "°C",
                  "device_class": "temperature",
                  "scaling": 0.1,
                  "id": 1,
                  "platform": "sensor"
                },
                {
                  "friendly_name": "Box_Humidity",
                  "device_class": "humidity",
                  "unit_of_measurement": "%",
                  "id": 2,
                  "platform": "sensor"
                },
                {
                  "friendly_name": "Box_Battery",
                  "device_class": "battery",
                  "id": 3,
                  "platform": "sensor"
                }
              ],
              "add_entities": false,
              "device_id": "<device_id>",
              "dps_strings": [
                "1 (value: 214)",
                "2 (value: 51)",
                "3 (value: high)"
              ],
              "product_key": "lf36y5nwb8jkxwgg"
            }

I was also able to add the device in the UI - but i had to fill "Manual DPS to add" field with "1,2,3", otherwise the discovery of the device was not working im my case. (I did this running a ping command to the IP in background and clicking add when the device respond to the ping. The device will go online (being available) for a few seconds only - if the state (temperature or humidity) change.

Hope this helps

insane2subro commented 5 months ago

Ok I found a solution. Its unable to connect to the sensor cause the sensor goes to deep sleep. While adding it to Local Tuya if its for example a contact sensor keep triggering it to keep the wifi active so Local Tuya can pair it.

FranciscoII commented 3 months ago

Same here. I have to trigger the sensor in order to add this to LocalTuya. Never buying anything from Tuya again 😅

bernardolm commented 3 weeks ago

None of these solutions worked for me 😞