Alternative Tuya smart outlet setup

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:

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    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 &quot;devId&quot tag. Sample xml snippet:

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
    <string name="tuya_data">{&quot;deviceRespBeen&quot;:[{&quot;activeTime&quot;:1524955128,&quot;devId&quot;:&quot;03210171cd4d22c3aa52&quot;
,&quot;verSw&quot;:&quot;2.0.0&quot;}},&quot;name&quot;:&quot;Couch Lamp&quot;

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:

  - platform: tuya
    name: Couch Lamp
    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

If you haven’t already, make sure to copy to your custom_components/switch folder so that Home Assistant can figure out what it do. Restart Home Assistant, your device should pop up!


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.



Worked like a champ.

The only issue for me was in step 3 with adb, I had to use .\adb devices, as power shell was giving the following error.

PS C:\Users\Owner\Desktop\platform-tools> adb devices -1
adb : The term 'adb' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ adb devices -1
+ ~~~
    + CategoryInfo          : ObjectNotFound: (adb:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Once I changed to .\adb devices, the connection was established and I was able to extract the file as described, no issues.

Still hoping we would be able to get the usage data from the outlets soon.

Are you getting “ConnectionError: Failed to update status.”, I’m getting numerous for each outlet, and control is lost until reboot.

Pretty sure update status is just a symptom, you probably have a “Connection reset by peer” error earlier on. I’m having an issue with the connection being reset, and whenever that happens it seems to drop the ability to use the switches, as documented here and here. It seems to be a known issue, with the only workaround that I seem to be even close to understanding is this

Darkyputz commented on Mar 14
Same experience here…
But i isolated my plug in my network so that it does not talk to the chineasien servers or phones anymore
Only my router is checking for my needs and is talking to it from now on…turning it off and on when my script says so
Great enhancement to my life…thx so much

Seems like this has something to do with either the switches connecting to the Tuya server or vice versa. They’ve proposed just deleting the app from your phone when you’re done setting it up - I’ve not confirmed that this will improve things.

Would definitely be interested in other solutions to this problem, or an example of what Darkyputz, i.e. isolating devices from accessing a Chinese server. It seems whatever the problem is, it is likely with the code, not with home-assistant or the setup as far as I can tell.

Doesn’t work, still getting errors, I will have to try isolating/blocking the outlets.

Thank You!

It works fine for me also with an 3x230V+USB outlet.

I received the power shell error in Win10 too, but I have used cmd with administrator rights, and so it was no problem.

Thank you! This worked for me with estink power strip… only detail is that I can’t control the USB plugs but I’m able to control the switches… Thank you so much for this!

Did you managed to control the usb? Can you share your yaml code please?

This is brilliant thanks!

I couldn’t get the lights to turn on/off until I turned off the WiFi on my phone. With it off, it took about a minute before they started working. Whatever connection the app has to the server, it must take a minute to timeout once disconnected.
But, they work!
So, once again, thanks!

I have Jinvoo installed on my phone so I tried with installing Jinvoo on Genymotion so I think above should change. But, I can’t even find the installation folder in the root. Data folder inside root seems to be empty when inspected through Amaze. Where on root could these files be located? Any help is appreciated!
Thank you,

OK. Figured that out. No need of all this. Just follow this

Thanks for the guide, managed to extract the device id’s and local keys for 14 switches.

I didn’t have a file speciifically named ‘dev_data_storage.xml’, to extract the devid 's and localkey’s.
The xml file containing this information was in the same directory (shared_prefs) the xml file name started with ‘preferences_global’.

I’m assuming it should be, but is this significantly quicker or better than the current default tuya integration?

I’ve got about 9 light switches - everything works fine - I can use the app, google home, hass and (ick) fingers, to change. Only real issue is:

2018-12-07 15:13:27 WARNING (MainThread) [homeassistant.components.switch] Updating tuya switch took longer than the scheduled update interval 0:00:30
2018-12-07 15:47:00 WARNING (MainThread) [homeassistant.components.switch] Updating tuya switch took longer than the scheduled update interval 0:00:30
2018-12-07 15:48:02 WARNING (MainThread) [homeassistant.components.switch] Updating tuya switch took longer than the scheduled update interval 0:00:30
2018-12-07 15:49:04 WARNING (MainThread) [homeassistant.components.switch] Updating tuya switch took longer than the scheduled update interval 0:00:30
2018-12-07 15:50:05 WARNING (MainThread) [homeassistant.components.switch] Updating tuya switch took longer than the scheduled update interval 0:00:30

Some of which may be my congested 2.4ghz wifi. Or might be the volume of connections going to the tuya server(s) meaning they need to throw some hardware at it, given this seems to be the OEM smart system of choice…

1 Like

Is this in the “adb” directory? I can’t seem to find this anywhere.

It was in the “shared_prefs” folder. The xml file began with ‘preferences_global’ the complete file name had a string of numbers after it.
The file structure was the same as indicated in the OP.

Should it be located here:
PS C:\adb\platform-tools_r28.0.1-windows>
Am I in the right directory?

I think your looking on your PC, it’s found on the Android device
Did you install the smartlife app on your emulator or android device?
The directory your looking for is found on the android device or emulator after you have installed the smartlife app and signed into your app. You should be able to navigate to the folder on the android dev/emulator. ( if you followed step as described in step 1 or 2).
Then you need to work out the exact path of the xml file, thats contains the local keys and dev ids, on your android device/emulator.
Once you have found the correct file and path,then you can copy the file to your PC using adb in powershell (from your PC, as described in step 3).

How did you overcome the ARM build issue?

An error occured while deploying the file.
This probably means that the app contains ARM native code and your Genymotion

Figured this out. Had to install the arm translation (just dropped the zip on top of the running emulator to flash).

Also, I have my devices added through the Tuya Smart app, not Smart Life. Tuya Smart has nearly the same file location, mine being ./data/data/ and my file was named preferences_global_keySEEMINGLY_RANDOM_STRING.xml. I wrote a little bash thing to parse the file and give me my outputs. The command string below requires the jq command.

cat YOUR_XML_FILE.xml | sed -e 's/&quot;/"/g' | sed -e 's/.*home_data.*">{"/{"/g' -e 's/<\/string>.*//g' | grep -v "<" | jq '.deviceRespBeen[] | .name + " -- key: " + .localKey + " -- id: " + .key'

If successful, you should get an output like:

"Desk Lamp -- key: OBFUSCATED -- id: OBFUSCATED"
"Guest Lamp -- key: OBFUSCATED -- id: OBFUSCATED"
"Master Lamp -- key: OBFUSCATED -- id: OBFUSCATED"
"Master Lamp 2 -- key: OBFUSCATED -- id: OBFUSCATED"

you can then put the key and id as provided in your switches config.

1 Like

I had the ARM issue as well and found this article fixed it: