jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
867 stars 157 forks source link

Old data from ZigBee device received #486

Closed S-19910 closed 2 months ago

S-19910 commented 2 months ago

Hello,

I have two Energy Metering Devices via ZigBee. I do get all the values through TinyTuya local, however, there is quite a big time delay. I mean the data I receive via TinyTuna are the (correct) values from +/- 1 minute old.

If I use the TuyaApp, the values are (within +/- 1 second) Realtime. But via TinyTuna not. Eg. I switch on a heater with 1,25kW : APP kW will increase by 1.25 almost immediately. TinyTuna will keep sending (changing) data, but only after +/- 1 minute the kW-value will increase by 1,25. Same of course when switching off.

Any suggestions? Help appreciated.

jasonacox commented 2 months ago

Hi @S-19910 - two suggestions:

import tinytuya
import time

d = tinytuya.OutletDevice(DEVICEID, DEVICEIP, DEVICEKEY)
d.set_version(3.1)

data = d.status()
print(data)

print(" > Wait 5 sec < ")
time.sleep(5)

print(" > Request Update < ")
result = d.updatedps()
# some require params that you wish updated
#result = d.updatedps(['18','19','20'])
print(result)

print(" > Fetch Status Again < ")
data2 = d.status()
print(data2)

print("")
print("Before %r" % data)
print("After  %r" % data2)
S-19910 commented 2 months ago

Hi,

thanks for the swift reply. I tried both suggestions.

updatedps() did not bring anything. However : the async read did the trick. Now I get the (near) real time values.

Thanks a million.

uzlonewolf commented 2 months ago

Since you got it working I'm going to go ahead and close this. Feel free to re-open if needed.