[Proof of Concept] Tuya/SmartLife Switches - Local Integration

I've referenced this a few times in the past---it's a roundabout way to get SmartLife switches working locally (without flashing!)

The methodology to get this working is somewhat advanced. I can't promise to support it, but I'll do my best to help.


Pre-Requisites...

You'll need to use your packet capture app of choice. I use iOS, so I have to tether my phone, *RVICTL*, and WireShark.

If you're on Android, you should be able to use something like Packet Capture , zAnti , or cSploit .

Capturing packets...

  1. You'll need to be on the local wifi network of the switches.
  2. In the Tuya/SmartLife/Whatever app, open the device page of the switch you want to control.
  3. Turn it off, and on. Again, make sure you do this from the individual device page
  4. At this point, you can stop capturing packets, and start looking through them.
  5. You may want to export the data for viewing on a desktop.
  6. Sort the packets by those sent to your device's IP.

The packets you want to find will usually have a length of ~300-400 bytes, and will begin and end like this:

0x45, 0x00, 0x00, 0xeb, 0x00 .... 0x00, 0x00, 0xaa, 0x55

The packets will be pretty long, but not consistent in length.

Test which packets work for on/off by using Packet Sender on a desktop. Enable persistent TCP for this step, or the tests will likely fail.

After a while of testing, you should find a packet for on, and a packet for off.

After you've captured and found your packets...

Take those packets, remove all of the brackets, braces, etc., and create a hex stream. Split the hex stream into four equal parts: ![hex string - split up|690x153](upload://bORMcNZHR2YXpv58Fgqvr9UZYJM.png)

Then, install the driver:


After Installation

  1. Create a new virtual device
  2. Assign the Tuya/SmartLife driver
  3. Add your device's IP
  4. Add your eight (four for on, four for off) hex strings to the settings:

... then, hit save!

You can now turn your Tuya/Smartlife device on and off from Hubitat. This communication is one-way only, so buckle up!

4 Likes

Also, flashing your devices is probably easier and more reliable than this. I initially did this as a challenge with a friend of mine to see which of us could reverse engineer the protocol of a $5 WiFi plug first.

We both realized that the switches I purchased were Tuya based, and that's where I left off. I don't really want to do more work with it for now, but I would presume that you could use the same integration method from HASS (the Tuya python library) to get the keys/certs needed to transmit commands locally.

2 Likes

Does this also allow you to get local changes on the device in Hubitat when they occur or is it only updated after a timeout?

It never gets updated in Hubitat :slightly_frowning_face: One-direction only. (Well, unless you use IFTTT! Then I suppose you could sync bi-directionally with some simple logic)

I don't use your code, but I have bi-directional IFTTT control by setting up 4 recipes for each switch in IFTTT; one each for on/off triggered from Hubitat; one each for on/off triggered by SmartLife. This way the device gets sync'd. So using your code this would replace the 2 IFTTT recipes for HE triggered events and can just leave the other 2 to synchronise SmartLife triggered events back to HE. Cool. But as you say, flashing with Tasmota would be a better solution.

1 Like

Depends on how comfortable you are with packet sniffing :slight_smile:

Yeah. More comfortable with that than with flashing, that's for sure :sweat_smile:

2 Likes

Let me know if I can do anything to help you :slight_smile:

I read various articles and it's just so confusing. The hardware options. What to download. How to wire it up. How to execute the flash. I just know its going to be a whole world of trouble and I'll end up burning hours and hours and end up getting frustrated, swearing a lot, and then throwing it out the window much to my wife's annoyance lol. So right now I just use IFTTT on the various WiFi devices I have and tolerate the lag. May try your code here but its kinda only half a solution because the reverse sync is really still needed.

1 Like

I was thinking you could still use IFTTT for that part

Yes, would have to. Which means it's still reliant on the Cloud. Boo! :face_vomiting:

2 Likes

I know this is a very old thread, should this still work? I did a packet capture on my firewall to the IP of my Tuya switch, and all the traffic is TLS 1.2, so it is encrypted.

Thanks,
Rick

I’d try to send them ahead of time with packet sender, or some similar app. Should work, though!

I don't follow. Do I need to capture with an app on the phone that will grab the data before encryption?
How does tethering the phone fit into this. I'm iOS on my phone, but Windows 10 pc.

Right now I'm doing the exact same thing as @Angus_M in post#4.
Thanks

You’ll need to use a packet capture app on a Mac or PC. I’ll see if there’s a method for capturing it in Windows—I’ve always used Mac in my iOS development environment

Linux has wireshark.. I happen to have a couple linux boxes running

I finally managed to make some progress on Tuya devices for Hubitat. This is still work in progress, but with this device handler I am able to send encrypted messages directly to my tuya Wifi siren turning it on without any external tools, it is just the Hubitat hub that calculates the message.

What you need to to pair the tuya device with one of the standard tuya apps, and get hold of the IP, device ID, device key (I used the register at iot.tuya.com and the Linux tools to extract the device key), and control endpoint. Once you have this information you just add it to the device preferences in Hubitat.

I used a package sniffer with the original tuya app to find out which endpoint to use, the Wifi siren I have has endpoint 104. But for other switches I think I have seen endpoints around 0-4.

I am posting this half finished work for others to get started with tuya devices on Hubitat. My next step is to decode the incoming message for the device.

[EDIT] Moving my repos to github as the import function doesn't seem to work for gitlab:

3 Likes

I searched and couldn't find it elsewhere.

I know that HA now supports local Tuya integration. Any way to do that with Hubitat?

gave up on this when i realized i need a separate pi just to update the firmware so it would work locally in hubitat.

I think that you can now have local control without flashing a new firmware, I'm just not sure whether it can be done with HE. See here for HA: DON'T use the Tuya Integration - get your devices off the cloud with Local Tuya - YouTube