rospogrigio / localtuya

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

Tuya devices contantly become unavailable #1530

Open Unwrapped3 opened 9 months ago

Unwrapped3 commented 9 months ago

The problem

I have multiple tuya smart lights at home. All of them periodically become unavailable in HA. Basically every day with rare exception I need to disconenct them from power, connect to the socket again, then use Start Life app to turn on and off agai and only then they become available in HA again for another few days. I am not sure wether it is an issue with all tuya devices or just lights because I only one other tuya device, a T&H sensor, that is super cheap and works very poorly anyways. However, logs show that the connection is being dropped with it as well.

Environment

SmartLife is used only to reconnect a unavailable device. Also access from all tuya devices is blocked on my router and pihole.

Steps to reproduce

  1. Connect smart lights;
  2. Sett them up;
  3. Check if the whole functionality works;
  4. Wait a few days;
  5. It is broken again.

DP dump

Device xxxxx at 192.168.178.xxx key xxxxx protocol 3.3 dev_type type_0a: DPS [20] VALUE [True] DPS [21] VALUE [white] DPS [22] VALUE [658] DPS [23] VALUE [800] DPS [26] VALUE [0] root@Wizard:~/tuyadebug#

Provide Home Assistant traceback/logs

2023-10-17 20:01:01.911 WARNING (MainThread) [custom_components.localtuya.common] [bf8...o8p] Failed to connect to 192.168.178.106: [Errno 113] Connect call failed ('192.168.178.106', 6668)
2023-10-17 20:01:01.911 WARNING (MainThread) [custom_components.localtuya.common] [bf9...m1n] Failed to connect to 192.168.178.159: [Errno 113] Connect call failed ('192.168.178.159', 6668)
2023-10-17 20:01:01.911 WARNING (MainThread) [custom_components.localtuya.common] [bf4...rm3] Failed to connect to 192.168.178.162: [Errno 113] Connect call failed ('192.168.178.162', 6668)
2023-10-17 20:02:01.879 WARNING (MainThread) [custom_components.localtuya.common] [bf8...o8p] Failed to connect to 192.168.178.106: [Errno 113] Connect call failed ('192.168.178.106', 6668)
2023-10-17 20:02:01.879 WARNING (MainThread) [custom_components.localtuya.common] [bf9...m1n] Failed to connect to 192.168.178.159: [Errno 113] Connect call failed ('192.168.178.159', 6668)
2023-10-17 20:02:01.880 WARNING (MainThread) [custom_components.localtuya.common] [bf4...rm3] Failed to connect to 192.168.178.162: [Errno 113] Connect call failed ('192.168.178.162', 6668)
2023-10-17 20:03:01.911 WARNING (MainThread) [custom_components.localtuya.common] [bf8...o8p] Failed to connect to 192.168.178.106: [Errno 113] Connect call failed ('192.168.178.106', 6668)
2023-10-17 20:03:01.912 WARNING (MainThread) [custom_components.localtuya.common] [bf9...m1n] Failed to connect to 192.168.178.159: [Errno 113] Connect call failed ('192.168.178.159', 6668)
2023-10-17 20:03:01.913 WARNING (MainThread) [custom_components.localtuya.common] [bf4...rm3] Failed to connect to 192.168.178.162: [Errno 113] Connect call failed ('192.168.178.162', 6668)
2023-10-17 20:04:01.879 WARNING (MainThread) [custom_components.localtuya.common] [bf8...o8p] Failed to connect to 192.168.178.106: [Errno 113] Connect call failed ('192.168.178.106', 6668)
2023-10-17 20:04:01.880 WARNING (MainThread) [custom_components.localtuya.common] [bf9...m1n] Failed to connect to 192.168.178.159: [Errno 113] Connect call failed ('192.168.178.159', 6668)
2023-10-17 20:04:01.880 WARNING (MainThread) [custom_components.localtuya.common] [bf4...rm3] Failed to connect to 192.168.178.162: [Errno 113] Connect call failed ('192.168.178.162', 6668)
2023-10-17 20:05:01.911 WARNING (MainThread) [custom_components.localtuya.common] [bf8...o8p] Failed to connect to 192.168.178.106: [Errno 113] Connect call failed ('192.168.178.106', 6668)
2023-10-17 20:05:01.911 WARNING (MainThread) [custom_components.localtuya.common] [bf9...m1n] Failed to connect to 192.168.178.159: [Errno 113] Connect call failed ('192.168.178.159', 6668)
2023-10-17 20:05:01.912 WARNING (MainThread) [custom_components.localtuya.common] [bf4...rm3] Failed to connect to 192.168.178.162: [Errno 113] Connect call failed ('192.168.178.162', 6668)
2023-10-17 20:06:01.879 WARNING (MainThread) [custom_components.localtuya.common] [bf8...o8p] Failed to connect to 192.168.178.106: [Errno 113] Connect call failed ('192.168.178.106', 6668)
2023-10-17 20:06:01.880 WARNING (MainThread) [custom_components.localtuya.common] [bf9...m1n] Failed to connect to 192.168.178.159: [Errno 113] Connect call failed ('192.168.178.159', 6668)
2023-10-17 20:06:01.881 WARNING (MainThread) [custom_components.localtuya.common] [bf4...rm3] Failed to connect to 192.168.178.162: [Errno 113] Connect call failed ('192.168.178.162', 6668)

I would highly appreciate any help! Cheers!

Spikey72 commented 9 months ago

Are you using the Local Tuya integration with HomeKit Bridge to have them integrated within Apple ecosystem? Mine have also gone offline last night and not responding now. SmartLife app still can communicate with lights…

Unwrapped3 commented 9 months ago

Are you using the Local Tuya integration with HomeKit Bridge to have them integrated within Apple ecosystem? Mine have also gone offline last night and not responding now. SmartLife app still can communicate with lights…

Nope, no bridge whatsoever. In my case, when they go offline, SmartLife can't communicate with them either. I need to disconnect them from power, then SmartLife is able to connect again. And only after that, they can get managed by HA.

I've read in tuyalocal description that it happens sometimes when tuya devices can't communicate with tuya servers for a certain amount of time. Not sure if it is the case with local tuya as well.

JaviVelascoG commented 9 months ago

I have the same problem. Whith all my devices. Lights, curtains and thermostast. I need to restart homeassistant to work again.

Home Assistant core 2023.7.3

Screenshot_2023-10-22-16-58-53-325_io homeassistant companion android

srusinov commented 9 months ago

Same issue on my setup as well. After day or two all devices get disconnected. HA restart fixes the issue.

Unwrapped3 commented 9 months ago

Same issue on my setup as well. After day or two all devices get disconnected. HA restart fixes the issue.

In my case restarting HA does not fix the issue. The only solution I've found so far is disconnecting the lights from power thus forcing a reboot, then executing one command in SmartLife. Only then they become available again.

MooseV2 commented 9 months ago

I have an interesting issue where the lights become unavailable through HA, but I can still control them from HomeKit via HomeKit Bridge. They are also available through the SmartLife / Tuya app so it seems the issue lies in the actual LocalTuya <-> HA UI integration.

noodlenoggan commented 9 months ago

Home Assistant 2023.10.5 Supervisor 2023.10.1 Operating System 11.1 Frontend 20231005.0 - latest

Same as others. A reboot of HA brings them back. They are all working fine in Smartlife. Items that I left to use Tuya cloud stays connected in HA while LocalTuya shows it disconnected.

Memo654 commented 9 months ago

Same as others.They are all working fine in Smartlife and it works well in the tuya cloud add-on.

Unwrapped3 commented 9 months ago

I think the problem is the hardware. I've tried tuya local integration and the issue remains the same.

What also makes me think it's hardware is that only certain devices become unavailable, whereas the others have been working for over a month without a single issue.

For reference

Lights that randomly become unavailable:

Lights that have been working correctly:

Would be interesting to see if the others having similar issues have the same products.

noodlenoggan commented 9 months ago

For me, it's all localtuya entities that are not working, not just some. A reboot of HA brings them back for awhile and then break again within a day

The same devices continue to work fine either with tuya in HA or in smart life during the same time they are not working in HA with localtuya.

Update: A recent update of HA has stabilized the connections. My localtuya entities are currently behaving.

Home Assistant

Core 2023.11.0

Supervisor 2023.10.1

Operating System 11.1

Frontend 20231030.1

Alberto0581 commented 8 months ago

Hello. I have the same problem from time to time, that entities become unavailable. Sometimes it's fixed by rebooting, but other times it doesn't. I've noticed that if you rename the project in io.tuya.com, all the devices work properly again without having to remove the power from the devices. I rename the project, reboot and everything works properly again

https://iot.tuya.com/cloud/basic?id=p1697620713686u7k9vv&region=EU&toptab=project&authorizeTab=0

Core 2023.11.2 Supervisor 2023.11.3 Operating System 11.1 Frontend 20231030.2

Memo654 commented 8 months ago

It looks like an integration issue, here is my log, normally it will understand the success and get the secret key, when it fails it will keep trying again.

success: 2023-11-15 19:52:40.151 DEBUG (MainThread) [custom_components.localtuya.discovery] Listening to broadcasts on UDP port 6666 and 6667 2023-11-15 19:52:40.634 INFO (MainThread) [custom_components.localtuya] Cloud API connection succeeded. 2023-11-15 19:52:42.295 INFO (MainThread) [Jellyfin] ---[ START JELLYFINCLIENT ]--- 2023-11-15 19:52:43.118 INFO (MainThread) [custom_components.localtuya.common] [6ce...bgy] Trying to connect to 192.168.100.127... 2023-11-15 19:52:43.372 INFO (MainThread) [custom_components.localtuya.common] [6ce...bgy] Successfully connected to 192.168.100.127 2023-11-15 19:52:44.198 DEBUG (MainThread) [custom_components.localtuya.discovery] Discovered device: {'ip': '192.168.100.127', 'gwId': '6ceea68ff1425e510dibgy', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'ugjbnqj2mffaexp5', 'version': '3.3'} fail: 2023-11-16 02:31:28.119 WARNING (MainThread) [custom_components.localtuya.common] [6ce...bgy] Disconnected - waiting for discovery broadcast 2023-11-16 02:31:28.549 INFO (MainThread) [custom_components.localtuya.common] [6ce...bgy] Trying to connect to 192.168.100.127... 2023-11-16 02:32:02.278 WARNING (MainThread) [custom_components.localtuya.common] [6ce...bgy] Failed to connect to 192.168.100.127: [Errno 113] Connect call failed ('192.168.100.127', 6668) 2023-11-16 02:32:03.637 INFO (MainThread) [custom_components.localtuya.common] [6ce...bgy] Trying to connect to 192.168.100.127... 2023-11-16 02:32:05.958 WARNING (MainThread) [custom_components.localtuya.common] [6ce...bgy] Failed to connect to 192.168.100.127: [Errno 113] Connect call failed ('192.168.100.127', 6668) 2023-11-16 02:32:08.588 INFO (MainThread) [custom_components.localtuya.common] [6ce...bgy] Trying to connect to 192.168.100.127...

Memo654 commented 8 months ago

它看起来像一个集成问题,这是我的日志,通常它会理解成功并获取密钥,当失败时它会继续尝试。

成功: 2023-11-15 19:52:40.151 DEBUG (MainThread) [custom_components.localtuya.discovery] 监听 UDP 端口 6666 和 6667 上的广播 2023-11-15 19:52:40.634 INFO (MainThread) [custom_components.localtuya 】 云API连接成功。 2023-11-15 19:52:42.295 信息(主线程)[Jellyfin] ---[ 启动 JELLYFINCLIENT ]--- 2023-11-15 19:52:43.118 信息(主线程)[custom_components.localtuya.common] [6ce ...bgy] 尝试连接到 192.168.100.127... 2023-11-15 19:52:43.372 INFO (MainThread) [custom_components.localtuya.common] [6ce...bgy] 成功连接到 192.168.100.127 2023 -11-15 19:52:44.198调试(主线程)[custom_components.localtuya.discovery]发现设备:{'ip':'192.168.100.127','gwId':'6ceea68ff1425e510dibgy','active':2,'ablilty ':0,'加密':True,'productKey':'ugjbnqj2mffaexp5','版本':'3.3'} 失败: 2023-11-16 02:31:28.119警告(主线程)[custom_components.localtuya.common] [ 6ce...bgy] 已断开连接 - 等待发现广播 2023-11-16 02:31:28.549 INFO (MainThread) [custom_components.localtuya.common] [6ce...bgy] 尝试连接到 192.168.100.127... 2023-11-16 02:32:02.278 警告(主线程)[custom_components.localtuya.common] [6ce...bgy] 无法连接到 192.168.100.127:[Errno 113] 连接调用失败('192.168.100.127', 6668) 2023-11-16 02:32:03.637 信息 (主线程) [custom_components.localtuya.common] [6ce...bgy] 尝试连接到 192.168.100.127... 2023-11-16 02:32:05.958警告(MainThread)[custom_components.localtuya.common] [6ce...bgy] 无法连接到 192.168.100.127:[Errno 113] 连接调用失败('192.168.100.127',6668)2023-11-16 02:32 :08.588 INFO(主线程)[custom_components.localtuya.common] [6ce...bgy] 尝试连接到 192.168.100.127...

I found the port has changed when it tried again later, which may be the problem.

user2705 commented 8 months ago

Hello. I have the same problem from time to time, that entities become unavailable. Sometimes it's fixed by rebooting, but other times it doesn't. I've noticed that if you rename the project in io.tuya.com, all the devices work properly again without having to remove the power from the devices. I rename the project, reboot and everything works properly again

https://iot.tuya.com/cloud/basic?id=p1697620713686u7k9vv&region=EU&toptab=project&authorizeTab=0

Core 2023.11.2 Supervisor 2023.11.3 Operating System 11.1 Frontend 20231030.2

Great, this workaround worked for me!

Chufur commented 8 months ago

hola, tengo el mismo problema con todas las entidades de localtuya

i8nemo commented 8 months ago

Have same problem. Certain devices come in and out of unavailable, even thought they work fine via tuya app.

Unwrapped3 commented 7 months ago

Allowing devices to access the web completely fixed the problem for me. Weird because they were blocked in both router and in my local DNS and still they were apparently entering the "zombie state" mentioned in the description.

fuchs-fabian commented 7 months ago

I actually have the same problem or the same problems. From time to time, all devices are simply no longer accessible.

Reloading the integration usually doesn't work. The only thing that often helps is restarting HomeAssistant. This usually solves the problem.

Some devices are often inaccessible for a long time and then suddenly become accessible again. This is probably due to the devices themselves.

Now, after the HomeAssistant Core update to 2023.11.3, I have a specific problem. Even a core update to 2023.12.1 did not solve the problem...

Incident

Today all devices were suddenly inaccessible. Even with the Hue Bridge, so that you can control them via Alexa, the devices no longer responded. Sometimes it's just a bug in HomeAssistant and strangely enough you can still control the devices via Alexa. But this time that wasn't the case.

After a restart, about half of the 37 devices were accessible again. However, a few were not. So I upgraded to Core 2023.12.1 as described above. No change. So I restarted the "router" (FritzBox). 2 devices were accessible again. Restarted the MiniPc on which the HomeAssistant is running, again no change. Restarted HomeAssistant again. Again no change. Reloading the LocalTuya integration in HACS did not help either.

The only way to make the devices accessible again was to make them accessible to the internet again (previously they were not accessible via the internet). I was then able to control the device again via SmartLife on my cell phone and lo and behold, the device was also available again in HomeAssistant. The LocalKey had not changed. Nothing else had changed either. I then blocked the smart device's internet access and it still works in HomeAssistant.

Unplugging the device or interrupting the power supply did not help to solve the problem either.

The only solution

Unlock the device for the Internet and then switch it on and off via SmartLife and then block Internet access again.

Cause of error and open question

The problem could therefore most likely be traced back to the LocalTuya integration. A network problem could be "ruled out".

Is there any other solution to fix the problem? This happened to me almost exactly 2 weeks after setting up LocalTuya.

paulsijben commented 6 months ago

I am observing the same issue.

I am not checking it against the tuya app as I have blocked the tuya wifi devices from accessing the internet.

VvanWyk commented 6 months ago

Same for me,

I have a combination of multiple LED bulbs, an Irrigation controller and some smart switches. All of them goes out at the same time at least once a day. They remain functional in the Tuya app. Restarting Home Assistant brings them all back online.

My main concern is with the irrigation controller where it once stopped working while watering one of the zones and because it went offline, it did not stop watering wasting lots of water.

I enabled debugging but I have no idea where to find the logs to try to identify the issue.