Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tuya - no status update after changing a switch state #65758

Closed
martinw72 opened this issue Feb 5, 2022 · 52 comments
Closed

Tuya - no status update after changing a switch state #65758

martinw72 opened this issue Feb 5, 2022 · 52 comments

Comments

@martinw72
Copy link

The problem

When turning on or off a Tuya wifi Switch, there is no update in the gui. In the Tuya App the state has changed but the ha gui move back to the old state after e few seconds.
A refresh on the integrations page solves the problem and the state is updated correctly. But only for the current action.

What version of Home Assistant Core has the issue?

2022.1

What was the last working version of Home Assistant Core?

2021.11

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

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Nothing in the logs

Additional information

No response

@probot-home-assistant
Copy link

tuya documentation
tuya source
(message by IssueLinks)

@probot-home-assistant
Copy link

Hey there @tuya, @zlinoliver, @METISU, @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!
(message by CodeOwnersMention)

@RMorera07
Copy link

Same for me, since I installed Core version 2022.2.0. I'm now on 2022.2.2 and the problem persists.
It's the same symptom with 2021 versions, with was totally solved on 2021.12.6 I think.
Thanks for helping us!

@FizzBuzz791
Copy link

Can confirm here too. Not sure if it's related, but I've disabled the device and now don't seem to be able to re-enable it.

Tuya IOT interface says it's online. It also works fine / is available in Google Home, so this definitely seems like it's an issue with the HA integration.

Diagnostic Info from HA if it helps.

@craigccfl
Copy link

craigccfl commented Feb 5, 2022

Same here, started after updating from the latest core 2021 to 2022.2.2. Update: Turned off the entity, status remained on in the UI but the entity (light bulbs) were off. Rebooted HA, went back to HA UI and the status showed off. Toggle the switch and the status and the light are in sync, functioning properly.

@craigrouse
Copy link

Same here. I suspect a Tuya server issue, as I'm using an older release of the integration (I've customized it) and getting the same issue. It's been happening on and off for a few days for me, but it's especially bad today.

@PelonVela
Copy link

My dehumidifer is showing the same behavior as reported by original poster.

@leeyuentuen
Copy link
Contributor

leeyuentuen commented Feb 5, 2022

i've open a ticket on tuya support and they are checking.
It seems they didn't send message to home assistant
You see here that tuya app got the update, but not on home assistant, But when I reload the tuya plugin, it will work for a short time and will get that problem again.
I'm now on 2022.2.1 but I'm going update to 2022.2.2 but I suppose the issue still exists and the problem is on tuya server. It was also the problem before 2022.2.0

Screenshot_20220205-224759

Screenshot_20220205-224738

@Tonjoriva
Copy link

I have the same problem

@maxpatrone
Copy link

mee too, same problem .... sometimes works correctly, but often at least 1 device state is not changed on H.A.
H.A. core 2022.1

@Anarkistic
Copy link

I am also experiencing the same issue. Indeed it was fixed in 2021.12.6 as someone previously mentioned, but in every single core update since that it has been broken, and continues to be so in 2022.2.3 that I installed today.

As with many other, a reload of the integration sorts it for a few minutes, then it breaks again. If you mash the switch for a light it will eventually agree with you that indeed, it IS off/on, but it sure does resist.

It's making me regret going down the route of Tuya with all my lights and outlets!

@FrancoLoco
Copy link

I also have the same issue...

It was indeed fixed for a brief release, but now is broken again..

Welp.. I re-enabled an automation I made to reload the tuya integration every few hours and it helps, but it's really annoying...

@leeyuentuen
Copy link
Contributor

I'm looking again in tuyalocal. Already have partial fix for the zigbee sensor with tuya gateway. If the other works great, i'll go to tuyalocal to have the fully control of it instead of the servers from tuya

@andreasbuff
Copy link

Same problem here. As described by Anarkistic, problem started with Tuya Integration, then was "solved" for a short period of time and startet new with some releases ago... hope it will be addressed and solved soon?!

@DIMMonchik
Copy link

I can't say anything about the switches, since they work for me through local tuya. basically the problem is with the door opening sensors and leak sensors.

@moedaug
Copy link

moedaug commented Feb 8, 2022

Same issue here, its like 2021 all over again !!

@craigrouse
Copy link

@tuya @zlinoliver do you have any suggestions here? Tuya lights are unusable much of the time now. This is definitely a Tuya and not an HA issue. Status updates are not being delivered a lot of the time, meaning lights are stuck showing an incorrect state. I have a lot of Tuya lights, and this is a big pain, as my automations are failing.

@leeyuentuen
Copy link
Contributor

FYI: for the people who are interesting. I'm testing out localtuya to support Zigbee protocol:
rospogrigio/localtuya#739
afbeelding

@Bobbik1
Copy link

Bobbik1 commented Feb 11, 2022

Same behavior here. Looks like status update is hit and miss

@mjcuk
Copy link

mjcuk commented Feb 12, 2022

I have had the same issue since I upgraded to the latest tuya integration since Christmas. I Never has an issue before. But now it pointless. The state never updates you can reload the integration. But it does not stay working for long.

@craigrouse
Copy link

@frenck sorry to call you out directly, but it seems Tuya has abandoned us. Do you have any suggestions on how to proceed? Sad as it would be, it would almost be better to remove the integration entirely from HA core, as it feels like it will be a long time before it's able to be used without issues. Automations fail constantly because the device state is incorrect, and the state machine doesn't send commands if the device is already in the state the automation is calling for.

@leeyuentuen
Copy link
Contributor

@craigrouse I suppose they are the device on your Zigbee? normally wifi device shouldn't have the problem?

@Anarkistic
Copy link

@craigrouse I suppose they are the device on your Zigbee? normally wifi device shouldn't have the problem?

Mine are all WiFi devices and I have the problem big time.

On a separate note though, I notice states update perfectly fine in the Smart Life app, just not in HA.

@craigrouse
Copy link

@leeyuentuen Mine are all wifi.

@craigrouse
Copy link

@Anarkistic I believe the smart life app uses local communication to devices, which is why it usually works.

@andreasbuff
Copy link

For those, who do not want to wait for a solution from Tuya, there is a workaround, to reload tuya-add-on every n-minutes.
All Credit to Olli for this solution! (see: https://smarterkram.de/1162/)
=> this shell-command will reload HACS-Add-on configuration

To create an automation, which is loading tuya-configurtion, every n-minutes:

  1. create a "shell-command" in "configuration.yaml", as described by Olli

Tutorial: https://smarterkram.de/1162/

shell_command:
tuya_restart: "/usr/bin/curl -X 'POST' -H 'authorization: Bearer eyJm............... xyz .......d2effea/reload"

then
2) create automation: (for example every 1 min. )

alias: Tuya AddOn (restart every 1min)
description: ''
trigger:

  • minutes: /01
    platform: time_pattern
    condition: []
    action:
  • service: shell_command.tuya_restart
    data: {}
    mode: single

@leeyuentuen
Copy link
Contributor

@leeyuentuen Mine are all wifi.

The only problem that was notice and anoying me was my motion sensor of tuya didn't work well will tuya server. I've open a ticket on tuya support but after 2 weeks still not really an answer. Only that they are looking at the problem. On the meantime, i've got enough time to testout localtuya and it solved my zigbee sensor.

I have now use localtuya on my own repo: https://github.com/leeyuentuen/localtuya

It works for my smartplugs and most of my zigbee sensors like temp and motion sensor.

Now i have tuya and localtuya using together. And set my motion sensor automatio'non both enitity. So if tuya failed to detect my motion sensor, localtuya will take over. Or if tuya response too late, localtuya can take over.

@enchantedphoenix
Copy link

The issue is still ongoing it seems and it really messes with automations that call for the device state as a condition, I think this is a Tuya issue but it's really disappointing as the vast majority of lightbulbs and other devices use Tuya so I'm sure this is affecting a few thousand people to say the least :/

@alexanv1
Copy link
Contributor

@frenck can we consider adding polling to the Tuya integration to workaround all of these issues?
Perhaps enabled via a integration config parameter so that it can be turned on and off whenever Tuya cloud is misbehaving?

When the issue occurs, the polled device state is actually correct. It seems only the state change notification isn't sent or sent with the wrong data. Polling every 30 seconds doesn't fully fix it but at least mitigates it sufficiently for vast majority of folks.

tuya_iot provides a update_device_caches method on TuyaDeviceManager so it seems that calling it for all devices and triggering HA updates would be straightforward...

Seems that polling is significantly better than what folks are doing with reloading the integration every 30 seconds, etc.

@frenck
Copy link
Member

frenck commented Feb 18, 2022

@alexanv1 That is not a solution.

@alexanv1
Copy link
Contributor

@alexanv1 That is not a solution.

If it solves the issue for vast majority of scenarios, it is a solution :)
Or at least a viable workaround given how many folks are running into this issue.

Anyway, just a suggestion, feel free to ignore. I run a custom fork of the Tuya integration anyway so will implement it there but won't be putting out a PR given that it won't be considered it seems like.

@frenck
Copy link
Member

frenck commented Feb 18, 2022

If it solves the issue for vast majority of scenarios, it is a solution :)

It doesn't

Or at least a viable workaround given how many folks are running into this issue

Workaround are not solutions

feel free to ignore.

I didn't, I just answered that I don't agree with doing that.

There are tons of problems with adding polling to an infrastructure that is not designed for it. The most obvious case issues handling the number of requests coming in at Tuya's servers that are designed around a different principle: Push.

Making changes and workarounds such as you are suggesting often end up with major problems. I would not be the first time a vendor starts blocking people and/or Home Assistant users because of such practices.

So, while I get your suggestion, it has a major impact when doing things like that in integration with high usage like this one. Additionally, the workaround does not solve anything and tends to increase the maintenance burden over time (which no one will benefit from).

@martinw72
Copy link
Author

I'm not sure if this would help. First we need a closer look what is going wrong! If we use the same method to do a status update as is done during changing the switch state than the issue would stillbexist!

@frenck
Copy link
Member

frenck commented Feb 18, 2022

@martinw72 I'm not following that response?

@alexanv1
Copy link
Contributor

@martinw72, it would help. The device state reported when actually querying the Tuya Cloud API is correct. The state change notification that Home Assistant relies upon is missed or contains stale data. I literally have a switch right now that's reported as ON in HA when it's actually OFF and the cloud API returns the correct state when querying :)

But, anyway, the powers that be won't consider this solution (for reasons that I completely disagree with but this isn't the first Tuya-related argument I simply give up on with respect to HA) so I guess folks are stuck waiting for Tuya to fix their cloud again...

@frenck
Copy link
Member

frenck commented Feb 18, 2022

so I guess folks are stuck waiting for Tuya to fix their cloud again

Yes, I cannot fix their code or service. Trying to break it by sending in tons of requests, will not help with that either. At best it will piss them off.

I simply give up on with respect to HA

Sorry to hear that. I understand that Home Assistant might not be a fit for you in that case.

It is one of the prices of cloud devices as well. In the end, I would definitely recommend consider buying product that work locally and do not rely on their cloud to function.

@alexanv1
Copy link
Contributor

alexanv1 commented Feb 18, 2022

so I guess folks are stuck waiting for Tuya to fix their cloud again

Yes, I cannot fix their code or service. Trying to break it by sending in tons of requests, will not help with that either. At best it will piss them off.

Well, the recommended solutions that I've seen in multiple bug reports are to reload the integration every x seconds\minutes. That's probably worse than polling in terms of # of API calls but I guess the hope is that most folks won't implement that workaround.

I simply give up on with respect to HA

Sorry to hear that. I understand that Home Assistant might not be a fit for you in that case.

Home Assistant is a perfect fit actually since it allows me to run anything I want as a custom integration (though rebasing is a pain every now and then). Though I do sometimes wish there was more of a customer\user focus vs. technology focus :)

@craigrouse
Copy link

@frenck despite being a frustrated Tuya user, I do agree that sending lots of extra requests is likely to exacerbate the problem. Do you have any lines of communication with Tuya that might help to convince them to take the problem seriously? They don't seem to care when end users contact them - support requests just seem to go into a black hole. It's a shame, because I bought a lot of Tuya kit on the promise they made to support HA, and now I wish I'd spent a bit more on something that works. It's worth noting I have occasionally seen some slow responses in the official Tuya app regarding device status updates, so it's possible the issue doesn't just affect the HA/Python integration. 🤞 this can be resolved soon.

@frenck
Copy link
Member

frenck commented Feb 18, 2022

@craigrouse I understand, and I hope the same (as someone who tries to help out on the Tuya integration, reading up on this is just frustrating for me too). We do have some lines open with Tuya.

For me personally, I've not been able to reproduce the issue. I know there are quite a few reports, so I'm not saying nothing is wrong (something is very wrong for sure); but not being able to reproduce it myself makes it just a guessing game for me.

@alexanv1
Copy link
Contributor

For anyone willing to run Tuya as a custom\modified component and interested in the polling workaround discussed above feel free to pull in this commit - alexanv1@5584b25
Works well enough for me but, obviously, no support is offered so use at your own risk :)

@leeyuentuen
Copy link
Contributor

leeyuentuen commented Feb 18, 2022

For anyone willing to run Tuya as a custom\modified component and interested in the polling workaround discussed above feel free to pull in this commit - alexanv1@5584b25 Works well enough for me but, obviously, no support is offered so use at your own risk :)

polling is a workaround but if you do it every 30 seconds, the limit of your API call on tuya will be increased, (there is a limit free API call from tuya server, otherwise you need to change to paid service)

@alexanv1
Copy link
Contributor

For anyone willing to run Tuya as a custom\modified component and interested in the polling workaround discussed above feel free to pull in this commit - alexanv1@5584b25 Works well enough for me but, obviously, no support is offered so use at your own risk :)

polling is a workaround but if you do it every 30 seconds, the limit of your API call on tuya will be increased, (there is a limit free API call from tuya server, otherwise you need to change to paid service)

Yeah, I did the math based on https://developer.tuya.com/en/docs/iot/pricing?id=Kazp2q5zpwdav
Assuming extra ~90,000 calls a month (a single API call every 30 seconds), I am looking at $0.30/month or so. That's easily worth it for me to get updates working again. Perhaps my math is wrong though, I guess I will find out in a few weeks :)

@andreasbuff
Copy link

andreasbuff commented Feb 19, 2022 via email

@enchantedphoenix
Copy link

enchantedphoenix commented Feb 19, 2022 via email

@craigrouse
Copy link

@enchantedphoenix that's because this is a Tuya server issue and nothing to do with HA. Don't hold your breath - I expect it's only working temporarily.

@craigrouse
Copy link

It does seem to be working much better for me now. I can only assume Tuya have fixed something on their end. Is everyone else seeing the same?

@leeyuentuen
Copy link
Contributor

They told me on the ticket that there was a message issue (disconnect) between HA en tuya server.

@martinw72
Copy link
Author

Guys I did some tests this moring and at the moment the situation has improved. Seems 95% of the time the state is now updated. I switch very fast between states with one time a mismatch! But this could have other reasons, too!

@craigrouse
Copy link

I would say this is 100% resolved. Status updates are now immediate and have been working flawlessly for a few days. I think we can close this for now... until next time!

@DIMMonchik
Copy link

DIMMonchik commented Mar 14, 2022

Only I have taya updated every other time today?

Logger: tuya_iot
Source: /opt/homeassistant/lib/python3.9/site-packages/tuya_iot/openmq.py:117
First occurred: 11:21:08 (2 occurrences)
Last logged: 11:21:08

Unexpected disconnection.16

@enchantedphoenix
Copy link

enchantedphoenix commented Mar 23, 2022 via email

@github-actions
Copy link

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.

@github-actions github-actions bot added the stale label Jun 21, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests