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

Power monitor smart plugs only updating usage rapidly when Smart Life app is opened #211

Open
jellekpsn opened this issue Jul 24, 2021 · 31 comments
Labels
bug Something isn't working

Comments

@jellekpsn
Copy link

Describe the bug
Elvico smart power monitor plug integrates well into Tuya V2 well, but current and power metrics are only updated infrequently (once a minute, on average) However, when I open the Smart Life app and view the 'Electric' tab, the values are updated every 2 seconds or so.

Expected behavior
To have the power and current values from the smart plug update every few seconds, even when the Smart Life app is not is use.

Screenshots
Not applicable

Home Assistant Version

  • e.g. 2021.7.0

Device info (please complete the following information, which can be found in log):
like this:
{
"active_time": 1610826786,
"biz_type": 18,
"category": "cz",
"create_time": 1610826786,
"icon": "smart/device_icon/eu1510865353607K7oJW/bf2a17e8f775e3fc3fqqqk161435492361950.png",
"id": "bf2a17e8f775e3fc3fqqqk",
"ip": "REDACTED",
"lat": "REDACTED",
"local_key": "REDACTED",
"lon": "REDACTED",
"name": "Kitchen Spots",
"online": true,
"owner_id": "489452",
"product_id": "j0zozzoarutv0nu1",
"product_name": "Wifi Plug",
"status": [
{
"code": "switch_1",
"value": true
},
{
"code": "countdown_1",
"value": 0
},
{
"code": "add_ele",
"value": 6
},
{
"code": "cur_current",
"value": 105
},
{
"code": "cur_power",
"value": 149
},
{
"code": "cur_voltage",
"value": 2318
},
{
"code": "relay_status",
"value": "last"
}
],
"sub": false,
"time_zone": "+01:00",
"uid": "REDACTED",
"update_time": 1626178437,
"uuid": "REDACTED"
}

Device specifications (please complete the following information, which can be found in log):
2021-07-24 23:54:42 DEBUG (SyncWorker_4) [tuya iot] Request: method = GET, url = https://openapi.tuyaeu.com/v1.0/devices/bf2a17e8f775e3fc3fqqqk/specifications, params = None, body = None, headers = {'client_id': 'REDACTED', 'sign': 'B50E83C8A2F46CD097F3ABABBF37D9A37634FFBD238261E2D63B2E69D3447F45', 'sign_method': 'HMAC-SHA256', 'access_token': 'REDACTED', 't': '1627163682915', 'lang': 'en'}
2021-07-24 23:54:42 DEBUG (SyncWorker_4) [tuya iot] Response: {
"result": {
"category": "cz",
"functions": [
{
"code": "switch_1",
"type": "Boolean",
"values": "{}"
},
{
"code": "countdown_1",
"type": "Integer",
"values": "{"unit":"s","min":0,"max":86400,"scale":0,"step":1}"
},
{
"code": "relay_status",
"type": "Enum",
"values": "{"range":["power_off","power_on","last"]}"
}
],
"status": [
{
"code": "switch_1",
"type": "Boolean",
"values": "{}"
},
{
"code": "countdown_1",
"type": "Integer",
"values": "{"unit":"s","min":0,"max":86400,"scale":0,"step":1}"
},
{
"code": "add_ele",
"type": "Integer",
"values": "{"unit":"kW·h","min":0,"max":50000,"scale":3,"step":100}"
},
{
"code": "cur_current",
"type": "Integer",
"values": "{"unit":"mA","min":0,"max":30000,"scale":0,"step":1}"
},
{
"code": "cur_power",
"type": "Integer",
"values": "{"unit":"W","min":0,"max":80000,"scale":1,"step":1}"
},
{
"code": "cur_voltage",
"type": "Integer",
"values": "{"unit":"V","min":0,"max":5000,"scale":1,"step":1}"
},
{
"code": "relay_status",
"type": "Enum",
"values": "{"range":["power_off","power_on","last"]}"
}
]
},
"success": true,
"t": 1627163682952
}
Additional context
Not actually sure this is a bug in the Tuya V2 integration of that the smart plug needs some sort of 'nudge' to relay energy values every few seconds.

Thanks!

@jellekpsn jellekpsn added the bug Something isn't working label Jul 24, 2021
@Bjarkes
Copy link

Bjarkes commented Jul 25, 2021

I have the same issue with the Denver SHP-100 Smart Plug.
It is the same behavior when using the API directly (from iot.tuya.com or any library), call it directly or look at the Device Log on iot.tuya.com.
If the app is not open in the "Electric" tab, then the updates comes very infrequent, sometimes more than an hour in-between.

@joe-sydney
Copy link

Same here with the Kogan smart plug with energy monitoring and 2 USB ports

@AdmiralStipe
Copy link

Same issue here with Robaxo RSP-025 plug - obviously NOT flashed with Tasmota, but this is the only link I found on them.
Log shows nothing unusual, just the consumption isn't updating in HA unless I have TuyaSmart app opened all the time on Electricity tab - then it works perfectly, but of course only for the plug, which I'm observing in TuyaSmart.

@calvinwankhede
Copy link

Same problem with the Wipro Smart plug. Description of the issue matches AdmiralStipe's down to the T.

@AdmiralStipe
Copy link

AdmiralStipe commented Aug 8, 2021

If this is of any help to developers, this link from another git issue with a concept of requesting updates (with so called "command 18") might give a way towards the solution (the issue was not resolved at original git, as it has gone somehow dormant).

@brunokelo
Copy link

same problem here,

@burnworld3d
Copy link

@tsutsuku is there anything we can provide to help you to track this issue?
Or is more a thing that you need to forward to the IOT api team?
thanks

@Bjarkes
Copy link

Bjarkes commented Aug 12, 2021

Here we traced the problem down to the device being more picky with the payload of the updateDPS command:
jasonacox/tuyapower#7
I have solved my problem temporarily by having a Python script using tinytuya, that call the UpdateDPS with the correct payload periodically, which will then result in data coming in via tuya-home-assistant correctly.

@burnworld3d
Copy link

Here we traced the problem down to the device being more picky with the payload of the updateDPS command:
jasonacox/tuyapower#7
I have solved my problem temporarily by having a Python script using tinytuya, that call the UpdateDPS with the correct payload periodically, which will then result in data coming in via tuya-home-assistant correctly.

I see, however this is a very 'custom' solution tho, specially if you plan to use with LocalTuya and similar (as you need to have the key for each of your devices)
Since we get official support, Tuya team needs to fix this thingy on their end, since they have all our devices data

But thanks anyway to let me know about your solution, very interesting!

@Bjarkes
Copy link

Bjarkes commented Aug 12, 2021

Yes I very much agree that this should be fixed by the Tuya Team. Either they fix the firmware for these devices, or make sure to call the updateDPS in the correct way for these devices.

And yes, my temporary fix will not work with LocalTuya (I have tried), as tinytuya use the same type of connection as LocalTuya, and the device does only allow one such client to be connected at any time, so they battle over the connection and take turns getting a disconnected error.

@joe-sydney
Copy link

Yes I very much agree that this should be fixed by the Tuya Team. Either they fix the firmware for these devices, or make sure to call the updateDPS in the correct way for these devices.

And yes, my temporary fix will not work with LocalTuya (I have tried), as tinytuya use the same type of connection as LocalTuya, and the device does only allow one such client to be connected at any time, so they battle over the connection and take turns getting a disconnected error.

Excellent tip. I was playing around with updateDPS, etc, with localtuya, but it didn't work due to the reason you mentioned. Here with Tuya v2, it has worked well. I use node-red to trigger the tinytuya updateDPS with different intervals depending on what the plug was used to connect (only use it to detect if something is operating so having a real time stream was not really required).

@Leatherface75
Copy link

Leatherface75 commented Aug 26, 2021

Got it working with tinytuya with a script that updates every second.
Not sure how to do this with localtuya/tuya2 plugin but can't see how this would be hard to implement.

import tinytuya
import time

d1 = tinytuya.OutletDevice('<device id>', '<ip>', '<device key>', 'device22') # DELTACO Smart Plug SH-P02 1
d2 = tinytuya.OutletDevice('<device id>', '<ip>', '<device key>', 'device22') # DELTACO Smart Plug SH-P02 2
d3 = tinytuya.OutletDevice('<device id>', '<ip>', '<device key>', 'device22') # DELTACO Smart Plug SH-P02 3

d1.set_version(3.3)
d2.set_version(3.3)
d3.set_version(3.3)
d1.set_socketPersistent(True)
d2.set_socketPersistent(True)
d3.set_socketPersistent(True)

while(True):
    payload1 = d1.generate_payload(tinytuya.UPDATEDPS)
    payload2 = d2.generate_payload(tinytuya.UPDATEDPS)
    payload3 = d3.generate_payload(tinytuya.UPDATEDPS)
    d1.send(payload1)
    d2.send(payload2)
    d3.send(payload3)
    time.sleep(1)

@AdmiralStipe
Copy link

To the developers, please, implement the solution Martin commited here. It polls updates with a heartbeat (10s) and it works perfectly.

@joe-sydney
Copy link

Hey all. I just got a charge from Tuya for exceeding quotas. All I have are 2 of the Kogan plugs, and triggering them to update energy data via the tinytuya method discussed above. (See bill info below).

Is this expected and caused by the energy data updates? Anyone else experience this, and how can we minimise the API calls/messages to stay within quota?

API CALL FOREIGN TRIAL数量 API CALL FOREIGN TRIAL费用
1549 3.3

@Leatherface75
Copy link

Leatherface75 commented Sep 9, 2021

That sounds strange have you done this first?

https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md

Also updating every 5 or 10 seconds maybe is enough for most people.
Above exemple updates every second.

@joe-sydney
Copy link

That sounds strange have you done this first?

https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md

Also updating every 5 or 10 seconds maybe is enough for most people.
Above exemple updates every second.

yeah, not sure what happened there. I received an email notification to check the details on the IoT Platform portform. Indeed, there was a $2+ charge. But today its been changed to zero.

I was triggering the tinytuya updateDPS commands via Node Red, every 15 seconds and 60 seconds for the two plugs, as I didn't really need constant streams of updates.

@brunokelo
Copy link

That sounds strange have you done this first?
https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md
Also updating every 5 or 10 seconds maybe is enough for most people.
Above exemple updates every second.

yeah, not sure what happened there. I received an email notification to check the details on the IoT Platform portform. Indeed, there was a $2+ charge. But today its been changed to zero.

I was triggering the tinytuya updateDPS commands via Node Red, every 15 seconds and 60 seconds for the two plugs, as I didn't really need constant streams of updates.

can you explain how you did it on node red?

thanks

@joe-sydney
Copy link

It was using basically the same script (for each device) without infinite loop. Then I used Node-red to call that script at the required intervals.

I have since reverted back to localtuya as there is a fix there now which sends the updateDPS at regular intervals.

That sounds strange have you done this first?
https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md
Also updating every 5 or 10 seconds maybe is enough for most people.
Above exemple updates every second.

yeah, not sure what happened there. I received an email notification to check the details on the IoT Platform portform. Indeed, there was a $2+ charge. But today its been changed to zero.
I was triggering the tinytuya updateDPS commands via Node Red, every 15 seconds and 60 seconds for the two plugs, as I didn't really need constant streams of updates.

can you explain how you did it on node red?

thanks

@brunokelo
Copy link

It was using basically the same script (for each device) without infinite loop. Then I used Node-red to call that script at the required intervals.

I have since reverted back to localtuya as there is a fix there now which sends the updateDPS at regular intervals.

I understood the correction would be the file (init.py?) I've already applied it here, but I'm still having a very long delay in updating the consumption,

@joe-sydney
Copy link

There are two files to be replaced/updated: common.py and init.py. See the following:

https://github.com/rospogrigio/localtuya/pull/549/files

@brunokelo
Copy link

There are two files to be replaced/updated: common.py and init.py. See the following:

https://github.com/rospogrigio/localtuya/pull/549/files

I updated the 2 files, even so I'm having a delay of more than 15m to update the consumption :(

@brunokelo
Copy link

brunokelo commented Sep 25, 2021

image
exemple.

strange, when the smart life app opens the update is in real time.

@dualmacops
Copy link

The problem still persists, i haven't updated the frimware on most of my plugs for this reason.

@LukasMendez
Copy link

I also have the same issue still... Very annoying, as I just bought 8 Tuya Smart Plugs, but the refresh rate is so unreliable

@jonathh21
Copy link

I've been investigating this issue after trying to work out what 'add electrity' is.

I wanted to have a device turn on ( a hover in my workshop) when I use my tablesaw but found the updates were hopelessly slow.

I am also investigating an issue where by the trigger seems to be an order of magnitude out. By maybe 100?

40w device triggers at 200w threshold. Homing in on the correct overreading by waiting to see a light turn on and off a new times.

I am new to this all and don't really know how to debug or hit the APIs.

@jorgnyg
Copy link

jorgnyg commented Jan 7, 2023

With Local Tuya you can set the scan interval manually. No need to open smart life app to get readings.
image

@gquach
Copy link

gquach commented Jun 10, 2023

Just making a note here that I'm experiencing the same issue with the Arlec Grid Connect smart plug. Reloading the Tuya integration manually fixes it temporarily, but then the energy consumption values remain frozen again after that...

@calibra69
Copy link

Hi everybody, still same problem with my Konyks plugs. any news?

@Shestoperd
Copy link

Same problem with the Smart Plug +. Scan Interval is set to 20 seconds, but this does not affect the update frequency in any way.

@TanYauRei
Copy link

Hi there, got the same problem and also tried the workaround with the localtuya integration, to no avail. What did end up working for me was the tuya local custom integration! Might worth a try!

@vigneshwaran0492
Copy link

@TanYauRei Thanks for the suggestion! I had the same issue where the power updates were very slow with my tuya plug and the localtuya didn't solve the issue for me. Switched to the tuya-local custom integration and the issue got resolved and now my power values get updated every 30 seconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests