Tuya Switches w/ Power Usage Data (No TuyaConvert Needed)

Have you got this solved???

Hi Phillip,

I have been working days on days to try to solve this, it is an en/decoding problem.

I tried this: https://github.com/TradeFace/python-tuya, which is an addition to PYTUYA, it works with the decoding in the sens that it correctly decode and encode the first part of the messages, the message sent, but my challenge is the Python programming, I am a skilled programmer, but Python is so different from all other lanquages I have programmed in, so I have not yet succeded to integrate his solution into your program.

He also explaines why some en/decoding do not work.

Hope this can help you, as I expect that TUYA is changing their en/decoding in new devices.

Not yet ā€¦ havenā€™t looked further. If someone has any news let us know!

Please can we keep this to one place, as itā€™s impossible to keep track of your comments when they are bouncing between here and the Github issue tracker. Thanks.

I just pushed version 1.1.2 to PyPi. This fixes an issue with some device using different dps keys.

This may solve some of the recent issue discussed in this thread.

Let me know how you get on with it.

Big thanks to @WeldFire for his input / pr!

1 Like

Just wanted to say big thanks for this latest version. Iā€™ve been following along and Iā€™ve been having the same issues as WeldFire. I upgraded just now, and Iā€™m seeing the power stuff. Big thanks to both of you. Good stuff!

2 Likes

Youā€™re welcome. I created the early versions based on my experience with my own device. @WeldFire came along and worked out that a lot of devices used the same dps keys as the devices on the old API. Until more people jump in and start adding fixes or making suggestions there is not much I can do to improve things. There are so many Tuya devices that itā€™s impossible for 1 person to make a script that covers them all.

Iā€™m glad the new version was what you needed to get your devices up & running!

@dferrandizmont @perr have you tried the latest version yet (see above) ?

Hey Phill! Thanks for the new version. Already tried but seems that doesnā€™t works at all ā€¦

{"result": "Incomplete response from plugbfb50067e2c0b15c28udin [192.168.1.158].", "deviceid": "bfb50067e2c0b15c28udin", "datetime": "2020-02-01T21:35:25Z"}

from the logs:

INFO:pytuya:pytuya version 7.0.5
INFO:pytuya:Python 2.7.16 (default, Oct 10 2019, 22:02:15)
[GCC 8.3.0] on linux2
INFO:pytuya:Using PyCrypto (3, 9, '4')
INFO:pytuya:Using PyCrypto from '/home/pi/.local/lib/python2.7/site-packages/Crypto/__init__.pyc'
DEBUG:pytuya:status() entry
DEBUG:pytuya:json_payload='{"devId":"bfb50067e2c0b15c28udin","gwId":"bfb50067e2c0b15c28udin"}'
DEBUG:pytuya:status received data="\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00,\x00\x00\x00\x01d\x8f\xf6\xc4\xbf\xf1\xb3\xe3\xa0\xaa\xc3Y\xcb\xaeC\x84\xbe\xec\xf6\x9d\x13\x17\xf0P{\x19\xd5\xc7\xa6\xdbO>a'\x01\x1d\x00\x00\xaaU"
DEBUG:pytuya:result='d\x8f\xf6\xc4\xbf\xf1\xb3\xe3\xa0\xaa\xc3Y\xcb\xaeC\x84\xbe\xec\xf6\x9d\x13\x17\xf0P{\x19\xd5\xc7\xa6\xdbO>'
DEBUG:pytuya:decrypted result=u'json obj data unvalid'
DEBUG:pytuya:status() entry
DEBUG:pytuya:json_payload='{"devId":"bfb50067e2c0b15c28udin","gwId":"bfb50067e2c0b15c28udin"}'
DEBUG:pytuya:status received data="\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00,\x00\x00\x00\x01d\x8f\xf6\xc4\xbf\xf1\xb3\xe3\xa0\xaa\xc3Y\xcb\xaeC\x84\xbe\xec\xf6\x9d\x13\x17\xf0P{\x19\xd5\xc7\xa6\xdbO>a'\x01\x1d\x00\x00\xaaU"
DEBUG:pytuya:result='d\x8f\xf6\xc4\xbf\xf1\xb3\xe3\xa0\xaa\xc3Y\xcb\xaeC\x84\xbe\xec\xf6\x9d\x13\x17\xf0P{\x19\xd5\xc7\xa6\xdbO>'
DEBUG:pytuya:decrypted result=u'json obj data unvalid'
DEBUG:pytuya:status() entry
DEBUG:pytuya:json_payload='{"devId":"bfb50067e2c0b15c28udin","gwId":"bfb50067e2c0b15c28udin"}'
DEBUG:pytuya:status received data="\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00,\x00\x00\x00\x01d\x8f\xf6\xc4\xbf\xf1\xb3\xe3\xa0\xaa\xc3Y\xcb\xaeC\x84\xbe\xec\xf6\x9d\x13\x17\xf0P{\x19\xd5\xc7\xa6\xdbO>a'\x01\x1d\x00\x00\xaaU"
DEBUG:pytuya:result='d\x8f\xf6\xc4\xbf\xf1\xb3\xe3\xa0\xaa\xc3Y\xcb\xaeC\x84\xbe\xec\xf6\x9d\x13\x17\xf0P{\x19\xd5\xc7\xa6\xdbO>'
DEBUG:pytuya:decrypted result=u'json obj data unvalid'
DEBUG:pytuya:status() entry
DEBUG:pytuya:json_payload='{"devId":"bfb50067e2c0b15c28udin","gwId":"bfb50067e2c0b15c28udin"}'
DEBUG:pytuya:status received data="\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00,\x00\x00\x00\x01d\x8f\xf6\xc4\xbf\xf1\xb3\xe3\xa0\xaa\xc3Y\xcb\xaeC\x84\xbe\xec\xf6\x9d\x13\x17\xf0P{\x19\xd5\xc7\xa6\xdbO>a'\x01\x1d\x00\x00\xaaU"
DEBUG:pytuya:result='d\x8f\xf6\xc4\xbf\xf1\xb3\xe3\xa0\xaa\xc3Y\xcb\xaeC\x84\xbe\xec\xf6\x9d\x13\x17\xf0P{\x19\xd5\xc7\xa6\xdbO>'
DEBUG:pytuya:decrypted result=u'json obj data unvalid'
DEBUG:pytuya:status() entry
DEBUG:pytuya:json_payload='{"devId":"bfb50067e2c0b15c28udin","gwId":"bfb50067e2c0b15c28udin"}'
DEBUG:pytuya:status received data="\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00,\x00\x00\x00\x01d\x8f\xf6\xc4\xbf\xf1\xb3\xe3\xa0\xaa\xc3Y\xcb\xaeC\x84\xbe\xec\xf6\x9d\x13\x17\xf0P{\x19\xd5\xc7\xa6\xdbO>a'\x01\x1d\x00\x00\xaaU"
DEBUG:pytuya:result='d\x8f\xf6\xc4\xbf\xf1\xb3\xe3\xa0\xaa\xc3Y\xcb\xaeC\x84\xbe\xec\xf6\x9d\x13\x17\xf0P{\x19\xd5\xc7\xa6\xdbO>'
DEBUG:pytuya:decrypted result=u'json obj data unvalid'
DEBUG:pytuya:status() entry
DEBUG:pytuya:json_payload='{"devId":"bfb50067e2c0b15c28udin","gwId":"bfb50067e2c0b15c28udin"}'
DEBUG:pytuya:status received data="\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00,\x00\x00\x00\x01d\x8f\xf6\xc4\xbf\xf1\xb3\xe3\xa0\xaa\xc3Y\xcb\xaeC\x84\xbe\xec\xf6\x9d\x13\x17\xf0P{\x19\xd5\xc7\xa6\xdbO>a'\x01\x1d\x00\x00\xaaU"
DEBUG:pytuya:result='d\x8f\xf6\xc4\xbf\xf1\xb3\xe3\xa0\xaa\xc3Y\xcb\xaeC\x84\xbe\xec\xf6\x9d\x13\x17\xf0P{\x19\xd5\xc7\xa6\xdbO>'
DEBUG:pytuya:decrypted result=u'json obj data unvalid'

Thank you so much for your effort

Just FYI, I was getting that same response before I realized I had the wrong IP for the device.

Thanks for pointing this, tried with all the IP and had the same response:

{"result": "Incomplete response from plugbfb50067e2c0b15c28udin [192.168.1.157].", "deviceid": "bfb50067e2c0b15c28udin", "datetime": "2020-02-01T22:24:59Z"}
{"result": "Incomplete response from plugbfb50067e2c0b15c28udin [192.168.1.158].", "deviceid": "bfb50067e2c0b15c28udin", "datetime": "2020-02-01T22:25:15Z"}
{"result": "Incomplete response from plugbfb50067e2c0b15c28udin [192.168.1.166].", "deviceid": "bfb50067e2c0b15c28udin", "datetime": "2020-02-01T22:25:33Z"}
{"result": "Incomplete response from plugbfb50067e2c0b15c28udin [192.168.1.167].", "deviceid": "bfb50067e2c0b15c28udin", "datetime": "2020-02-01T22:25:55Z"}
{"result": "Incomplete response from plugbfb50067e2c0b15c28udin [192.168.1.168].", "deviceid": "bfb50067e2c0b15c28udin", "datetime": "2020-02-01T22:26:13Z"}
{"result": "Incomplete response from plugbfb50067e2c0b15c28udin [192.168.1.173].", "deviceid": "bfb50067e2c0b15c28udin", "datetime": "2020-02-01T22:26:29Z"}
{"result": "Incomplete response from plugbfb50067e2c0b15c28udin [192.168.1.174].", "deviceid": "bfb50067e2c0b15c28udin", "datetime": "2020-02-01T22:26:45Z"}
{"result": "Incomplete response from plugbfb50067e2c0b15c28udin [192.168.1.192].", "deviceid": "bfb50067e2c0b15c28udin", "datetime": "2020-02-01T22:27:13Z"}

Are you obfuscating the id? The last 4 characters look odd to me. Also, both my device idā€™s contain 20 characters instead of 22.

Mmm ā€¦ this is what I get from the Smart Life app:

Why does this show a different IP for each row? Incorrect &/or failed attempts to connect to a device will result in it just blocking connections then send out seemingly random data.

Phill,

I did a try, but I am afraid my testenvironment needed to be reset.

I did however get the new message about the devise info not found.

I will go deeper into this next week, and let you know.

Each row has a different IP because I tried the getstats.py with all those IPs just in case iā€™m pointing the wrong IP.

Tested with:

python getstats.py "bfb50067e2c0b15c28udin" "192.168.1.157" "417ad98dbcbb4fa6" "3.3"

and

python getstats.py "bfb50067e2c0b15c28udin" "192.168.1.157" "417ad98dbcbb4fa6" "3.1"

for each of those IPs.

Anyway, as @kklicker said, my device ID is 22 characters long, itā€™s wrong?

Thank you so much.

Ok, Please post an issue over on Github and Iā€™ll see if we can somehow work it out.

Done it :slight_smile:, thanks Phill!

1 Like

Hi Phill,

Iā€™m trying to check the connection under firmware 1.0.2 and It only returns this:

{ā€œdeviceidā€: ā€œ03268688807d3a7c9aabā€, ā€œdatetimeā€: ā€œ2020-02-02T19:04:38Zā€}

I donā€™t know how to get the local key but following your info it would not be needed anyway. Whatā€™s could be wrong?

Thank you.

Hi Phill

Did a complete clean of my environment, and reinstalled your packet (1.1.3)?

and both with protecol 3.1 and 3.3, i get this message from mosquitto:

pi@raspberrypi:~ $ mosquitto_sub -t ā€œdevices/tuya/plug/TestPlugā€ -u ā€œperā€ -P ā€œperā€
{ā€œdatetimeā€: ā€œ2020-02-03T09:41:45Zā€, ā€œdeviceidā€: ā€œTestPlugā€, ā€œresultā€: ā€œIncomplete response from plugTestPlug [192.168.1.139].ā€}

I have added it to the Github

Itā€™s always best to try with keys & the firmware version varies from device to device. You can get the device key using the instructions linked to in my first post. Once you have those you can try against both api versions.