localtuya icon indicating copy to clipboard operation
localtuya copied to clipboard

Local connection not restored after device dropped off line for a short time

Open snigehere opened this issue 2 years ago • 15 comments

The problem

Recently local tuya devices have stated being unavailable while being online in the smart life app. Restarting the integration will bring the device back available again.

Further investigation reveals that the device goes off line for a short while and when it comes back online again the local integration does not recover the device.

Environment

Windows 10 running Oracle Virtual box Version 6.1.38 r153438 (Qt5.6.2)

Last working localtuya version Unknown - Last month or so Home Assistant 2022.10.5 Supervisor 2022.10.0 Operating System 9.2 Frontend 20221010.0 - latest Local Tuya v4.1.1 Home Assistant localTuya only (no Cloud component) I use the smartlife app if I have issues with Home Assistant

Steps to reproduce

Device goes off line for local reason - power / network / etc Network monitor (prtg) reports device off line Device unavailable in Home Assistant and SmartLife Device recovers or is recovered Network monitor (prtg) reports device online SmartLife app shows device back online Home assistant continues to report an error

Configuration configuration.yaml or config_flow


DP dump

Provide Home Assistant taceback/logs

Logger: custom_components.localtuya.common Source: custom_components/localtuya/pytuya/init.py:704 Integration: LocalTuya integration (documentation, issues) First occurred: 16:44:44 (63 occurrences) Last logged: 17:46:44

[070...676] Connect to 192.168.0.199 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/custom_components/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.0.199', 6668)

Logbook 23 October 2022 Tree became unavailable 20:54:27 - 2 hours ago Tree turned on 20:53:28 - 2 hours ago Tree became unavailable 20:53:14 - 2 hours ago Tree turned on 20:52:05 - 2 hours ago Tree became unavailable 20:52:01 - 2 hours ago Tree turned on 20:51:56 - 2 hours ago

{ "home_assistant": { "installation_type": "Home Assistant OS", "version": "2022.10.5", "dev": false, "hassio": true, "virtualenv": false, "python_version": "3.10.5", "docker": true, "arch": "x86_64", "timezone": "Europe/London", "os_name": "Linux", "os_version": "5.15.72", "supervisor": "2022.10.0", "host_os": "Home Assistant OS 9.2", "docker_version": "20.10.17", "chassis": "vm", "run_as_root": true }, "custom_components": { "hacs": { "version": "1.28.2", "requirements": [ "aiogithubapi>=22.2.4" ] }, <-----------snip ----------> "localtuya": { "version": "4.1.1", "requirements": [] } }, "integration_manifest": { "domain": "localtuya", "name": "LocalTuya integration", "version": "4.1.1", "documentation": "https://github.com/rospogrigio/localtuya/", "dependencies": [], "codeowners": [ "@rospogrigio", "@postlund" ], "issue_tracker": "https://github.com/rospogrigio/localtuya/issues", "requirements": [], "config_flow": true, "iot_class": "local_push", "is_built_in": false }, "data": { "device_config": { "friendly_name": "Tree", "local_key": "xxxxxxxxxxxxxx", "host": "192.168.0.199", "device_id": "xxxxxxxxxxxxxxxxxx", "protocol_version": "3.3", "product_key": "xxxxxxxxxxxxxxxxxxx", "dps_strings": [ "1 (value: False)", "2 (value: colour)", "3 (value: 255)", "4 (value: 102)", "5 (value: 00ff000078ffff)", "6 (value: 00ff0000000000)", "7 (value: ffff320100ff00)", "8 (value: ffff5003ff000000ff000000ff)", "9 (value: ffff3201ff0000)", "10 (value: ffff0505ff000000ff00ffff00ff00ff0000ff)" ], "entities": [ { "id": 1, "friendly_name": "Tree", "brightness_lower": 29, "brightness_upper": 1000, "color_temp_min_kelvin": 2700, "color_temp_max_kelvin": 6500, "color_temp_reverse": false, "music_mode": false, "brightness": 3, "color_temp": 4, "color_mode": 2, "color": 5, "scene": 6, "platform": "light" } ] } } }

## Additional information
My local network monitor (PRTG) detected the device going off line and it coming back on again

snigehere avatar Oct 23 '22 22:10 snigehere

home_assistant_tree_light_prtg

snigehere avatar Oct 23 '22 22:10 snigehere

I'm experience the same behavior here. It's get dropped and don't get back but when checking with tuya app everything is working fine from there so I guess the re-connection isn't working.

GhostNr1 avatar Oct 25 '22 06:10 GhostNr1

Same here. Not with all devices. A few never disconnect, others do very often. I had a smart bulb that worked perfectly well when connected, but checking the logbook it kept becoming unavailable/available. I replaced it with a Tuya dimmer, and see similar behavior to the one described on this issue, once it became unavailable, it didn't reconnect until restarting the integration. Also, any idea why it becomes unavailable on the 1st place?

babelhoo avatar Oct 25 '22 13:10 babelhoo

Had the same problem. For now, downgrading to 4.0.2 solved the issue for me.

FragMenthor avatar Oct 25 '22 14:10 FragMenthor

Had the same problem. For now, downgrading to 4.0.2 solved the issue for me.

Sorry for the possibly dumb question: how do you downgrade a single HA integration (other than reverting to a backup)?

babelhoo avatar Oct 25 '22 14:10 babelhoo

Had the same problem. For now, downgrading to 4.0.2 solved the issue for me.

Sorry for the possibly dumb question: how do you downgrade a single HA integration (other than reverting to a backup)?

In HACS, select localtuya integration, then 3 dots upper right corner, Redownload, and choose the version you want.

FragMenthor avatar Oct 25 '22 16:10 FragMenthor

In HACS, select localtuya integration, then 3 dots upper right corner, Redownload, and choose the version you want.

Thanks!!!

babelhoo avatar Oct 25 '22 20:10 babelhoo

Same problem here.

stuckis6er avatar Oct 25 '22 22:10 stuckis6er

... Also, any idea why it becomes unavailable on the 1st place?

For me its just a general network drop of some kind - the devices that drop are typically distant ones and external so network interference or noise beyond my control. I run PRTG as a network monitor so get alerted if devices drop and when the come back .. normally this short drop would not be noticed otherwise .. the SmartLife app picks it back up when it comes back online but the integration in HA does not.

snigehere avatar Oct 25 '22 23:10 snigehere

Same problem here!

Update!| After downgrading to 4.0.2, everything works perfectly for me

josephgeorgep avatar Oct 26 '22 08:10 josephgeorgep

To work around and monitor this issue for now, I created an automation that reloads local tuya and sends my phone a notification. It is triggered by any tuya local device becoming unavailable for 2 minutes. This is an alternative option to downgrading.

foxymichelle avatar Oct 26 '22 14:10 foxymichelle

To work around and monitor this issue for now, I created an automation that reloads local tuya and sends my phone a notification. It is triggered by any tuya local device becoming unavailable for 2 minutes. This is an alternative option to downgrading.

Can you share it?

babelhoo avatar Oct 26 '22 18:10 babelhoo

Sure - here you go. I got my first notice an hour after setting this up - the light that has been becoming unavailable most the last few days had bugged out again, and this worked perfect to fix the connection before I'm doing it manually, annoyed that it's not responding. I'll delete the notification bit if it gets annoying

alias: Restart for TuyaLocal
description: ""
trigger:
  - platform: state
    entity_id:
      - light.garage_light_tuya
      - light.dining_light_tuya
      - continue listing your devices
    to: unavailable
    for:
      hours: 0
      minutes: 2
      seconds: 0
condition: []
action:
  - service: notify.mobile_app_your_phone
    data:
      message: Reloaded Tuya Local
  - service: localtuya.reload
    data: {}
mode: restart

foxymichelle avatar Oct 26 '22 19:10 foxymichelle

Sure - here you go. ...

Thanks! I'll give it a try

babelhoo avatar Oct 26 '22 19:10 babelhoo

Same problem here!

Update!| After downgrading to 4.0.2, everything works perfectly for me

It worked for me for a while (2-3 days). Suddenly the problem returned... Unstable now in any 4.x.x version. This is driving me nuts, because it has been working for me for almost 2 years; all my system depends on this, soooo..... i'm really screwed, lol.

This is my "offline device counter":

image

1-2 devices offline is normal for me, I have a doorbell that never quite worked 100%, and other device has weak wireless connection. now, it's chaos... only come back after a complete HA restart, using the restart service doesn't fix this for me, althought they are available to control in Smartlife app.

FragMenthor avatar Oct 28 '22 16:10 FragMenthor