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
71.17k stars 29.85k forks source link

Tuya integration locks up several times per day #90737

Closed Compugup closed 1 year ago

Compugup commented 1 year ago

The problem

I have more than 20 WiFi Cloud-connected Tuya devices that worked fine (except when my Tuya subscription expired) for several months. But in the last weeks I am getting a locked-up Tuya integration (no Tuya device updates and no Tuya device operations possible). After re-starting the Tuya-integration, everything works fine, until the next lock-up, several hours later.

I was able to catch a log of such an occasion and it seems to happen around a "refresh" of the connection.

This issue was/is also being discussed here: https://community.home-assistant.io/t/tuya-integration-hangsup/519130

Update 2023-4-6: There is also a work-around automation presented: https://community.home-assistant.io/t/tuya-integration-hangsup/519130/12 .

What version of Home Assistant Core has the issue?

core-2023.3.6

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

TuyaStaleLog202304031128.txt

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Added comments in the log.

Additional information

Maybe I "over-obfuscated" the logs (I am a bit "paranoid"). Give me a PM if you need more information.

home-assistant[bot] commented 1 year 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)

Compugup commented 1 year ago

This might be related to: GH #91899: Tuya integreation don't update sensor, need to be reloaded... GH #91186: Tuya some devises stop responding in HA GH #90840: Status tyua sensor GH #90661: Tuya needs reloading as they stop working GH #88133: Home Assistantupdates ...........only when Tuya smart-phone App is started HA #519130: Tuya integration hangsup HA #368896: Tuya devices state not updating properly (latest messages) HA #341991: Tuya v2 does not refresh states of entities (latest messages) HA #301020: Can I wite an automation to reload ...... (latest messages)

glowieX commented 1 year ago

same here since a few days. manual reload works fine for a few minutes/hours. But after an unknown amout of time one by one start to "freeze". Even with an older HA version, like 2023.1.X

midadami commented 1 year ago

Same. Happening for a few days already. My energy meter gets stuck until integration is reloaded and then lasts for few hours.

Compugup commented 1 year ago

My theory is that it only happens when the connection is refreshed by Home Assistant (if it is a "keep-alive" message, it should not execute for me because I have enough Tuya traffic), which happens every two hours. After the connection refresh the chance is that Tuya does not send any data anymore (or HA doesn't receive it), although Tuya does react on "pings" from HA (every minute), or it has no problem and will go on for the next two hours. Once you restart the integration, the two hour interval will re-start again. I captured several fails now with debug logs and every time it happened during that "refresh".

NatMan3000 commented 1 year ago

Yes im having this issue too. On the dashboard, none of the tuya devices will change to indicate "ON", but if i press On for a (any) of my lights, kettle/blind etc. they will turn on (doesn't indicate ON though). however, if i press again to toggle off, it is non-responsive. Very strange that it will send an ON command, but even one second later will not send the off command. Reloading tuya integration does also fix it for me for a while.

kurtdefeyter commented 1 year ago

same over here

kurtdefeyter commented 1 year ago

i keep wondering as this is a core , if people should keep using this , there are no responses from the code owners , question is if this things are getting any attention at all , many people saying to move to local tuya is that the solution ?

damian-82 commented 1 year ago

Same, been happening for probably a couple of weeks off and on (some days fine, other days require reload every few hours) pretty annoying as I've so far not been able to identify any pattern.

dpgh947 commented 1 year ago

I have circumvented the problem like this:

I did this in node red, an automation should work too… I have a spare tuya smart plug which I use:

turn on the plug wait 10 seconds check the reported state of the plug - if it’s not reporting on, reload the integration (call service reload_config_entry giving it the entity of the plug) turn the plug off

I have set this to run every 10 minutes (I used an inject node in node red which you can configure to fire at regular intervals). It reloaded once overnight (it notifies my phone if it does the reload), and all tuya devices are responding properly this morning, so it had the desired effect.

I wanted a better way of spotting when there is a problem instead of the sledgehammer approach of just reloading the integration every 60/30/10 minutes or whatever. This method should catch the condition I get, where the device responds to a command but the status in HA flicks back after a few seconds, or indeed the problem some people seem to get where the device doesn’t respond at all either.

VIMVa commented 1 year ago

I have circumvented the problem like this:

I did this in node red, an automation should work too… I have a spare tuya smart plug which I use:

turn on the plug wait 10 seconds check the reported state of the plug - if it’s not reporting on, reload the integration (call service reload_config_entry giving it the entity of the plug) turn the plug off

I have set this to run every 10 minutes (I used an inject node in node red which you can configure to fire at regular intervals). It reloaded once overnight (it notifies my phone if it does the reload), and all tuya devices are responding properly this morning, so it had the desired effect.

Hello, would you mind posting a screenshot??? You made me discover node-red and I have no idea on what to put in there.

dpgh947 commented 1 year ago

Hello, would you mind posting a screenshot??? You made me discover node-red and I have no idea on what to put in there.

I'm out for the day but I'll try tonight...

padamiak81 commented 1 year ago

Hi, My tuya integration actually stops after a few unstable issues. Today I tried to reconnect it with the result as below. I will be grateful for advice.

2023-04-05 10:53:07.740 ERROR (Thread-5) [tuya_iot] error while get mqtt config 2023-04-05 10:53:07.743 ERROR (Thread-5) [root] Uncaught thread exception Traceback (most recent call last): File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "/usr/local/lib/python3.10/site-packages/tuya_iot/openmq.py", line 161, in run time.sleep(self.mq_config.expire_time - 60) AttributeError: 'NoneType' object has no attribute 'expire_time'

Compugup commented 1 year ago

I tested the same approach the last two days, with an automation at 5-minute interval, as proposed by @VIMVa, and that works (the problem was there 7 times in the last 46 hours). Don't use a switch which has a mechanical relay, at the long term you wear-out the relay, I used the electronic "child-lock" of one of my switches. I am now looking on using a trigger that looks at the debug log for "[tuya_iot] _on_subscribe: 1", which is the end of the "refresh" process and then do just one check 10 seconds later (every two hours).

Compugup commented 1 year ago

None of the previous, is an actual solution, they are work-arounds, so I hope we can convince the devs that this is a new problem to analyze, not necessarily caused by HA. Although they might be overwhelmed by other problems related to Tuya.

VIMVa commented 1 year ago

I tested the same approach the last two days, with an automation at 5-minute interval, as proposed by @VIMVa, and that works (the problem was there 7 times in the last 46 hours). Don't use a switch which has a mechanical relay, at the long term you wear-out the relay, I used the electronic "child-lock" of one of my switches. I am now looking on using a trigger that looks at the debug log for "[tuya_iot] _on_subscribe: 1", which is the end of the "refresh" process and then do just one check 10 seconds later (every two hours).

Good suggestion. Must say that I don't hear any relay action with my setup: have the impression that switching off a plug that is already off does not do anything. I'm now going for @dpgh947's suggestion because mine is failing since this morning.

padamiak81 commented 1 year ago

In my case no one touches device. I can easily change the state with Google integration or Tuya app.

Compugup commented 1 year ago

I published my HA Tuya Test automation, although it is "work in progress", here: https://community.home-assistant.io/t/tuya-integration-hangsup/519130/12

JDJuergenD commented 1 year ago

I have 2 aircondition and 3 thermostat. Same problem at 2023-03-18. See api statistic iot platform: Screenshot (288) After many tests i change to "Tuya Local".

degrengo1978 commented 1 year ago

the same issue, and its getting on intense

peregrines2 commented 1 year ago

same problem here :( several times a day all my tuya devices lock up. only a restart will make them work again.

stephanbosch commented 1 year ago

Same problem here with several Tuya RGB bulbs. I have installed localtuya in parallel and that still works.

VIMVa commented 1 year ago

Hello, would you mind posting a screenshot??? You made me discover node-red and I have no idea on what to put in there.

I'm out for the day but I'll try tonight...

😭😟No need anymore... I managed to make that work. Here it seemed to work until 3 hours ago. Then my sensors went quiet. I'm back to automatic reload every 30 minutes on top of your workaround. 🤐

MinerSpark commented 1 year ago

Same issue, it completly stops reporting any power data but the switches remain working somehow

Screenshot_20230406-041147_Home Assistant

VIMVa commented 1 year ago

Hello, would you mind posting a screenshot??? You made me discover node-red and I have no idea on what to put in there.

I'm out for the day but I'll try tonight...

😭😟No need anymore... I managed to make that work. Here it seemed to work until 3 hours ago. Then my sensors went quiet. I'm back to automatic reload every 30 minutes on top of your workaround. 🤐

From the logbook I can see that the injection of the Node-RED flow stopped working at the time my nightly OneDrive Backup addon started. Watchdog for Node-Red is on. Any solution for that?

degrengo1978 commented 1 year ago

The problem for me seems to be that HA doesn't update the state of the presence sensors. While I'm checking in the Tuya app the sensors state works fine, but there is no change in HA. Yesterday the integration reloading was helping, today all sensors are dead - no state update whatsoever.

Aliskin-Papa commented 1 year ago

same problem here :(

Pgeup commented 1 year ago

Same problem here

dpgh947 commented 1 year ago

Well here is my flow anyway... it is slightly more complicated than I initially explained, because it checks the "off" call works too. There is a very remote but nevertheless possible chance that the "on" call could work and then the integration could fail during the first 10 second wait, meaning that the off call would fail, and so the plug state would be "on" for ever after that, and the test would not pick up a problem. So it checks the entity state is as expected after both calls. You can see it last reloaded yesterday evening... image

dpgh947 commented 1 year ago

Same problem here with several Tuya RGB bulbs. I have installed localtuya in parallel and that still works.

I have had localtuya running in parallel for some time too, and that has been giving me problems for the past few weeks too, as per this issue https://github.com/rospogrigio/localtuya/issues/1322

craigo1975 commented 1 year ago

The problem for me seems to be that HA doesn't update the state of the presence sensors. While I'm checking in the Tuya app the sensors state works fine, but there is no change in HA. Yesterday the integration reloading was helping, today all sensors are dead - no state update whatsoever.

This is what's happening for me too. Tuya Smartlife app updates immediately and correctly for the current state of sensors, HA has for the last 6 months updated immediately and correctly too, however for the last week the Tuya integration in HA seems to lock up / freeze and no sensors update. I can reload the integration and it works fine again for a while then locks again. I'm not overly keep on automating a reload every few minutes as it doesn't feel like it's solving the issue...

Compugup commented 1 year ago

My work-around automation (described here: https://community.home-assistant.io/t/tuya-integration-hangsup/519130/12 ) detected yesterday (CET time) only 2 crashes, one in the early morning and one in the late evening (Chinese holiday !?, less traffic, faster timing, less time-outs ???) , this morning I already had two crashes, which the automation automatically recovered.

Aliskin-Papa commented 1 year ago

My be remove this integration from official integration list? And code owner too.... Im use Tuya-local now, because code-owner not work.

JaybeRF commented 1 year ago

I've added virtual switch and virtual smoke sensor in Tuya Iot. In Tuya app i created an automation to change sensor signal time (Switch on - 1 min, switch off - 0 min) and use this pair in automation in HA as Tuya status check.

From experience so far - only about 25% of sensor state changes are received and shown in HA. As result, Tuya integration is reloaded every 15-20 minutes.

UPD: Status changes recognition in HA is below 5%. Tuya status boolean I've made is almost always off.

slartibartfast11 commented 1 year ago

For me I have the biggest issue with PIR sensors recently. The state change is appearing correctly in both the mobile Tuya app and on iot.tuya.com Debug logs, but the HA integration is missing most of the events (I.e. from person detected to clear)

damian-82 commented 1 year ago

For me I have the biggest issue with PIR sensors recently. The state change is appearing correctly in both the mobile Tuya app and on iot.tuya.com Debug logs, but the HA integration is missing most of the events (I.e. from person detected to clear)

Yea, me too. It's pretty much unusable now.

pkrasnousov commented 1 year ago

For me I have the biggest issue with PIR sensors recently. The state change is appearing correctly in both the mobile Tuya app and on iot.tuya.com Debug logs, but the HA integration is missing most of the events (I.e. from person detected to clear)

Same for me

wevsena commented 1 year ago

Same issue, it completly stops reporting any power data but the switches remain working somehow

Screenshot_20230406-041147_Home Assistant

Same problem!

izotop510 commented 1 year ago

Same problem here, the wifi contact sensors don't update their state in HA but they do in tuya app. If I reload tuya integration It works for a while but after freezes.

reprogerman commented 1 year ago

I have the same problem, power sensors don't update instantly like before. Is it possible to go back to a previous version of the plugin? Or will this problem be fixed in the future?

guidohaesen commented 1 year ago

I have the same issue. The tuya wifi PIR sensors and tuya camera stream doesn't work since a year in HA, since last week also the zigbee sensors don't work in HA

Must be something in HA, because the PIR and door sensors still correct working in alexa ENVIRONMENT. The zigbee and wifi sensors. I hope for a quick solution before i need to change all the sensors.

JaybeRF commented 1 year ago

From what I've got in Wireshark, packets about sensors changes are not coming from Tuya, so my bet is something happens on Tuya side

guidohaesen commented 1 year ago

From what I've got in Wireshark, packets about sensors changes are not coming from Tuya, so my bet is something happens on Tuya side

OK Thanks. So Amazon/Alexa is solving this issue on a different way.

JaybeRF commented 1 year ago

From what I've got in Wireshark, packets about sensors changes are not coming from Tuya, so my bet is something happens on Tuya side

OK Thanks. So Amazon/Alexa is solving this issue on a different way.

I think Tuya behaves like this only with HA.

slartibartfast11 commented 1 year ago

From what I've got in Wireshark, packets about sensors changes are not coming from Tuya, so my bet is something happens on Tuya side

OK Thanks. So Amazon/Alexa is solving this issue on a different way.

I think Tuya behaves like this only with HA.

So we approach Tuya as a bug with their API, or is the HA integration calling Tuya in a way they suddenly don't like..?

JaybeRF commented 1 year ago

Well, it's hard to say for me but what is HA for Tuya anyway? Small DIY society without billions. They can put rhis integration on bottom of bandwidth and computing power

reprogerman commented 1 year ago

Por lo que tengo en Wireshark, los paquetes sobre cambios de sensores no provienen de Tuya, por lo que apuesto a que algo sucede en el lado de Tuya.

Bueno, gracias. Entonces Amazon/Alexa está resolviendo este problema de una manera diferente.

Creo que Tuya se comporta así solo con HA.

Entonces, nos acercamos a Tuya como un error con su API, ¿o la integración HA está llamando a Tuya de una manera que de repente no les gusta?

The error coincides with an update that appeared to me from Tuya a few days ago

Compugup commented 1 year ago

@JaybeRF: From what I've got in Wireshark, packets about sensors changes are not coming from Tuya

I saw that in my logs, that happens mostly after the connection is refreshed with a new valid token (every app. 2 hours), but I was not sure if something internally was received (not being reported by debug logs), you are now confirming that the Tuya side completely stops sending. That is progress ! (@frenck , @zlinoliver ). I read somewhere (needs to be confirmed) that the HA Tuya integration is almost completely written by Tuya themselves (that is maybe also the reason that the HA devs are not very eager to look at this issue) and launched the Tuya integration together with the HA team. If so, then I hope that the devs can open a case at Tuya, which would put a lot more "meat" to the case.

jmcollin78 commented 1 year ago

The error coincides with an update that appeared to me from Tuya a few days ago

can you explain more what you have seen ?

reprogerman commented 1 year ago

Use localTuya and cloudTuya integration. It seems that localTuya works correctly at the moment. The devices that I have through cloudTuya since I got an update from Tuya is when it is failing me, I don't remember what date the update came out, but it could be about a week. Since then, some power meters do not update the information instantly, so I think that the error is from the cloudTuya integration but I am not an expert in this, I am reading comments on the net that it could be a cloudTuya error. I have several automations based on power measurement with cloudTuya and since this disaster is happening many functions do not work for me at home