home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.03k stars 28.27k forks source link

Tuya sensors still freezing and requiring HA restart or integration reload #96253

Closed RLB7777 closed 6 days ago

RLB7777 commented 10 months ago

The problem

Thsi issue has been discussed before but most users seem to say it's been resolved for them. But it remains a problem for me. Randomly (perhaps once a day) HA stops receiving data from Tuya sensors. Smart Life remains up to date. HA can still control Tuya devices but changed states are not detected. A reload of the integration updates the sensor values and sometimes kick-starts ongoing updates. A restart of HA seems to have a much better sucess rate at resuming ongoing sensor updates. But after a day the integrate falls over again. My Tuya IoT account is renewed and active, and I'm not up to my API call limit.

I attach a graph of two temperature sensors to show the problem.

Screenshot_2023-07-10-06-40-19-07_c3a231c25ed346e59462e84656a70e50

I have run logs on Tuya (full logs attached). These are very long but I have isolated the behaviour when it is receiving status updates, and when it fails. Essentially, the integration sends a connect and then a disconnect command to Tuya IoT. You’ll see from the log file and the extracts below that when it works, Tuya IoT responds with “Received CONNACK” and the integration gets status updates from all sensors. When it fails, there’s no “received CONNACK” and the integration goes into an unending attempt to connect.

Immediately below are the logs from when it works. You can see it connect and start to receive status updates. Further down I have pasted the logs from when it fails.

When it works:

2023-07-09 14:14:04.936 DEBUG (Thread-2) [tuya_iot] Request: method = GET, url = https://openapi.tuyaeu.com/v1.0/token/1ee37542750df8fd9df1817fa2ba8c4d, params = None, body = None, t = 1688908444935 2023-07-09 14:14:05.209 DEBUG (Thread-2) [tuya_iot] Response: { "result": { "access_token": "", "expire_time": 7200, "refresh_token": "", "uid": "" }, "success": true, "t": 1688908445193, "tid": "7ad4ba301e5a11ee871736843e81b476" } 2023-07-09 14:14:05.211 DEBUG (Thread-2) [tuya_iot] Request: method = POST, url = https://openapi.tuyaeu.com/v1.0/open-hub/access/config, params = None, body = {'uid': '', 'link_id': '', 'link_type': 'mqtt', 'topics': 'device', 'msg_encrypted_version': '1.0'}, t = 1688908445211 2023-07-09 14:14:05.278 DEBUG (Thread-2) [tuya_iot] Response: { "result": { "client_id": "", "expire_time": 7200, "password": "***", "sink_topic": { "device": "cloud/token/out/{device_id}" }, "source_topic": { "device": "cloud/token/in/d0282f0e9f719cfb18633280bbb38089" }, "url": "ssl://m1.tuyaeu.com:8883", "username": "cloud_d0282f0e9f719cfb18633280bbb38089" }, "success": true, "t": 1688908445261, "tid": "7ade5eb41e5a11ee871736843e81b476" } 2023-07-09 14:14:05.280 DEBUG (Thread-2) [tuya_iot] connecting ssl://m1.tuyaeu.com:8883 2023-07-09 14:14:05.497 DEBUG (Thread-2) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 14:14:05.501 DEBUG (Thread-2) [tuya_iot] _on_log: Sending DISCONNECT 2023-07-09 14:14:05.504 DEBUG (Thread-11 (_thread_main)) [tuya_iot] disconnect 2023-07-09 14:14:05.650 DEBUG (Thread-12 (_thread_main)) [tuya_iot] _on_log: Received CONNACK (0, 0) 2023-07-09 14:14:05.652 DEBUG (Thread-12 (_thread_main)) [tuya_iot] connect flags->{'session present': 0}, rc->0 2023-07-09 14:14:05.653 DEBUG (Thread-12 (_thread_main)) [tuya_iot] _on_log: Sending SUBSCRIBE (d0, m1) [(b'cloud/token/in/d0282f0e9f719cfb18633280bbb38089', 0)] 2023-07-09 14:14:05.753 DEBUG (Thread-12 (_thread_main)) [tuya_iot] _on_log: Received SUBACK 2023-07-09 14:14:05.754 DEBUG (Thread-12 (_thread_main)) [tuya_iot] _on_subscribe: 1 2023-07-09 14:14:17.186 DEBUG (Thread-12 (_thread_main)) [tuya_iot] _on_log: Received PUBLISH (d0, q0, r0, m0), 'cloud/token/in/d0282f0e9f719cfb18633280bbb38089', ... (348 bytes) 2023-07-09 14:14:17.187 DEBUG (Thread-12 (_thread_main)) [tuya_iot] payload-> b'{"data":"JIl7keJ9lIfX2LELlsp5/pq0I2exUsiXHDMCEAejptV05k3WQC+n0dc+Y3ktaZtqX0dRh/1Aa4+Wvh965k0rI0tR1NUdRMYu4pUXH/UWrGGt/0XFrfdJ/DzFct6B8AAS8EqwQ0b7q1Mfh1nzck0RBc3j2jou5kbxZbYGhCfnLGwI0PTRpJp/zEK+/HQBneYrgm8Ks26njcmp9/o3KHtzXfAP2uq2j8lD02xHZcQ5VTxawyLobPaGPGAKGj/HuYna","protocol":4,"pv":"2.0","sign":"86c1c93f27cbc511849f779981543aa2","t":1688908451}' 2023-07-09 14:14:17.189 DEBUG (Thread-12 (_thread_main)) [tuya_iot] on_message: {'data': {'dataId': 'eac07f58-2a8a-4cb5-88bc-b8d395d41a5c', 'devId': '28224860807d3a7aee4e', 'productKey': 'kOKEJBFoF9VNB5FR', 'status': [{'code': 'cur_voltage', 't': '1688908451', '6': 2405, 'value': 2405}]}, 'protocol': 4, 'pv': '2.0', 'sign': '86c1c93f27cbc511849f779981543aa2', 't': 1688908451} 2023-07-09 14:14:17.190 DEBUG (Thread-12 (_thread_main)) [tuya_iot] mq receive-> {'data': {'dataId': 'eac07f58-2a8a-4cb5-88bc-b8d395d41a5c', 'devId': '28224860807d3a7aee4e', 'productKey': 'kOKEJBFoF9VNB5FR', 'status': [{'code': 'cur_voltage', 't': '1688908451', '6': 2405, 'value': 2405}]}, 'protocol': 4, 'pv': '2.0', 'sign': '86c1c93f27cbc511849f779981543aa2', 't': 1688908451} 2023-07-09 14:14:17.191 DEBUG (Thread-12 (_thread_main)) [tuya_iot] mq _on_device_report-> [{'code': 'cur_voltage', 't': '1688908451', '6': 2405, 'value': 2405}] 2023-07-09 14:14:17.192 DEBUG (Thread-12 (_thread_main)) [homeassistant.components.tuya] Received update for device 28224860807d3a7aee4e: {'switch': False, 'countdown_1': 0, 'cur_current': 0, 'cur_power': 0, 'cur_voltage': 2405} 2023-07-09 14:14:49.072 DEBUG (Thread-12 (_thread_main)) [tuya_iot] _on_log: Received PUBLISH (d0, q0, r0, m0), 'cloud/token/in/d0282f0e9f719cfb18633280bbb38089', ... (348 bytes) 2023-07-09 14:14:49.074 DEBUG (Thread-12 (_thread_main)) [tuya_iot] payload-> b'{"data":"tNcE7huiVXIoggHoM+T4elBWtyI0gNn4bsqxzGe/3yK32if6bzGmaKNPWFZufg3uX0dRh/1Aa4+Wvh965k0rI0tR1NUdRMYu4pUXH/UWrGGt/0XFrfdJ/DzFct6B8AAS8EqwQ0b7q1Mfh1nzck0RBc3j2jou5kbxZbYGhCfnLGwI0PTRpJp/zEK+/HQBneYrYHI+fNr18S1xJXSW76+mfnPnmmoLbRUFtyhAL5R1j8uujjCS78cuVsUxhQfMYUr9","protocol":4,"pv":"2.0","sign":"5e69f6c4e823b0cdcefff5f3cee15d57","t":1688908483}' 2023-07-09 14:14:49.076 DEBUG (Thread-12 (_thread_main)) [tuya_iot] on_message: {'data': {'dataId': '4464e9c0-e662-4eef-a068-1734b2979aaf', 'devId': '28224860807d3a7aee4e', 'productKey': 'kOKEJBFoF9VNB5FR', 'status': [{'code': 'cur_voltage', 't': '1688908483', '6': 2398, 'value': 2398}]}, 'protocol': 4, 'pv': '2.0', 'sign': '5e69f6c4e823b0cdcefff5f3cee15d57', 't': 1688908483} 2023-07-09 14:14:49.078 DEBUG (Thread-12 (_thread_main)) [tuya_iot] mq receive-> {'data': {'dataId': '4464e9c0-e662-4eef-a068-1734b2979aaf', 'devId': '28224860807d3a7aee4e', 'productKey': 'kOKEJBFoF9VNB5FR', 'status': [{'code': 'cur_voltage', 't': '1688908483', '6': 2398, 'value': 2398}]}, 'protocol': 4, 'pv': '2.0', 'sign': '5e69f6c4e823b0cdcefff5f3cee15d57', 't': 1688908483} 2023-07-09 14:14:49.080 DEBUG (Thread-12 (_thread_main)) [tuya_iot] mq _on_device_report-> [{'code': 'cur_voltage', 't': '1688908483', '6': 2398, 'value': 2398}] 2023-07-09 14:14:49.084 DEBUG (Thread-12 (_thread_main)) [homeassistant.components.tuya] Received update for device 28224860807d3a7aee4e: {'switch': False, 'countdown_1': 0, 'cur_current': 0, 'cur_power': 0, 'cur_voltage': 2398} 2023-07-09 14:15:06.123 DEBUG (Thread-12 (_thread_main)) [tuya_iot] _on_log: Sending PINGREQ 2023-07-09 14:15:06.145 DEBUG (Thread-12 (_thread_main)) [tuya_iot] _on_log: Received PINGRESP 2023-07-09 14:15:11.086 DEBUG (Thread-12 (_thread_main)) [tuya_iot] _on_log: Received PUBLISH (d0, q0, r0, m0), 'cloud/token/in/d0282f0e9f719cfb18633280bbb38089', ... (348 bytes) 2023-07-09 14:15:11.091 DEBUG (Thread-12 (_thread_main)) [tuya_iot] payload-> b'{"data":"UbWiu+KIzufmyiqqehV1EYmCZYU4ngacoaZCjw60iZdAmyIj3rEVJ4DVZUbFUStRX0dRh/1Aa4+Wvh965k0rI0tR1NUdRMYu4pUXH/UWrGGt/0XFrfdJ/DzFct6B8AAS8EqwQ0b7q1Mfh1nzck0RBc3j2jou5kbxZbYGhCfnLGwI0PTRpJp/zEK+/HQBneYroFPs15zbXSVjXcLmv2880SX/snEC8szNjb/0GrcahyS6yzbCT9vCZAySOn6dfsLf","protocol":4,"pv":"2.0","sign":"6a0e1f8a55c340d9237ecd02776f0ac5","t":1688908505}' 2023-07-09 14:15:11.107 DEBUG (Thread-12 (_thread_main)) [tuya_iot] on_message: {'data': {'dataId': '0800c3db-34e4-49ce-9afb-05a8ad67b4e9', 'devId': '28224860807d3a7aee4e', 'productKey': 'kOKEJBFoF9VNB5FR', 'status': [{'code': 'cur_voltage', 't': '1688908505', '6': 2387, 'value': 2387}]}, 'protocol': 4, 'pv': '2.0', 'sign': '6a0e1f8a55c340d9237ecd02776f0ac5', 't': 1688908505} 2023-07-09 14:15:11.108 DEBUG (Thread-12 (_thread_main)) [tuya_iot] mq receive-> {'data': {'dataId': '0800c3db-34e4-49ce-9afb-05a8ad67b4e9', 'devId': '28224860807d3a7aee4e', 'productKey': 'kOKEJBFoF9VNB5FR', 'status': [{'code': 'cur_voltage', 't': '1688908505', '6': 2387, 'value': 2387}]}, 'protocol': 4, 'pv': '2.0', 'sign': '6a0e1f8a55c340d9237ecd02776f0ac5', 't': 1688908505} 2023-07-09 14:15:11.109 DEBUG (Thread-12 (_thread_main)) [tuya_iot] mq _on_device_report-> [{'code': 'cur_voltage', 't': '1688908505', '6': 2387, 'value': 2387}] 2023-07-09 14:15:11.109 DEBUG (Thread-12 (_thread_main)) [homeassistant.components.tuya] Received update for device 28224860807d3a7aee4e: {'switch': False, 'countdown_1': 0, 'cur_current': 0, 'cur_power': 0, 'cur_voltage': 2387} 2023-07-09 14:15:23.080 DEBUG (Thread-12 (_thread_main)) [tuya_iot] _on_log: Received PUBLISH (d0, q0, r0, m0), 'cloud/token/in/d0282f0e9f719cfb18633280bbb38089', ... (348 bytes) 2023-07-09 14:15:23.082 DEBUG (Thread-12 (_thread_main)) [tuya_iot] payload-> b'{"data":"jWcLP8ry61Q2GdHut/7nFsCPp4y+/bup2/q2y8AX6HMdMVPOXaBaAJsjGxx11QWUX0dRh/1Aa4+Wvh965k0rI0tR1NUdRMYu4pUXH/UWrGGt/0XFrfdJ/DzFct6B8AAS8EqwQ0b7q1Mfh1nzck0RBc3j2jou5kbxZbYGhCfnLGwI0PTRpJp/zEK+/HQBneYrjNWmHjOUyAulIOAzmz21YHPnmmoLbRUFtyhAL5R1j8uujjCS78cuVsUxhQfMYUr9","protocol":4,"pv":"2.0","sign":"9e355f765635bb817f7bfa0a9631cbfa","t":1688908517}'

This is when it fails. You'll see there is no "Received CONNACK" and the whole thing falls over. The integration doesn't recover from this.

When it fails:

2023-07-09 20:11:06.834 DEBUG (Thread-2) [tuya_iot] Request: method = GET, url = https://openapi.tuyaeu.com/v1.0/token/01fa9e870481e35c3c8f704cdc9fea8f, params = None, body = None, t = 1688929866833 2023-07-09 20:11:07.124 DEBUG (Thread-2) [tuya_iot] Response: { "result": { "access_token": "", "expire_time": 7200, "refresh_token": "", "uid": "" }, "success": true, "t": 1688929867105, "tid": "5b4847aa1e8c11ee94e0a2e0adfc0b14" } 2023-07-09 20:11:07.125 DEBUG (Thread-2) [tuya_iot] Request: method = POST, url = https://openapi.tuyaeu.com/v1.0/open-hub/access/config, params = None, body = {'uid': '', 'link_id': '', 'link_type': 'mqtt', 'topics': 'device', 'msg_encrypted_version': '1.0'}, t = 1688929867125 2023-07-09 20:11:07.212 DEBUG (Thread-2) [tuya_iot] Response: { "result": { "client_id": "", "expire_time": 7200, "password": "***", "sink_topic": { "device": "cloud/token/out/{device_id}" }, "source_topic": { "device": "cloud/token/in/d0282f0e9f719cfb18633280bbb38089" }, "url": "ssl://m1.tuyaeu.com:8883", "username": "cloud_d0282f0e9f719cfb18633280bbb38089" }, "success": true, "t": 1688929867195, "tid": "5b52859e1e8c11ee94e0a2e0adfc0b14" } 2023-07-09 20:11:07.213 DEBUG (Thread-2) [tuya_iot] connecting ssl://m1.tuyaeu.com:8883 2023-07-09 20:11:07.423 DEBUG (Thread-2) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:11:07.427 DEBUG (Thread-2) [tuya_iot] _on_log: Sending DISCONNECT 2023-07-09 20:11:08.526 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:11:10.619 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:11:14.702 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:11:22.797 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:11:38.888 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:12:10.981 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:13:15.075 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:15:15.173 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:17:15.267 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:19:15.370 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:21:15.466 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:23:15.567 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:25:15.666 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:27:15.759 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:29:15.849 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:31:15.952 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:33:16.053 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47' 2023-07-09 20:35:16.149 DEBUG (Thread-15 (_thread_main)) [tuya_iot] _on_log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'cloud_5fcfafa72ea62fa83ae579004cb08b47'

I'm at the outer limits of my understanding here but hopefully this makes sense to people with more expertise.

What version of Home Assistant Core has the issue?

core-2023.7.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Tuya

Link to integration documentation on our website

https://www.home-assistant.io/integrations/tuya

Diagnostics information

error_log-3.txt

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 10 months ago

Hey there @tuya, @zlinoliver, @frenck, mind taking a look at this issue as it has been labeled with an integration (tuya) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `tuya` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign tuya` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


tuya documentation tuya source (message by IssueLinks)

Fred-DTV commented 10 months ago

I am having the same issue, after about a 1 month where it has been working fine. Due to this I am currently running a Tuya Local HACS integration parallel to see if it has the same issue.

BernieV1977 commented 10 months ago

I'am having also this issue (HA Core 2023.7.1 with Python 3.11 in venv)

RLB7777 commented 10 months ago

Just to add this is definitely better fixed (temporarily) with an HA restart than with an integration reload. The restart seems to allow the sensors to resume updating as normal, at least for a time. The reload often seems to deliver just a single sensor update.

SuperStark commented 10 months ago

Can confirm I also have this issue, got worse since the last two updates. I also noticed that device count goes up and down, usually when the issue is present I see more devices than I actually have.

Home Assistant 2023.7.1 Supervisor 2023.07.1 Operating System 10.3 Frontend 20230705.1 - latest

Fred-DTV commented 10 months ago

I am having the same issue, after about a 1 month where it has been working fine. Due to this I am currently running a Tuya Local HACS integration parallel to see if it has the same issue.

The Tuya Local HACS integration doesn't have this problem. I have been running both parallel and even when I toggle a switch on Tuya Local it doesn't update that same switch in the regular Tuya integration

SuperStark commented 10 months ago

I am having the same issue, after about a 1 month where it has been working fine. Due to this I am currently running a Tuya Local HACS integration parallel to see if it has the same issue.

The Tuya Local HACS integration doesn't have this problem. I have been running both parallel and even when I toggle a switch on Tuya Local it doesn't update that same switch in the regular Tuya integration

I wouldn't mind running the local integration, but it takes so long to set up every device, and I didn't see energy monitoring as part of it? (correct me if I'm wrong)

mjkosin68 commented 10 months ago

I am having this issue, but it seemed to start when I added a Tuya device to the same account, but at another location, my office. I have been running this integration through HASS for about a year without issue until I did this. I am going to try deleting this device to see if functionality goes back to normal.

Do you guys know how I could trigger an automation to restart the integration? I am thinking of adding a dummy relay and simply turn it on every 15 minutes and look for the status change. If the status doesn't change after turning it on, then I could reload the integration.

Thoughts?

Fred-DTV commented 10 months ago

I am having this issue, but it seemed to start when I added a Tuya device to the same account, but at another location, my office. I have been running this integration through HASS for about a year without issue until I did this. I am going to try deleting this device to see if functionality goes back to normal.

Do you guys know how I could trigger an automation to restart the integration? I am thinking of adding a dummy relay and simply turn it on every 15 minutes and look for the status change. If the status doesn't change after turning it on, then I could reload the integration.

Thoughts?

I think this might be a good lead, as my issues started at about the time I connected my two HA servers via 'Home Assistant Remote'

RLB7777 commented 9 months ago

I am having this issue, but it seemed to start when I added a Tuya device to the same account, but at another location, my office. I have been running this integration through HASS for about a year without issue until I did this. I am going to try deleting this device to see if functionality goes back to normal.

Do you guys know how I could trigger an automation to restart the integration? I am thinking of adding a dummy relay and simply turn it on every 15 minutes and look for the status change. If the status doesn't change after turning it on, then I could reload the integration.

Thoughts?

Here's an automation which checks every 5mins to see if a Tuya sensor (in this case, a bathroom temperature sensor) hasn't changed for 24hrs (or however long you want). If there's been no change, it reloads the Tuya integration. The reload command references a hot water tank sensor, but it can be any Tuya device on your system as this command reloads the entire integration, not just the single device.

alias: Restart Tuya if failed for 24hrs
description: ""
trigger:
  - platform: time_pattern
    minutes: /5
condition:
  - condition: template
    value_template: >-
      {{ now() -
      states.sensor.temperature_sensor_bathroom_temperature.last_changed >=
      timedelta (hours=24) }}
action:
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      entity_id: sensor.hot_water_tank_1_temperature
mode: single

I have better luck with the version below, which is pretty much the same but instead of reloading Tuya, it restarts Home Assistant itself. I find this is more likely to begin a virtuous cycle of Tuya updating properly. The "reload Tuya" version sometimes falls over again very quickly.

alias: Restart HA if Tuya down for 2 hours
description: ""
trigger:
  - platform: time_pattern
    minutes: /5
condition:
  - condition: template
    value_template: >-
      {{ now() -
      states.sensor.temperature_sensor_bathroom_temperature.last_changed >=
      timedelta (hours=2) }}
action:
  - service: homeassistant.restart
    data: {}
mode: single
kilrgt commented 8 months ago

Anyone every get to the bottom of this??, My Tuya light switches have all been freezing since maybe two updates ago, smartlife app is all functioning but HA not. My IOT is all up to date and everything that needs to to function is there. I haven't had any issues in a year but not every 12 hours ish i need to a restart or some times a reload will work to get Tuya to unfreeze…..any help here ?

RLB7777 commented 8 months ago

Mine is still freezing. I have an automation to restart HA when Tuya locks up. It's firing about once every 12hrs.

mjkosin68 commented 8 months ago

I have an automation to restart the Tuya integration every hour. Catches most of it, but still not perfect. I have not had a chance yet to delete the device at the remote location, thinking that will help.

mjkosin68 commented 8 months ago

Well, so far my theory is correct, I removed the device from the second location and I now have 8 hours of flawless function. It was dropping more than once/hour previously.

Let me know if anyone gets a fix for this, not just a reload.

Thanks,

riddle-stc commented 8 months ago

@mjkosin68: did you manage to solve the issue? I'm having the same problem since some weeks now.

RLB7777 commented 8 months ago

No, I haven't solved it. My automation to restart HA fires about once or twice a day.

kilrgt commented 8 months ago

Still Freezing... Constant reloading the integration, Ive pulled my hair out trying to figure it out. My IoT account is fine, I even reset up on that side and deleted the old one hoping it would help.... it has not, Its defiantly not a issue with my network.

Ive basically given up and I'm looking to replace all 22 Light switches plus what ever else I have Tuya. Pretty big cost of money and time but i need this stuff to work when i need it to work. I am holding off a bit hoping it will get resolved. it worked flawlessly for over 18 months not once having a issue, something changed and I'm leaning towards the HA side, again the app works perfect and never a issue once

mjkosin68 commented 8 months ago

Yes, mine has worked perfectly for the past two weeks since I removed the Tuya devices from the second location. I had to set up another IoT account for the second location, and now all devices at both locations are working perfectly, not a single issue since then.

tunisiano187 commented 8 months ago

Same problem for me, I have 2 power relay and after some time, they aren't updated anymore and the switch in ha don't do anything neither. After reloading the integration, it works 1 or 2 times and stop again. I haven't added anything to the account for a year, maybe two if it can help.

mjkosin68 commented 8 months ago

Are they on the same IP network? Are you using IPv6 on your network at all? Try disabling that.

riddle-stc commented 8 months ago

Yes, mine has worked perfectly for the past two weeks since I removed the Tuya devices from the second location. I had to set up another IoT account for the second location, and now all devices at both locations are working perfectly, not a single issue since then.

I have a smart plug in my holiday house I monitor using Tuya-HA for more than 8 months. Removing that plug from my account will fix it you think?

I don't use IP§ AFAIK.

mjkosin68 commented 8 months ago

Yes, I would try that. I think that will fix your issue.

tunisiano187 commented 8 months ago

Are they on the same IP network? Are you using IPv6 on your network at all? Try disabling that.

No IPV6 is disabled

mjkosin68 commented 8 months ago

I would try updating the firmware on the device. Are they possibly connected to two different WIFI SSIDs?

tunisiano187 commented 8 months ago

i've just checked, they are up to date. I'll try to reset them and join them to the wifi again

kilrgt commented 8 months ago

Same on my end ,no firmware updates, all on the same network , IPV6 all disabled…… What i find odd is I ran this prior to these freezes for around 18 months with absolute zero issues. All good feedback so far tho and hope you all dont have the same problems as I

RLB7777 commented 5 months ago

This is still happening for me. Sensors/sockets are a mix of wifi and Zigbee, all in the same location. It’s getting to be quite a problem as I have automations to turn some sockets on triggered by the temperature hitting certain thresholds. Obviously, that is very unreliable if I need an HA restart to ensure status updates.

At the beginning of this thread, I posted the logs which showed a different behaviour when Tuya updated and when it failed. Does anyone reading this have the expertise to interpret those?

tkarman83 commented 5 months ago

Same issue over here as well. I just moved from Local Tuya to the core app because anytime a light got reset by accident it took a million year to get it configured back into the local integration. Anyway, now that I'm on Tuya core I'm dealing with all of the issues described above. I only have lights but they keep losing their status in HA. Sometimes I will turn a light on or off and the switch in HA will revert back to the opposite position after a few seconds. I've also noticed that other integrations like Adaptive Lighting have a really hard time controlling the lights. Sometimes Adaptive Lighting works and sometimes not and usually when it does work it's only on a select few lights and not all of them.

kilrgt commented 5 months ago

I’ve been chasing this for months. It did improve until around 2 weeks ago , I need to constantly reload the integration. I decided to try some Kasa light switches. Has worked my flawless, I need to replace another 18 ish hardwire but in the end it’s worth having a device that works. I would think if more ppl had issues this would have been looked at , I can’t say where the problem lays , but it’s a problem and I need my stuff to work. Wish I could help more but my skill set is limited

mjkosin68 commented 5 months ago

Mine was working flawlessly until a couple weeks ago as well. Failure likely associated with a HA update, but cannot say for sure.

riddle-stc commented 4 months ago

This is still happening for me. And to make things worse, I had created a automation some months ago that checks if my Tuya device is frozen. However since one of the latest HA updates my ZHA integration does not reload after a HA restart. So HA is becoming a real pain. I need to check my system at least 2-3 times a day to see if all is still OK. Any help would be welcome.

mjkosin68 commented 4 months ago

Sorry riddle-stc, since my last post almost a month ago, I have only had to reload once. Not sure why the issue reoccurred for a short time, but it seems to have corrected itself.

mjkosin68 commented 3 months ago

OK, so my Tuya integration went down completely last week, so I did a reload like I usually do, then all of the devices were gone in HA. I checked the app and everything was still online. As I stated in previous posts, I had set up another developer account and app account for another location (my office), and that location showed the same exact symptoms. With this, I assumed it was a systemic problem, so I decided to start over and migrate to Local Tuya. I deleted my projects in the original developer account and created a new developer account, then followed the process to install local Tuya and pull in all the devices. Discovering devices was pretty simple, but adding them so I could use them was a bit tricky as each entity of each device must be manually defined. So, what I did was to add each device with the main entity defined (switch, light, etc.), then all of the sub entities I identified as sensors. I would then manipulate the device through the app and watch the entities to determine exactly what they were. I could then remove and re-add the device and correctly define the (sub) entities. I found that incorrectly defining the entities (other than as sensors) would lock up the entire integration, but adding them as sensors did not. I did have a problem with battery powered devices that hibernate when the state is not changing. I could add them, but their functionality was terribly slow to respond and went unavailable when they would hibernate. Fortunately I only had two of these, so I replaced them with Zigbee devices and the problem was solved.

With nearly 40 devices, it took quite some time to complete this, but the end result is so much improved over the cloud integration. Lightning fast response on automations, I should have done this a long time ago. Good thing I had eight hours to waste because that's about how long I spent troubleshooting then moving everything to the local Tuya.

Good luck, let me know how it goes.

issue-triage-workflows[bot] commented 1 week ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.