Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disconnect Tuya Device #160

Open
ranrinc opened this issue Nov 17, 2020 · 18 comments
Open

Disconnect Tuya Device #160

ranrinc opened this issue Nov 17, 2020 · 18 comments
Labels
bug Something isn't working

Comments

@ranrinc
Copy link

ranrinc commented Nov 17, 2020

HA: 0.117.6
Latest: localtuya from master

Upon updating to 0.117.6 from time-to-time my tuya device is just disconnected and will not interact with HA. For example my multiplugs appear to be online but I will not be able to switch on/off and this happen to bulb too. After reboot HA everything will work as is. So I believe the device did disconnect after sometimes.

also getting this error messages

2020-11-17 13:23:55 ERROR (MainThread) [custom_components.localtuya.common] Connect to 192.168. failed
Traceback (most recent call last):
  File "/config/custom_components/localtuya/common.py", line 140, in _make_connection
    self._interface = await pytuya.connect(
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 593, in connect
    _, protocol = await loop.create_connection(
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1025, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 496, in sock_connect
    return await fut
  File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 528, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('192.168.', 6668)
@postlund
Copy link
Collaborator

Can you install the latest release from master and try again? If the same thing happens, enable debug logging and attach logs here.

https://github.com/rospogrigio/localtuya#debugging

@postlund postlund added the bug Something isn't working label Nov 17, 2020
@ranrinc
Copy link
Author

ranrinc commented Nov 18, 2020

Can you install the latest release from master and try again? If the same thing happens, enable debug logging and attach logs here.

https://github.com/rospogrigio/localtuya#debugging

Currently I'm running on master.. but unsure if I got the latest one.. will try to replace it with the current one and will let you know. Thanks man.

@postlund
Copy link
Collaborator

Merged a few things yesterday, so you might not have those changes.

@ranrinc
Copy link
Author

ranrinc commented Nov 20, 2020

Merged a few things yesterday, so you might not have those changes.

Update my HA to 0.118 and update master however, it continues to have 2 multi-outlet disconnected after several hours. Restart HA will bring the device back but that's it. Unsure the logs since there is no error on that end

@drinfernoo
Copy link

drinfernoo commented Nov 21, 2020

I'm having a similar error, whether integrated via config flow or YAML... An example of one of my lights:

2020-11-20 18:15:06 ERROR (MainThread) [custom_components.localtuya.common] [464...fd0] Connect to 192.168.1.247 failed
Traceback (most recent call last):
File "/config/custom_components/localtuya/common.py", line 146, in _make_connection
self._interface = await pytuya.connect(
File "/config/custom_components/localtuya/pytuya/__init__.py", line 626, in connect
_, protocol = await loop.create_connection(
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1025, in create_connection
raise exceptions[0]
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection
sock = await self._connect_sock(
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 496, in sock_connect
return await fut
File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 528, in _sock_connect_cb
raise OSError(err, f'Connect call failed {address}')
ConnectionResetError: [Errno 104] Connect call failed ('192.168.1.247', 6668)

This happens whenever I restart Home Assistant, and most of my added entities become unavailable. Sometimes reloading their respective integrations works, but also sometimes not.

I also get these messages in the log for lights that don't connect:

2020-11-20 18:15:12 WARNING (SyncWorker_22) [custom_components.localtuya.light] [464...fd0] Entity light.back_porch is requesting unknown DPS index 1
2020-11-20 18:15:12 WARNING (SyncWorker_22) [custom_components.localtuya.light] [464...fd0] Entity light.back_porch is requesting unknown DPS index 4
2020-11-20 18:15:12 WARNING (SyncWorker_22) [custom_components.localtuya.light] [464...fd0] Entity light.back_porch is requesting unknown DPS index 5
2020-11-20 18:15:12 WARNING (SyncWorker_22) [custom_components.localtuya.light] [464...fd0] Entity light.back_porch is requesting unknown DPS index 3
2020-11-20 18:15:12 WARNING (SyncWorker_22) [custom_components.localtuya.light] [464...fd0] Entity light.back_porch is requesting unknown DPS index 2
2020-11-20 18:15:12 WARNING (SyncWorker_22) [custom_components.localtuya.light] [464...fd0] Entity light.back_porch is requesting unknown DPS index 2

For what it's worth, I'm on HA 0.118.1 and localtuya from the latest commit at this time: 5668595.

@postlund
Copy link
Collaborator

I can reproduce the issue myself now and I'm working on it, but it's a bit tricky. Will hopefully come up with a solution soon.

@postlund
Copy link
Collaborator

Would he great if you can test #177. Hopefully smooth sailing ⛵️

@ranrinc
Copy link
Author

ranrinc commented Nov 23, 2020

Would he great if you can test #177. Hopefully smooth sailing ⛵️

How do I test this one? since its said out of date?

@drinfernoo
Copy link

drinfernoo commented Nov 24, 2020

I've updated to 3.1.0, and all but one of my lights are working consistently (actually the same case as with 5668595). It seems I can add this light successfully via the config flow (entity works just fine), but not via YAML, as the entity consistently stays unavailable.

On the previous version, I had almost the opposite results (for all but this light), which means all but this one light are now integrated via YAML, and working...

This one light I'm having an issue with is a Merkury bulb, which doesn't have color temperature, so I'm simply not setting a DP for it (on my other bulbs I use DP4 for this), if that matters.

It looks like if I remove it from my YAML, and then add it again through config flow, it works.

@ranrinc
Copy link
Author

ranrinc commented Nov 30, 2020

Update both HA and LocalTuya to the latest.. Still having the same issue..disconnected after several hours or minutes

@ultratoto14
Copy link
Collaborator

@drinfernoo can you put a DP dump there for your Merkury bulb ?
@ranrinc are your device always on and use logical on/off or are they physically off sometimes like a bulb switched off via physical wall switch ?

@ranrinc
Copy link
Author

ranrinc commented Nov 30, 2020

@drinfernoo can you put a DP dump there for your Merkury bulb ?
@ranrinc are your device always on and use logical on/off or are they physically off sometimes like a bulb switched off via physical wall switch ?

its always on and even though the device being disconnected its status remain. Just that from HA the device is post as disconnect until I restart HA.

@DavidFFerreira
Copy link

DavidFFerreira commented Dec 4, 2020

@ultratoto14 I did experience that today. I turn off all bulbs (but remain connected to netowrk), after wake up I realise when I turn on the bulbs, 2 of them disconnected during night and dont update the status. But in Tuya Custom and on smartlife they both connected and working proprely. I was able to reload the bulb in your integration, but only after reload I was able to mess with the bulb again with your integration

Logger: custom_components.localtuya.common
Source: custom_components/localtuya/pytuya/init.py:239
Integration: LocalTuya integration (documentation, issues)
First occurred: 1:33:42 (12 occurrences)
Last logged: 5:54:34

[680...406] Connect to 192.168.1.XXX failed
[218...3ae] Connect to 192.168.1.XXX failed
[738...fd0] Connect to 192.168.1.XXX failed
[660...67b] Connect to 192.168.1.XXX failed
[680...403] Connect to 192.168.1.XXX failed
Traceback (most recent call last):
File "/config/custom_components/localtuya/common.py", line 156, in _make_connection
status = await self._interface.status()
File "/config/custom_components/localtuya/pytuya/init.py", line 461, in status
status = await self.exchange(STATUS)
File "/config/custom_components/localtuya/pytuya/init.py", line 456, in exchange
return await self.exchange(command, dps)
File "/config/custom_components/localtuya/pytuya/init.py", line 440, in exchange
msg = await self.dispatcher.wait_for(seqno)
File "/config/custom_components/localtuya/pytuya/init.py", line 239, in wait_for
await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
File "/usr/local/lib/python3.8/asyncio/tasks.py", line 498, in wait_for
raise exceptions.TimeoutError()
asyncio.exceptions.TimeoutError

DEBUG

2020-12-04 04:50:45 DEBUG (MainThread) [custom_components.localtuya.pytuya] [680...a94] Dispatching message TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211)
2020-12-04 04:50:45 DEBUG (MainThread) [custom_components.localtuya.pytuya] [680...a94] Got heartbeat response
2020-12-04 04:50:45 DEBUG (MainThread) [custom_components.localtuya.pytuya] [680...a94] Decrypted payload: {}
2020-12-04 04:50:49 DEBUG (MainThread) [custom_components.localtuya.common] [218...234] Connecting to 192.168.1.XXX
2020-12-04 04:50:52 ERROR (MainThread) [custom_components.localtuya.common] [218...234] Connect to 192.168.1.XXX failed
Traceback (most recent call last):
File "/config/custom_components/localtuya/common.py", line 146, in _make_connection
self._interface = await pytuya.connect(
File "/config/custom_components/localtuya/pytuya/init.py", line 626, in connect
_, protocol = await loop.create_connection(
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1025, in create_connection
raise exceptions[0]
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection
sock = await self._connect_sock(
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 496, in sock_connect
return await fut
File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 528, in _sock_connect_cb
raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('192.168.1.XXX', 6668)
2020-12-04 04:50:52 DEBUG (MainThread) [custom_components.localtuya.common] [218...234] Connecting to 192.168.1.XXX
2020-12-04 04:50:52 DEBUG (MainThread) [custom_components.localtuya.common] [218...234] Waiting 300 seconds before connecting
2020-12-04 04:51:00 DEBUG (MainThread) [custom_components.localtuya.pytuya] [680...acf] Sending command heartbeat (device type: type_0a)
2020-12-04 04:51:00 DEBUG (MainThread) [custom_components.localtuya.pytuya] [680...acf] Send payload: b'{}'
2020-12-04 04:51:00 DEBUG (MainThread) [custom_components.localtuya.pytuya] [680...acf] Waiting for sequence number -100
2020-12-04 04:51:00 DEBUG (MainThread) [custom_components.localtuya.pytuya] [680...acf] Dispatching message TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211)
2020-12-04 04:51:00 DEBUG (MainThread) [custom_components.localtuya.pytuya] [680...acf]

@ultratoto14
Copy link
Collaborator

ultratoto14 commented Dec 4, 2020

@DavidFFerreira for lights with physical switches, this PR should be helpful, if you want to try: #171
Also be advised that many of TUYA devices support only one connection at a time. It means that using the Tuya app on mobile phone may prevent HA to work with them.

⚠️ Be careful, this changes your devices in registry. I mean you may need to remove and recreate devices if you go back to master afterwards. If you have plenty of devices, i would recommend you to save your configuration in yaml instead of config_flow.

@DavidFFerreira
Copy link

@ultratoto14 thanks, and yes, I have alot of devices :D

@drinfernoo
Copy link

drinfernoo commented Dec 7, 2020

For me, it seems that whenever a bulb loses connection, I can turn it off, but the state doesn't update, so I can't turn it back on.

It does seem that if a light, which isn't updating correctly, is off (but the state is still "on"), and I change the brightness (turning the light on), then turning it off again does update the state. However, the same thing happens again if I then turn it back on again.

@MickPBduece
Copy link

I added one mini-plug on first try with the scan method. Works very good except I need to reload the integration after restarting HA but that might be my slightly off standard setup too. I really hope at some point I can be a contributor in addition to being a consumer

@MickPBduece
Copy link

Installed v 3.3 and it seems that the restart thingy is fixed. I wish I had tried this before returning box loads of Black Friday cheap wall switches! Oh well. All is good - Thanks Again!

PaulCavill pushed a commit to PaulCavill/localtuya that referenced this issue May 9, 2024
PaulCavill pushed a commit to PaulCavill/localtuya that referenced this issue May 9, 2024
* Fix an issue where adding new device integeration won't load up.
* Refactor quick reconnect method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants