jasonacox/tuyapower

Tuya API change / Missing Power Data

Closed this issue · 3 comments

Hi,

Thanks for this excellent package!

I am running into [Missing Power Data] messages when polling devices. I suspect the issue might be related to something incorrect in the Tuya API access that I've set up.

The Tuya IoT platform seems to have been updated since the guide in the ReadMe. I can't seem to find the Smart Home Devices Management, Authorization and Smart Home Family Management APIs listed in the guide.

I guessed at some APIs, here are the ones I've currently enabled:
image
Are these correct?

Here's the current response from a quick scan of the 4 devices I've set up. The state is updated as the switches are turned on and off, but the power data is absent.

# Scan the network and unpack the response 
devices = tuyapower.deviceScan()
for ip in devices:
       id = devices[ip]['gwId']
       key = devices[ip]['productKey']
       vers = devices[ip]['version']
       (on, w, mA, V, err) = tuyapower.deviceInfo(id, ip, key, vers)
       print("Device at %s: ID %s, state=%s, W=%s, mA=%s, V=%s [%s]"%(ip,id,on,w,mA,V,err))
Device at 192.168.50.153: ID ebce49cc8507c3997bm3or, state=False, W=0, mA=0, V=0 [Missing Power Data]
Device at 192.168.50.215: ID ebe62208944b1effd8x6xa, state=False, W=0, mA=0, V=0 [Missing Power Data]
Device at 192.168.50.217: ID eb4aa77b450e9560bboule, state=False, W=0, mA=0, V=0 [Missing Power Data]
Device at 192.168.50.151: ID ebac2a160afe1f8ba5bruz, state=False, W=0, mA=0, V=0 [Missing Power Data]

Also, I had to sign up as a free trial for most of the APIs. This is just for hobby use, does anyone have any idea what the current pricing model is for this API?

Here is more output using the debugging mode:

import tinytuya

tinytuya.set_debug(True, False) # Turn on Debug - for non-ANSI color use tinytuya.set_debug(True, False)

PLUGID = 'eb4aa77b450e9560bboule'
PLUGIP = '192.168.50.217'
PLUGKEY = "DEVICE_KEY" #modified to placeholder
PLUGVERS = "3.3"

tuyapower.devicePrint(PLUGID,PLUGIP,PLUGKEY,PLUGVERS)
DEBUG:status() entry (dev_type is default)
DEBUG:final payload_dict for 'eb4aa77b450e9560bboule' ('v3.3'/'default'): {1: {'command': {'gwId': '', 'devId': '', 'uid': '', 't': ''}}, 7: {'command': {'devId': '', 'uid': '', 't': ''}}, 8: {'command': {'gwId': '', 'devId': ''}}, 9: {'command': {'gwId': '', 'devId': ''}}, 10: {'command': {'gwId': '', 'devId': '', 'uid': '', 't': ''}}, 13: {'command': {'devId': '', 'uid': '', 't': ''}}, 16: {'command': {'devId': '', 'uid': '', 't': ''}}, 18: {'command': {'dpId': [18, 19, 20]}}, 64: {'command': {'reqType': '', 'data': {}}}}
DEBUG:building command 10 payload=b'{"gwId":"eb4aa77b450e9560bboule","devId":"eb4aa77b450e9560bboule","uid":"eb4aa77b450e9560bboule","t":"1694820323"}'
DEBUG:sending payload
DEBUG:payload encrypted=b'000055aa000000010000000a00000088f15a57953868140b85fbef98f228c2a0da228ec7bb661bcf439d78322147ae22a5a3cf6f4b98b4c2a4cc6190b25785f0ff3e34366749ff6f057538a4bba0f8c34e0edfc034cbdd21485d41e0c527a75eda228ec7bb661bcf439d78322147ae22f7e2f379f646cf7dd374b891a0b35c5a695b312354954e03e047fec145d87cb2ca4af9ed0000aa55'
DEBUG:received data=b'000055aa000000010000000a0000006c000000008bc2e640d20d2e5ec63177fd39bb559e262a82d747773d4b6ab823898b48c46295e2ade5b7144502e506eaeba5c510a2038e68872277364c2eccd190c026311f55d2b8affefa538ba92970dc6a80132c46715e522c6f2f866b7f3aef59aaf6379386af730000aa55'
DEBUG:received message=TuyaMessage(seqno=1, cmd=10, retcode=0, payload=b'\x8b\xc2\xe6@\xd2\r.^\xc61w\xfd9\xbbU\x9e&*\x82\xd7Gw=Kj\xb8#\x89\x8bH\xc4b\x95\xe2\xad\xe5\xb7\x14E\x02\xe5\x06\xea\xeb\xa5\xc5\x10\xa2\x03\x8eh\x87"w6L.\xcc\xd1\x90\xc0&1\x1fU\xd2\xb8\xaf\xfe\xfaS\x8b\xa9)p\xdcj\x80\x13,Fq^R,o/\x86k\x7f:\xefY\xaa\xf67', crc=2475077491, crc_good=True, prefix=21930, iv=None)
DEBUG:raw unpacked message = TuyaMessage(seqno=1, cmd=10, retcode=0, payload=b'\x8b\xc2\xe6@\xd2\r.^\xc61w\xfd9\xbbU\x9e&*\x82\xd7Gw=Kj\xb8#\x89\x8bH\xc4b\x95\xe2\xad\xe5\xb7\x14E\x02\xe5\x06\xea\xeb\xa5\xc5\x10\xa2\x03\x8eh\x87"w6L.\xcc\xd1\x90\xc0&1\x1fU\xd2\xb8\xaf\xfe\xfaS\x8b\xa9)p\xdcj\x80\x13,Fq^R,o/\x86k\x7f:\xefY\xaa\xf67', crc=2475077491, crc_good=True, prefix=21930, iv=None)
DEBUG:decode payload=b'\x8b\xc2\xe6@\xd2\r.^\xc61w\xfd9\xbbU\x9e&*\x82\xd7Gw=Kj\xb8#\x89\x8bH\xc4b\x95\xe2\xad\xe5\xb7\x14E\x02\xe5\x06\xea\xeb\xa5\xc5\x10\xa2\x03\x8eh\x87"w6L.\xcc\xd1\x90\xc0&1\x1fU\xd2\xb8\xaf\xfe\xfaS\x8b\xa9)p\xdcj\x80\x13,Fq^R,o/\x86k\x7f:\xefY\xaa\xf67'
DEBUG:decrypting=b'\x8b\xc2\xe6@\xd2\r.^\xc61w\xfd9\xbbU\x9e&*\x82\xd7Gw=Kj\xb8#\x89\x8bH\xc4b\x95\xe2\xad\xe5\xb7\x14E\x02\xe5\x06\xea\xeb\xa5\xc5\x10\xa2\x03\x8eh\x87"w6L.\xcc\xd1\x90\xc0&1\x1fU\xd2\xb8\xaf\xfe\xfaS\x8b\xa9)p\xdcj\x80\x13,Fq^R,o/\x86k\x7f:\xefY\xaa\xf67'
DEBUG:decrypted 3.x payload='{"dps":{"1":true,"9":0,"38":"memory","39":"relay","40":false,"41":"","42":"","43":""}}'
DEBUG:payload type = <class 'str'>
DEBUG:decoded results='{"dps":{"1":true,"9":0,"38":"memory","39":"relay","40":false,"41":"","42":"","43":""}}'
DEBUG:status() received data={'dps': {'1': True, '9': 0, '38': 'memory', '39': 'relay', '40': False, '41': '', '42': '', '43': ''}}
INFO:{'datetime': '2023-09-15T23:25:23Z', 'switch': True, 'power': 0, 'current': 0, 'voltage': 0}
 ERROR: Power data unavailable

TuyaPower (Tuya Power Stats) [0.2.0] tinytuya [1.12.11]

Device eb4aa77b450e9560bboule at 192.168.50.217 key DEVICE_KEY protocol 3.3:
    Switch On: True
    NOTE: Power data unavailable

Are you sure this Tuya device (switch) has power measurement? You are getting a valid response that decodes to:

{'1': True, '9': 0, '38': 'memory', '39': 'relay', '40': False, '41': '', '42': '', '43': ''}}

But it is missing any power data points (e.g. 18, 19, or 20) - you can see the index here: https://github.com/jasonacox/tinytuya#version-33---plug-switch-power-strip-type

Are you seeing Current, Voltage and Wattage values in the SmartLife app?

Aiyiyi that would explain it, wouldn't it! Thanks for your feedback!

Sorry for not catching that earlier. For anyone else searching, I was using these plugs (which do not have any power measurement capabilities).

I'm still curious how the changes to the Tuya IoT platform impact the guide listed in the readme, but my hunch is that the default APIs work. (Also still curious if the Tuya API pricing model has changed). But I need to buy proper plugs to investigate!