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
73.4k stars 30.65k forks source link

Tuya doesn't send state of devices #63052

Closed Floris039 closed 1 year ago

Floris039 commented 2 years ago

The problem

When a light bulb or other tuya device is turned on/off the state isn't changed in HA. The device stays the state it was switched to even when you try to change it after a while.

What version of Home Assistant Core has the issue?

2021.12.7

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

No response

Link to integration documentation on our website

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

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

probot-home-assistant[bot] commented 2 years ago

tuya documentation tuya source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

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)

jreidel commented 2 years ago

I can confirm this after updating to 12.7. None of my HEIMAN BW-SHP13 smart plugs are reporing anymore

Istria1704 commented 2 years ago

I also still have the same problem with tuya light states not updating. The issue has been closed as its supposed to be fixed in 12.6. But although it worked for a while (although the updates were slower than the used to be) after updating, now again I have the same problem. The lights can be controlled. But the states are incorrect.

gringoireDM commented 2 years ago

I confirm having this same issue. It seems, this works correctly for 10 minutes or so, then the status is not reported/reported incorrectly. After the other thread was closed, I created an automation that restarts the integration every 15 minutes. I would like to avoid to do so, but right now I feel the only way to avoid doing that is to move away from Tuya. unfortunately the integration in these conditions is too unreliable, and the alternatives are too hacky (local Tuya)

Istria1704 commented 2 years ago

It works fine again now. Although a little bit slow sometimes compared to "the old days". But very much functional. Let's see how it holds up.

bockelaar commented 2 years ago

confirm: updates still not working correct. i see a lot of issues like this closed but problem is imo not fixed.

frenck commented 2 years ago

There are two issues.

First: a technical one, which has been fixed in .7 Second: incorrect configuration by the end-user, not having setup their Tuya account correctly.

The second isn't fixable by Home Assistant.

bockelaar commented 2 years ago

the 2nd is a bit tricky: tha API changed, setting up the tuya integration changed. i think i setup the Tuya side correct. Debugging the entities on that side show no errors and all working well. Perhaps some guidance on what the correct setup is would be helpful to determine where things go wrong. Any logs which are needed can be provided.

frenck commented 2 years ago

Perhaps some guidance on what the correct setup is would be helpful to determine where things go wrong

See the documentation of Home Assistant.

bockelaar commented 2 years ago

i followed all those a couple of times.

bockelaar commented 2 years ago

ok. just debugged a little: 2021-12-31 12:44:20 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140162252726624] Received {'type': 'call_service', 'domain': 'light', 'service': 'turn_on', 'service_data': {'entity_id': 'light.smart_bulb_rgbcw'}, 'id': 29}

2021-12-31 12:44:20 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=light, service=turn_on, service_data=entity_id=light.smart_bulb_rgbcw>

[2021-12-31 12:44:20,885] [tuya-openapi] Request: method = POST, url = https://openapi.tuyaeu.com/v1.0/devices/SOME-ID/commands, params = None, body = {'commands': [{'code': <DPCode.SWITCH_LED: 'switch_led'>, 'value': True}]}, t = 1640951060885

2021-12-31 12:44:20 DEBUG (SyncWorker_0) [homeassistant.components.tuya.base] Sending commands for device SOME-ID: [{'code': <DPCode.SWITCH_LED: 'switch_led'>, 'value': True}]

2021-12-31 12:44:20 DEBUG (SyncWorker_0) [tuya_iot] Request: method = POST, url = https://openapi.tuyaeu.com/v1.0/devices/SOME-ID/commands, params = None, body = {'commands': [{'code': <DPCode.SWITCH_LED: 'switch_led'>, 'value': True}]}, t = 1640951060885

[2021-12-31 12:44:20,958] [tuya-openapi] Response: { "result": true, "success": true, "t": 1640951060951 }

2021-12-31 12:44:20 DEBUG (SyncWorker_0) [tuya_iot] Response: { "result": true, "success": true, "t": 1640951060951 }

2021-12-31 12:44:20 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140162252726624] Sending {"id": 29, "type": "result", "success": true, "result": {"context": {"id": "SOME-ID2", "parent_id": null, "user_id": "SOME-ID3"}}}

The light (in this case) switches on. The switch moves to on and to off again in lovelace. Result is that the light is turned on, lovelace thinks it is off. Reloading the addon makes lovelace know the switch should be on.

(i hope t is just a timestamp number :) )

frenck commented 2 years ago

There is a communication missing, which is the new state. This requires the IoT notification subscription to be active an set up correctly in your Tuya account.

So the new updated state isn't pushed into Home Assistant from Tuya right now (the confirmation the state actually changed or not)

bockelaar commented 2 years ago

image

all there according the docs

frenck commented 2 years ago

I am not sure what to tell you m8, your Tuya account doesn't send status updates. We cannot magically make those out of nothing.

I suggest, if you are absolutely sure you have correctly configured your account and have an active subscription, to contact Tuya support.

I wish I could help you, but we can not act on something that isn't there.

bockelaar commented 2 years ago

i know :) its cosmetic. Searching for a month+ now on where it goes wrong. Cant you create an addon which automagically fills in missing blanks? ;) appreciate your comments, thanks!

frenck commented 2 years ago

It isn't cosmetic, your account isn't working correctly, as shown by the logs.

Are you sure your subscription on the device notification module is active an not expired? Is the expiration date for the subscription on that module in the future?

bockelaar commented 2 years ago

yep. i even extended it last week, just to be sure it didnt expire in januar image

frenck commented 2 years ago

Send them a support message, it might as well be another issue on their end.

bockelaar commented 2 years ago

i did ID:T20211231someRNG(You are a Basic Edition user and promise to answer you within 12 hours (working time),Improve response speed)

jocamane commented 2 years ago

Here the same. This problem has been around for over a month. I wonder if anyone can resolve this once and for all. I am thinking of giving up on HA sincerely. I have about 60 tuya devices and so I work with smartlife, at least I don't have these problems

Istria1704 commented 2 years ago

For me, it works OK (slowish, but works) when I flip the switches in HA. But if I turn on/off lights with an automation, the switches stay at the old position.

bockelaar commented 2 years ago

i am wondering: there is a response coming back: [2021-12-31 12:44:20,958] [tuya-openapi] Response: { "result": true, "success": true, "t": 1640951060951 }

2021-12-31 12:44:20 DEBUG (SyncWorker_0) [tuya_iot] Response: { "result": true, "success": true, "t": 1640951060951 } t= epoch format time, result and success both are TRUE, so switch is turned to ON (in this case). is the response in a wrong format/unexpected format?

frenck commented 2 years ago

i am wondering: there is a response coming back

That is the confirmation of the command received, another message is expected after that, the one that announces the new state of the device.

So, in your logs, the command is send and received, but not confirmed (as in, not confirmed by the new device state)

frenck commented 2 years ago

Here the same. This problem has been around for over a month. I wonder if anyone can resolve this once and for all. I am thinking of giving up on HA sincerely. I have about 60 tuya devices and so I work with smartlife, at least I don't have these problems

Sorry to hear you are having issues, as stated above, this is a Tuya issue/user configuration issue as far as we are aware. Up until now, no-one has been able to point out an issue the Home Assistant end that causes this.

If you can provide a proper reproduction or logs that show otherwise; than I am the first in line to help fixing the issue.

bockelaar commented 2 years ago

ah right, makes sense. thanks!

maijo366 commented 2 years ago

I have the same issue. The Status of the switches ar not up to date in HA. I push the on button the switch is going on, but in a view seconds the button goes back and the switch stays on. Doubletap on the button turns the switch off. When i reload the integration TUYA the status change and is correct. On the SmartLife App and on Tuya i can see the correct status.

anisite commented 2 years ago

I have same problem. Fixed it two days but come back.... what is your region? I'm in canada, it's the issue?

jocamane commented 2 years ago

I have same problem. Fixed it two days but come back.... what is your region? I'm in canada, it's the issue?

i'm in Portugal

escobarin3 commented 2 years ago

For the last couple of days all of my Tuya devices are randomly updating.... Most of the time they do not update their status. My suscription are up to date. I had this issue last year and "fixed" with an automation when an ERROR in the tuya_iot appeared in logs ... But now, no errors in log. I'm from Western America server. It's driving me crazy... any ideas?

bockelaar commented 2 years ago

log a call with Tuya, as Frenck suggested. imo the only way to let tuya know their API is lacking some values. I had a tuya engineer testing an working on it, he tried several things, i uploaded a bunch of debug logs etc. Issue is still not resolved, but they are not reacting/updating the call since 5th January. Ah well... pay peanuts, get this i guess :(

bockelaar commented 2 years ago

@frenck FYI: tuya is not solving this it seems. posting the transcript of the logged issue at tuya goes too far for here but debugging the tuya end is not really progressing :) their response: Tuya engineer01-12 11:31:04 By querying the return value of the tuya interface, we did not find that there is no return. It is recommended to consult the homeassistant official if they can provide a way to find the details of the problem.

jocamane commented 2 years ago

What I think is that they are pushing each other and the problem is not solved. I'm leaving Home assistant. So I don't need it.

jocamane commented 2 years ago

You can write in the description of the home assistant that works with everyone but not with tuya

frenck commented 2 years ago

What I think is that they are pushing each other and the problem is not solved.

This is an open source project. The code be verified and read.

Enable the debug logging and see very single detail that goes over the line.

If one still thinks it's our issue, based on all that, please let me know.

@jocamane 👋

escobarin3 commented 2 years ago

My tuya devices have been working perfect for the last 48 hours now. I did nothing in HA nor Tuya to fix it... So I guess the failure was on Tuya's end.

jocamane commented 2 years ago

I don't say that it's HA's fault, but instead of users reporting to tuya, if it's the HA people I think they have more strength

gringoireDM commented 2 years ago

I gave up on this integration, yet I'd like to figure out what went wrong. The thing that makes me think it cannot be on Tuya side is that if I restart the integration it works for some time (in the order of hours) then it stops. If it was on Tuya side a restart shouldn't do anything. Unfortunately I can't debug anything as I rage trashed the wifi switches I had to try out Tuya.

bockelaar commented 2 years ago

tuya is ignoring my comments. they stated the issue is on HA's side, go bug them. I may have remarked something about customer intimacy in their issue but i expect nothing close to a solution.

I might try to delete all entries, remove the tuya integration, remove smartlife app, remove tuya projects and start from scratch, but that has a too big impact for now.

For now i created an automation that reloads the integration every 30 seconds to get all the switches show up correct. I will not consider buying tuya stuff any time soonish and am looking for alternatives.

anisite commented 2 years ago

You can look at localtuya HACS extension, I ended with it after official cloud version state problem.

maijo366 commented 2 years ago

tuya is ignoring my comments. they stated the issue is on HA's side, go bug them. I may have remarked something about customer intimacy in their issue but i expect nothing close to a solution.

I might try to delete all entries, remove the tuya integration, remove smartlife app, remove tuya projects and start from scratch, but that has a too big impact for now.

For now i created an automation that reloads the integration every 30 seconds to get all the switches show up correct. I will not consider buying tuya stuff any time soonish and am looking for alternatives.

Can you please give me the automation.yaml, you have created. Thanks so much.

bockelaar commented 2 years ago
jocamane commented 2 years ago

I've also had this automation implemented, but the problem with this automation is that when you have anhother automation running that has relay time, when you reload tuya the automation stops. this and other examples that can happen.

bockelaar commented 2 years ago

Tuya states the reply is send and shows this snippet of logs. Question is where the body disappears between tuya and HA? @frenck is it worth debugging more or leave it here and move on?

addfbb06a191dd1b
zlinoliver commented 2 years ago

Hi @bockelaar , sorry for the inconvenience! We have investigated the information you have provided to Tuya technical support, including your account info, home assistant log and even create a virtual device with the same DP codes as your light device. Unfortunately, we cannot reproduce your issue on our side. The cloud API did return data to you after querying the log using your timestamp.

It is recommended that you do not modify the code or add any debug configuration and try again. Also, have you tried other Tuya devices besides the light device?

BTW, your issue is not related to Home Assistant side as @frenck explains above. Thanks for the understanding.

bockelaar commented 2 years ago

hi @zlinoliver i am not blaming HA, i am caught somewhere in bit-hell, between two sides :) It is not only the bulbs, the smartplugs show the same behaviour, and the wifi doorsensor gives the wrong states as well. I am lost in where or what to debug and do not know what can be the solution? Should i just remove all tuya from both tuya and HA and start from scratch? It is weird, the logs do not give hints on where things go wrong.

thanks!

LightAngel8366 commented 2 years ago

Unfortunately I've been having the same problem for a few days. Neither the status of the lamps nor that of various door sensors is updated. Unfortunately, Home Assistant is not useful for me, which I would find extremely unfortunate, because otherwise it is great. Is there already a solution? Only when I reload the Tuya integration is the status updated for a few moments and then it's over again.

Thanks.

cvroque commented 2 years ago

Sadly I'm also having the same issue this entire month, without any error on the logs.

This doesn't happen with all devices at the same time, one light can be in the unresponsive state (displaying as on while turned off and vice versa) and the other is working normally, but eventually all devices can display this erroneous behavior until I restart HA and/or reload the integration. This also means that this issue will be a pain to reproduce.

I also checked all the necessary services and made sure they didn't expire:

image

Status in the Smart Life app remain correct.

Due to the lack of errors, I recorded a short video showing the issue with two different tuya devices, I'll open a ticket on tuya cloud support and send it there.

After any command, devices without this issue will receive update messages like this while debugging:

2022-01-26 16:20:39 DEBUG (Thread-12) [tuya_iot] mq _on_device_report-> [{'1': True, 'code': 'switch_1', 't': '1643224838', 'value': True}]
2022-01-26 16:20:39 DEBUG (Thread-12) [homeassistant.components.tuya] Received update for device 070410025002910dee4d: {'switch_1': True, 'countdown_1': 0, 'add_ele': 16, 'cur_current': 236, 'cur_power': 403, 'cur_voltage': 2214

Meanwhile devices out of sync don't seem to receive this "device update" and don't generate any error either.

bockelaar commented 2 years ago

out of the blue Tuya updated the servicecall which was still marked unresolved in their systems: "Hello, I'm sorry to keep you waiting for so long. As for your problem, we are working on it. We will send you the results as soon as possible." Looking forward for their finds 👍

bockelaar commented 2 years ago

heh, a new update from Tuya: "We have gone through a complete testing process and cannot reproduce the problem, that is, we have not found a way to find the reason why the interface does not return data (as you have reported), so we recommend that we continue to observe whether there are large batches of data. The problem happens, we work together to solve the problem."

Time to stop hoping for a solution i think :)