Continuing the discussion from Add Support for Smart Life Components:
Okay so after struggling with this for a couple days, I thought I’d post as in depth a success story on a Tuya / Smart Life / Jinvoo electrical outlet as I can manage, starting from the beginning. This is all in hopes that this information is useful to someone else.
Tools: Genymotion, adb, Smart Life app (note that this will work for all Jinvoo, Tuya, and similar devices), a computer, a mobile device
Step 1: Installing Genymotion on the computer
After mucking about in proxies, Charles, and packet sniffing, I was frustrated with the state of this information. After all, all I want is access to an xml file that I would be able to use if it weren’t for lack of root privileges on my phone. Then I realized, all Genymotion emulated phones are rooted, and I already had one of those! So, for those of you that don’t, download Genymotion (it’s free for personal use). When Genymotion is installed and running, click “Add +” and create a new device. Settings aren’t going to be too important here, I set up a Galaxy S7 with 6.0.0 API 23, since this is the same as my phone. Once the device is configured, (again default settings will do) go ahead and start it up!
Step 2: Getting set up with SmartLife on the mobile device and Genymotion emulator
You’re going to want to download the Smart Life apk onto this device. To do that, download a local copy of the apk: https://apkpure.com/smart-life-smart-living/com.tuya.smartlife
With this downloaded, drag and drop the apk file over the top of the Genymotion Emulated phone. It should ask some questions and automatically install!
You’re going to want to download the Smart Life App on a mobile device as well, for the actual setup. It’s okay if your devices are already setup on Smart Life, because we’re not trying to sniff them, we’re just getting the already preconfigured file!
Add all devices (if they’re not already on Smart Life) to the app from your phone. The emulator won’t be able to set them up. Once they’re all set up in the Smart Life app on your phone, you should be able to login on the emulator and see all of your devices listed!
Step 3: Getting your configuration file
Okay, now I used adb here, and anyone familiar with rooting or android development probably already has that installed. If you don’t, there are different ways of installing it depending on OSX, Windows, etc. I’m going to leave that part of the instructions to better minds.
So I’ll just assume we’ve gotten adb installed on the computer of your choice. With your emulator running, go ahead and open the terminal and type
adb devices -l
this should give you an output listing your emulated device. Sample output
List of devices attached
192.168.56.102:5555 device product:vbox86p
model:Samsung_Galaxy_S7___6_0_0___API_23___1440x2560 device:vbox86p
The file you want is deep in the in the root directories, never worry, we can easily copy it to your desktop (I’m doing this on OSX, Linux and Windows users won’t have the “Users” folder, use pwd
to put it in your current directory):
$ adb pull ./data/data/com.tuya.smartlife/shared_prefs/dev_data_storage.xml /Users/<your_name>/Desktop
So now you should have a file on your Desktop called dev_data_storage.xml
Step 4: Smart Life data
Okay, now if you open up this file in Sublime or Atom or Notepad or however you roll, its gonna have a lot of unorganized data in it. You’ll be able to see the details for each device following the "devId"
tag. Sample xml snippet:
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<string name="tuya_data">{"deviceRespBeen":[{"activeTime":1524955128,"devId":"03210171cd4d22c3aa52"
,"dps":{"1":false,"2":0},"iconUrl":"https://images.tuyaus.com/smart/icon/152473664830iqy0c90et0vgl8xl82r9t3xr_0.jpg"
,"isShare":false,"key":"03210171cd4d22c3aa52"
,"lat":""
,"localKey":"aa8d3cf33ce62371"
,"lon":""
,"moduleMap":{"mcu":{"isOnline":true,"verSw":"2.0.0"},"wifi":{"bv":"5.24"
,"isOnline":true,"pv":"2.1"
,"verSw":"2.0.0"}},"name":"Couch Lamp"
,"productId":"kltFAtyjWBevLkvm"
,"resptime":1524955130149,"runtimeEnv":"prod"
,"timezoneId":"America/New_York"
,"uuid":"03210171cd4d22c3aa52"
,"virtual":false}],"groupBeen":[],"meshBeen":[],"productBeen":[]}</string>
</map>
I know this is rl ugly, but stay with me here. The two values we’re interested in are the localKey (mine’s aa8d3cf33ce62371
here) and the devId (mine’s 03210171cd4d22c3aa52
here). If you have multiple devices, you’ll have to collect each of them in this same manner from this xml. Remember the first item of each device is devId, so that should split them up for you.
Step 5: Configuration file updates
Alright guys, we’ve gotten all the hard stuff over with. We’re just gonna cruise over to the configuration.yaml
and add the following for our switch:
switch:
- platform: tuya
name: Couch Lamp
host: 192.168.0.124
local_key: aa8d3cf33ce62371
device_id: 03210171cd4d22c3aa52
id: 1
No quotes, nothing funny, just like that. Note that my IP address may not be the same as yours. I used the very precise method of listing all the devices on my router in order to find the right one, and then just unplugging things and pinging them to see what I had unplugged. I’m going to assume you can find the right IP (make sure you do, I was using the wrong one for a while and thought I had really messed up).
Step 6: Using tuya.py
If you haven’t already, make sure to copy tuya.py to your custom_components/switch folder so that Home Assistant can figure out what it do. Restart Home Assistant, your device should pop up!
Takeaways
Now, was any of that easier than sniffing packets or however everyone else got their local key and id? Probably not. But it worked for me, and if nothing else when I forget how I did this and need to set up more outlets, I’ll have written instructions.