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

This package, for all intents mimics the tuya app and asks the device for the relevant info in the same way. So if you can’t use the app, then you can’t use this unfortunately.

To be honest it’s hard to keep track of all the info you are bouncing around. Also, the firmware version has very little to do with it since every device / device manufacturer is responsible for their own firmware numbering. So version 1.4.2 for one device can be greatly different from another device with the same number but made by a different manufacturer (or even a different device by the same manufacturer). The API version is the most important thing. If you are sure that you have API v3.3 then something else is the reason for the issues.

Regardless, since this library leverages other python libraries, and you are convinced that you have the correct credentials for your devices, I recommend posting an issue on one of the upstream repos.

Glad to hear you are making progress. If you resolve the issue, please report back here or make a pull request on the repo. The more people/devices we can open this up to, the better.

Got it working - the socket disconnects were nothing, the device was still communicating with the MQTT server.

Thanks so much for this - have the dishwasher, dryer and washing machine up and running with some cheap plugs, so awesome!! Very grateful for this.

1 Like

Excellent. I’m glad it helped and you got it sorted.

Hey @Phill_Healey first of all thanks for your work!

I’ve able to retrieve the device id and device key, but whatever API ver I use I can’t get the stats of the switches, I’ve enabled the loggin and this are the results:

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\x01\x98_K\xc1\xc3\x9e\x97M\x0f\x80\xa0\xb3_\xbf\xf1M\x0bJ/h\x9a$\xdeN\x9a\x92\x07i\x97\xd5Q_\xda\xfb\xc6x\x00\x00\xaaU'
DEBUG:pytuya:result='\x98_K\xc1\xc3\x9e\x97M\x0f\x80\xa0\xb3_\xbf\xf1M\x0bJ/h\x9a$\xdeN\x9a\x92\x07i\x97\xd5Q_'
ERROR:pytuya:Unexpected status() payload='\x98_K\xc1\xc3\x9e\x97M\x0f\x80\xa0\xb3_\xbf\xf1M\x0bJ/h\x9a$\xdeN\x9a\x92\x07i\x97\xd5Q_'
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\x01\x98_K\xc1\xc3\x9e\x97M\x0f\x80\xa0\xb3_\xbf\xf1M\x0bJ/h\x9a$\xdeN\x9a\x92\x07i\x97\xd5Q_\xda\xfb\xc6x\x00\x00\xaaU'
DEBUG:pytuya:result='\x98_K\xc1\xc3\x9e\x97M\x0f\x80\xa0\xb3_\xbf\xf1M\x0bJ/h\x9a$\xdeN\x9a\x92\x07i\x97\xd5Q_'
ERROR:pytuya:Unexpected status() payload='\x98_K\xc1\xc3\x9e\x97M\x0f\x80\xa0\xb3_\xbf\xf1M\x0bJ/h\x9a$\xdeN\x9a\x92\x07i\x97\xd5Q_'

Those seems like encrypted data like the @perr

Any way to decrypt it? Thanks!

Hi, yes same problem, it seems like crypto do not get the local key, I have raised it to the crypto people, and I am currently looking into it my self. Nice to see I am not having this problem alone. It is not Phill’s vide that is wrong, the error is in the crypto modules.

Thanks for looking into it! If you have any news post it :slight_smile:

It looks like there may be another api version that some devices are using. I’ll look into in some of the upstream packages and see if there is any updates / work going on.

Are you able to get stats via the Tuya app? Not all devices offer power data.

Yeah, i can see the power consumption and if its On / Off:

Thanks for the reply! :wink:

Ok, I just wanted to eliminate that.

Ask if you need me to do something, anything I can do I’ll try to do it. :+1:

Unfortunately, I’m not really able to dig into this for at least a couple of weeks. Sadly Pytuya does appear to be abandoned, but I will see what I can do when time permits.

It just occurred to me that wildfire had a decoding issue and did a pull request to my gut repo for Tuyapower2MQTT, but I don’t think I released this on Pypi. As soon as I have time I’ll push the release to Pypi and then you can give it a try. The chances are small but, it might move you a step closer to resolving your issue.

Having said that I’m still unclear as to how you got those DPS value that you posted in ascreenshot further up in this thread. Those DPS values are literally the unencoded info that we are trying to get.

Just out of curiosity which version of the mobile app did you use to get the LocalKey? Because version used by me wasn’t producing any “&quote” (it’s mentioned several times, i know, but haven’t seen in a single time)

EDIT: Aaaaah sorry, notepad, now i get it. :laughing: But i would try to use another version just to make sure you are really getting the right localKey.
BTW: “bf20d8688f946386bd7rjo” is intentionally edited to not show the actual MAC address?

If so then try to use anything from 3.x.x and above. The older ones are not supported anymore (according to pop-up when i installed it…)
The reason why i’m asking about the ID is that all of my IDs ends by MAC address of the device and “rjo” definitely is impossible to have as a MAC. :nerd_face:

I know that you need the app to cache the LocalKey (i used the same method and succesfully have four plugs up and running) i was just worried if unsupported apps don’t use a different way to generate the LocalKey (you can get the preference file via early subversions of 3.x.x as well) and therefore you got what you’re getting.
And the DevID which is significantly different from mine picked up my eyes too.

Anyway if you confirmed the numbers are same across different methods and versions of the app then don’t mind me and good luck.

I fear this is starting to dominate this thread and making it a little bloated. Perhaps it’d be best if you now moved this over to the repo and open an issue there.

1 Like

Googled the Internet, after trying to reflash without success, this is the reason for it not working:

barbudor says:

December 16, 2019 at 8:26 pm

I just cut-open my unbranded “Tuya” from Ali Express and as expected the Wifi module is not ESP based. It seems to be a W600 TW-02 module from “Shenzhen ThingsTurn Technology Co Ltd”. A smaller version of the W600 available at SeedStudio/electrodragin/AliExpress. It runs a Cortex M3. More details at https://fccid.io/2ASQV-TW-02/User-Manual/User-manual-4211029. It looks like a lot of details can be found on the Internet, not all in English.

Photos of the disassembled module available here : https://drive.google.com/drive/folders/1GsxYAnR-Bz19K19MqNGq2SbZPhw9URzn?usp=sharing

The IP id in my router are ThingsTurnxx, so this is the explanation for it not working.

That really shouldn’t matter. The library interacts with the device api and essentially mimics the Tuya app. It doesn’t talk directly to the device components.