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.72k stars 28.87k forks source link

TUYA Integration requires reauth on every reboot/reload. #120879

Open maddinhome opened 2 days ago

maddinhome commented 2 days ago

The problem

After each restart, the TUYA integration must be re-authorized via QR code and SMART-LIFE app. Sometimes the QR code has already expired and HA needs to be restarted to generate a new QR code.

What version of Home Assistant Core has the issue?

core-2024.7.0b5

What was the last working version of Home Assistant Core?

2024.6.4

What type of installation are you running?

Home Assistant OS

Integration causing the issue

TUYA

Link to integration documentation on our website

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

Diagnostics information

No response

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 2 days 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. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


tuya documentation tuya source (message by IssueLinks)

SRETeamofTEN commented 2 days ago

I am also affected by this for a few days now. I have updated all details in Tuya, issued new project etc. At random, devices become unavalable and integration stops working due to authentication request. I then have to issue the authentication 5-10 times and sometimes delete the integration completely to fix the issue. Thank you in advance for looking into this.

TobiasPSP commented 2 days ago

After the last HA update I installed today, tuya integration becomes unusable and instable: requires re-auth via QR, reports „re-auth successful“, then 5 sec later there is the next re-auth issue popping up. Something has been seriously messed up I am afraid, either on Tuyas end or on HA. Very frustrating. I wish HA would issue updates much less often and instead take the time to check for regressions.

TobiasPSP commented 2 days ago

When I respond to the tuya notfication and scan the qr code with the app, I get „reauth successful“, then a few sec later HA reports a new authentication issue, claiming that the authentication (that I just successfully refreshed) is already expired.

It‘s frustrating to see the complete home automation suddenly go down the drain after updating HA.

It may have been reckless to use tuya devices in the first place but frankly, the tuya integration worked very well until now.

Friedrieck commented 2 days ago

I can't use TUYA anymore : since few hours, HA tells me to re-configure TUYA, but each time I scan the QR code, the TUYA app says that the QR code has expired... I'm on 2024.6.4. HACS' LocalTuya is still working.

TobiasPSP commented 2 days ago

I went back to 2024.6.3 where I did not have this experience before, however it is still present. So it doesn't seem to be related to HA Core. What else did change?

What's frustrating is that there seems to be next to no documentation what exactly is happening during authentication, and there is really nothing a user can do to test or isolate problems. At the same time, the issue is so fundamental that it can't be ignored: virtually nothing works anymore.

CL0SeY commented 2 days ago

Somehow, I have a Tuya hub that is working while also showing the 'reconfigure' button. image

CL0SeY commented 2 days ago

Is this a dupe of https://github.com/home-assistant/core/issues/120644

applegeeks commented 2 days ago

Somehow, I have a Tuya hub that is working while also showing the 'reconfigure' button. image

I would ignore the reconfigure button for now if your devices and integration reloaded ok.

StevusPrimus commented 1 day ago

https://github.com/home-assistant/core/issues/120644#issuecomment-2199309997

Please try this workaround.

ekalle-swe commented 1 day ago

Started for me 2 days ago and first time re-auth popped up it was impossible to re-auth. Routine went through successfully but same problem popped up again a couple of seconds later. No matter how many times I retired, the problem just kept coming back. After reboot, I had to re-auth twice before the integration started working again and that pattern has repeated itself on every restart since then.

TobiasPSP commented 1 day ago

the TUYA app says that the QR code has expired... I'm on 2024.6.4. HACS' LocalTuya is still working.<

Apparently the QR code is generated when the problem is detected, and by the time you notice this and use the QR code, it has expired.

For me, restarting HA has helped. When HA restarts, it seems to generate fresh QR codes. If you are quick enough to re-auth right after the restart is completed, you should be good.

That said, since yesterday I experience a new issue where the QR code reauthentication is reportedly „successful“ however HA pops up a new „authentication expired“ warning right after successfully authenticating.

I did this in (many) cycles yesterday night until eventually everything started working again. I have no clue what made the difference, leaving me with an eerie feeling that currently Tuya integration can stop working any time for an undetermined period of time.

I wish there was documentation about the authentication process and better ways to diagnose and isolate issues.

My suspicion is that the integration doesn’t fully expose underlying error messages: if „re-auth successful“ is reported, then imho there is no way that authentication can expire just ten seconds later. The true culprit is most likely something else, and the error messages do not seem to correctly describe the situation.

Jcgc270365 commented 1 day ago

Same problem here, i do not kniow if It IS related but i have also observed more home assistant restarts, each restart meands a new cicle of QR identification... BEST regards.

dabbler68 commented 1 day ago

Same here. BUT Local Tuya is working. I have 10 Tuya devices on the core integration and none work, One device on Local Tuya (xzetsubou fork) because it is not supported in the core integration, That device works fine.

Only discovered when the devices did not work and then discovered the "Repair needed" since yesterday. I updated from 2024.6.3 to 6.4 yesterday.

EDIT: 3 hours later and another reboot all the Tuya devices are working. I had done nothing about the Repair needed or anything else related to these devices or Tuya. It is no longer showing that a repair is needed.

DavidMW38 commented 1 day ago

I'm also having the re-auth issue on every reboot, however, I'm not using the core Tuya integration, I've been using the Smart Life Beta HACS integration since it was first released (unlike Tuya, it doesn't rely on having a Tuya IoT developer project, or having a Tuya IoT core licence/subscription (or asking Tuya for a free trial extension, as the Tuya integration requires you to do)). The re-auth issue started at the same time as other previous comments. I see on the Smart Life Beta page that the integration is now going to be part of HA Core (hence why I'm posting here rather than the Smart Life page). I know the Tuya and Smart Life apps are identical in every way, but the way that the two integrations work, and how they provide the devices to HA are very different so I was surprised to see Tuya integration users posting about the same issue I was checking on, but I'm guessing as they use the same auth method within HA both integrations are being affected by the same issue.

I have looked at the suggested fix in comment '#120644 (comment)', and even though the SL integration doesn't use the Tuya IoT cloud development platform, I've logged into my Tuya developer account, accepted the new terms and even got my IoT Core trial extended (which, again, SL doesn't need but I thought it couldn't hurt, just in case lol), but I still have to re-auth SL on every HA reboot. The one difference to the comments above is that no matter how long I leave it after the reboot (I forgot to do for a couple of days one of the times because I hadn't tried to use any of my SL devices), the QR code doesn't expire, it works first time, every time.

TheBartoMan commented 1 day ago

Yes I also have this recently. Try loggin into iot.tuya.com and accepting the terms.

Friedrieck commented 1 day ago

I can't use TUYA anymore : since few hours, HA tells me to re-configure TUYA, but each time I scan the QR code, the TUYA app says that the QR code has expired... I'm on 2024.6.4. HACS' LocalTuya is still working.

Strangely enough, after having rebooted, the problem solved by itself, not even asking me to re-auth. All my entities are available again.

iotinkognito commented 1 day ago

Having exactly the same issue. I have >170 devices. I was going to try pair some off to another account and then test if my number of devices is part of the issue. I have deleted any IOT developer projects and accounts that I could find.

ekalle-swe commented 1 day ago

Having exactly the same issue. I have >170 devices. I was going to try pair some off to another account and then test if my number of devices is part of the issue. I have deleted any IOT developer projects and accounts that I could find.

Don't really think so. I only use Tuya to bridge between my summerhouse and home. Rest is directly connected via ZHA or WiFi. In the cottage I only have about 25 devices and still have the problem.

DavidMW38 commented 1 day ago

Having exactly the same issue. I have >170 devices. I was going to try pair some off to another account and then test if my number of devices is part of the issue. I have deleted any IOT developer projects and accounts that I could find.

No, it's not your number of devices. I've only got 7 devices attached to my SL account atm (I've just moved so I've lost the ~120 devices I'd permanently installed into my old house 😪).

On the plus side, at least the auth process only takes about 3 seconds (as long as you have 2 devices within arms reach lol).

ObviousInvestor commented 1 day ago

Same issue, really becoming a pain now. I have 66 devices, 288 entities.

ObviousInvestor commented 1 day ago

Yes I also have this recently. Try loggin into iot.tuya.com and accepting the terms.

This stopped the constant verification for me, thanks! Still lost a few entities for some reason but just adding them back manually.

ObviousInvestor commented 1 day ago

Yes I also have this recently. Try loggin into iot.tuya.com and accepting the terms.

This stopped the constant verification for me, thanks! Still lost a few entities for some reason but just adding them back manually.

Strike that, it's back again now. Still requires constant verification.

athirst99 commented 1 day ago

For me I have been restored the previous version and it works again like charm :) , waiting another update or fix tuya integration

ExoNoe commented 1 day ago

Hello @all,

I solved the reauthentication problem on Tuya as follows.

Enter the Tuya Account Developer Platform. here on Cloud -》cloud services -》IoT Core "view Details" -》Authorized Projects. Object to authorization here. Then click on “switch service” and also contradict “Authorization Token Manager”, “Smart Home Basic Service” and “Data Dashboard Service”. Then restart the Home Assistant Cloud and scan the QR code to authenticate. He asks again immediately afterwards, but then it should work again.

Ok, the problem seems to be triggered by version 4.6.24 core. I downgraded to 2.6.24 and after following the path described above it seems to work again.

@applegeeks and @davidMW38 Sorry, but everything is working permanently again for me. Only downgrading to 2.6.24 core was previously unsuccessful FOR ME. Despite many authentications and restarts of HA. If this doesn't work for you two or you can't use it or you don't understand it or or or, then don't give up and keep looking.

Good luck!

applegeeks commented 1 day ago

Hello @ALL,

I solved the reauthentication problem on Tuya as follows.

Enter the Tuya Account Developer Platform. here on Cloud -》cloud services -》IoT Core "view Details" -》Authorized Projects. Object to authorization here. Then click on “switch service” and also contradict “Authorization Token Manager”, “Smart Home Basic Service” and “Data Dashboard Service”. Then restart the Home Assistant Cloud and scan the QR code to authenticate. He asks again immediately afterwards, but then it should work again.

this only works if you got a project that exists in the first place. Some of us who have deleted the projects since the introduction of the QR code feature where a project is not required, this solution would not apply.

DavidMW38 commented 17 hours ago

Hello @ALL, I solved the reauthentication problem on Tuya as follows. Enter the Tuya Account Developer Platform. here on Cloud -》cloud services -》IoT Core "view Details" -》Authorized Projects. Object to authorization here. Then click on “switch service” and also contradict “Authorization Token Manager”, “Smart Home Basic Service” and “Data Dashboard Service”. Then restart the Home Assistant Cloud and scan the QR code to authenticate. He asks again immediately afterwards, but then it should work again.

this only works if you got a project that exists in the first place. Some of us who have deleted the projects since the introduction of the QR code feature where a project is not required, this solution would not apply.

Exactly, it's not an issue with the Tuya IoT auth process itself. As I mentioned in a previous message, the Smart Life integration has no relationship with Tuya IoT dev projects so the auth issue being present in both the Tuya and Smart Life integrations means it's being caused due to a change in HA core's code (and, I'm guessing, how it talks to the SL/Tuya apps, which don't have any settings to adjust for HA integration), and, imho, I don't see how your settings within a Tuya dev project could affect the issue (unless you're already running an older version of HA Core which didn't have the auth issue and/or your Tuya dev project settings were incorrect anyway so you're getting the auth issue due to a separate issue with setting up Tuya/HA correctly).

While this can obviously be sorted by rolling back to a previous version, I don't really see the point, in my case anyway. Re-auth takes 2 seconds (and I only reboot HA manually (rather than during an automation) so it's not really much of an inconvenience either), and it's not like it causes any other issues for HA, everything else works perfectly, so I'm happy to leave it as is, flag the issue for HA Core devs, and occasionally have to re-auth until a fix comes along in a future version.

TobiasPSP commented 11 hours ago

The issue does not just surface with planned reboots. It can occur during integration restart (which is required to import newly added devices), plain power outage, update installation, etc. So it is not „controllable“ by trying to not reboot for as long as possible.

It‘s also not just „2 seconds of inconvenience“. When re-authentication fails (as happend this weekend), it is rather hours or even days of being locked out and unable to control potentially mission-critical devices. During this time, no device data is logged and irreversibly lost.

If your analysis is correct (I share your conclusion) and the issue is caused by HA core code and not the tuya api, then I wonder why this issue does not seem to be addressed. Reauth problems have been reported for quite a while and seem to aggrevate.

You may be not be severely affected by this issue, yet I kindly ask for a little bit of empathy to the many users who are.

All people ask is that this issue is finally taken seriously and in some way addressed, either by inviting users to participate in investigating, testing and reporting through some authentication diagnostics + verbose logging, or by - fixing it.

DavidMW38 commented 9 hours ago

I've definitely managed to avoid the worst of the issues then. Sorry it's so bad for you.

Obviously, there are other times that a reboot/forced reboot happens (maybe I'm just lucky but I can't remember the last time I had a power cut (at least 2 years), wasn't already on HA when devices/entities got added or an update was happening (seems a prerequisite tbf), and I don't think HA has ever crashed/rebooted on me. It's about time I got lucky with something tbh lol), but my point was, it's not like it's happening every 5 minutes or causing a conflict within HA and crashing the system, and you can set up an automation to tell you when the integration, or a certain number of Tuya devices, goes/go down so it's possible to avoid the huge gaps in data logging or "mission-critical devices" being down for long. So I do have empathy for those struggling with worse issues but at the same time, having much, much worse issues could we be a config issue adding to the auth issue.

I'm guessing that I'm having a much easier time with these isssues because I'm using the Smart Life integration, rather than the Tuya one. I'd definitely suggest switching over. Yes, it will mess up your device/entity names, your dashboards, and your automations, however, based on the issues you said you were having with this, I'm guessing that an hour or two spent switching over to the Smart Life will be time very well spent for you. Plus, as previously mentioned, it doesn't use the Tuya IoT dev platform so it makes everything so much more simple (and the QR scan works first time, every time), especially as you don't have to mess around with DP IDs etc during installation, everything in your SL/Tuya app just pops up and works straight away. Until this auth issue came along I would have said SL was bulletproof. If you're already using SL, then I can't think of a reason why our experience of this issue is so wildly different. Yes, I only have 7 devices on the integration atm but I have only just moved house and so the auth issue was happening while I had every hard-wired item in my house running on Tuya/SL.

I'd definitely agree it's about time this auth issue was sorted out (especially as it's a relatively recent change in the HA core code that caused it, so the fix is available in the old core code), or an acknowledgement that it's been noted and will be fixed.

ekalle-swe commented 7 hours ago

I've definitely managed to avoid the worst of the issues then. Sorry it's so bad for you.

Obviously, there are other times that a reboot/forced reboot happens (maybe I'm just lucky but I can't remember the last time I had a power cut (at least 2 years), wasn't already on HA when devices/entities got added or an update was happening (seems a prerequisite tbf), and I don't think HA has ever crashed/rebooted on me. It's about time I got lucky with something tbh lol), but my point was, it's not like it's happening every 5 minutes or causing a conflict within HA and crashing the system, and you can set up an automation to tell you when the integration, or a certain number of Tuya devices, goes/go down so it's possible to avoid the huge gaps in data logging or "mission-critical devices" being down for long. So I do have empathy for those struggling with worse issues but at the same time, having much, much worse issues could we be a config issue adding to the auth issue.

I'm guessing that I'm having a much easier time with these isssues because I'm using the Smart Life integration, rather than the Tuya one. I'd definitely suggest switching over. Yes, it will mess up your device/entity names, your dashboards, and your automations, however, based on the issues you said you were having with this, I'm guessing that an hour or two spent switching over to the Smart Life will be time very well spent for you. Plus, as previously mentioned, it doesn't use the Tuya IoT dev platform so it makes everything so much more simple (and the QR scan works first time, every time), especially as you don't have to mess around with DP IDs etc during installation, everything in your SL/Tuya app just pops up and works straight away. Until this auth issue came along I would have said SL was bulletproof. If you're already using SL, then I can't think of a reason why our experience of this issue is so wildly different. Yes, I only have 7 devices on the integration atm but I have only just moved house and so the auth issue was happening while I had every hard-wired item in my house running on Tuya/SL.

I'd definitely agree it's about time this auth issue was sorted out (especially as it's a relatively recent change in the HA core code that caused it, so the fix is available in the old core code), or an acknowledgement that it's been noted and will be fixed.

Restart of HA is enough. You don't have to reboot the OS to get in trouble here.

J4CE2 commented 3 hours ago

I re-authed, lights and devices all working, but I still get the error that it has expired constantly sat there.