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.75k stars 28.91k forks source link

Tuya Power Sensor Latency #115878

Open pwhitea opened 2 months ago

pwhitea commented 2 months ago

The problem

I have noticed that the readings from a number of sensors that I use for power monitoring in the energy dashboard are inacurate since 2023.12.1 release. I am comparing the sensor value from the Tuya integration with the value in the Smart Life app and see there is a considerable refresh latency occurring. When I compare my energy dashboard prior to Dec 2023 to historic data in the Smart Life app there were slight variances (5-10%) but generally cumulative daily values were comparable, now my enegy dashbaord readings are C 10x lower than cumulative values in smart life. Initially I thought that I had a problem with Riemann Sum's but following investigation its the actual sensor values being provided by the Tuya integration.

If I compare real time between a HA sensor and Smart Life app there is a discrepancy for all smart plug devices I have (10 in total) at any point in time. Close comparison of the HA power sensor and smart life real time power reading shows that the only time the two are comparible is after the integration has been reloaded, they then remain comparible for C10 minutes before the latency appears again. It appears that the appliance attached to the smart plug (in this case a TV) varies its power consumption - smart life captures this but HA does not.

Sharing an example of this, both screenshots taken at the same time

IMG_7453

Screenshot 2024-04-20 100735

What version of Home Assistant Core has the issue?

2024.4.3

What was the last working version of Home Assistant Core?

2023.12.1

What type of installation are you running?

Home Assistant Container

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?

No response

Additional information

No response

home-assistant[bot] commented 2 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. - `@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)

pwhitea commented 2 months ago

Here is a further example of the problem. In this case the Tuya plug is on a washing mashine, in this case the washer is running thus as you can see in the Smart Life app there are ongoing changes to power consumption yet in HA there has been no update come through for 6 minutes. While I realise there will always be some missed updates what I am seeing is that in HA sensor values are in some cases not updating for 30 minutes. Updates seem to be be better for the first 30-60 minutes after restarting the Tuya integration but then I see the problem in this video.

https://github.com/home-assistant/core/assets/112006314/cd3011a0-ceaf-462c-9f5c-7a35f6a3e96a

jonwaland commented 2 months ago

suspect its the cloud connection failing - see https://github.com/home-assistant/core/issues/115344

niltonvasques commented 2 months ago

Same issue here! In my case, updates in my case is taking 5~30 minutes. image

pwhitea commented 2 months ago

@niltonvasques thats exactly what I am seeing, after a restart senors update frequently, but after 10 minutes I get 30 min + delays on sensor updates when I can see changes on Smart Life.

@jonwaland have checked the logs/run debug and I am seeing no errors on my installation

jonwaland commented 2 months ago

have checked the logs/run debug and I am seeing no errors on my installation

I often dont get errors - even with Debug. What I get is "misses":

024-04-10 17:23:03.759 DEBUG (SyncWorker_52) [homeassistant.components.tuya] Sending commands for device 02000855807d3a4f4853: [{'code': <DPCode.SWITCH_1: 'switch_1'>, 'value': True}]
2024-04-10 17:23:06.203 DEBUG (Thread-2611 (_thread_main)) [homeassistant.components.tuya] Received update for device 02000855807d3a4f4853: {'switch_1': True, 'switch_2': True}
2024-04-10 17:24:43.365 DEBUG (SyncWorker_32) [homeassistant.components.tuya] Sending commands for device 02000855807d3a4f4853: [{'code': <DPCode.SWITCH_2: 'switch_2'>, 'value': True}]
2024-04-10 17:25:08.687 DEBUG (SyncWorker_59) [homeassistant.components.tuya] Sending commands for device 02000855807d3a4f4853: [{'code': <DPCode.SWITCH_2: 'switch_2'>, 'value': True}]
2024-04-10 17:25:09.672 DEBUG (Thread-2803 (_thread_main)) [homeassistant.components.tuya] Received update for device 02000855807d3a4f4853: {'switch_1': True, 'switch_2': True}
2024-04-10 17:25:13.867 DEBUG (SyncWorker_34) [homeassistant.components.tuya] Sending commands for device 02000855807d3a4f4853: [{'code': <DPCode.SWITCH_2: 'switch_2'>, 'value': False}]
2024-04-10 17:30:10.396 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.current_uv_index is taking over 10 seconds

each send should have a corresponding update. to set the new state.

but 2024-04-10 17:24:43.365 DEBUG (SyncWorker_32) and 2024-04-10 17:25:13.867 DEBUG (SyncWorker_34) didn't receive an update. meaning HA was out of sync with reality...

If you enable debug, I suspect you will see regular "Received update" messages, but with gaps...

pwhitea commented 2 months ago

Same here, I am getting no errors and the debug shows nothing. The only way of re-creating the problem I am seeing is to physically compare the Smart Life app with the data hitting Home Assistant.

pwhitea commented 2 months ago

Hey @tuya, @zlinoliver, @frenck, any updates on this one?

Mindful that this issue has been present for some time assuming that it relates to Tuya cloud services and not an easy fix. With that in mind just bought 4 TP-Link P110 plugs and can report that they work perfectly - consumption reported by HA / App the same. Appreciate an update as if this is going to be a lengthy fix will buy more TP-Link devides and get my Tuya ones listed on Ebay!

niltonvasques commented 1 month ago

Some smartplug devices I could fix by connecting them to HA via tuya local (https://github.com/make-all/tuya-local/issues/420#issuecomment-1435765676), but not for all of them.

juanmijm commented 1 month ago

same here, I have 2 smarts plugs updating sensors every long long time, before it had the unofficial LAN integration with those same plugs and it updated very quickly.

The strange thing is I have others tuya devices updating every 5 seconds, with this same integration, Is there anything I can do? I think it was a mistake to switch to the official integration...