In Part I (HERE), we set up a Raspberry Pi so that we can host Tuya Convert, the process that allows us to flash a Smart Life or Tuya Smart switch OTA. In this entry, we’re going to select a compatible Wi-Fi plug, set up Tuya Convert on the Pi, and flash the plug. This is a REALLY easy project. If you follow the steps carefully, you won’t run into any major problems and then, after a couple of conversions, you’ll have it down.
First, you need to have a Smart Life or Tuya Smart Wi-Fi plug to flash. Not every plug will work – some of them never worked due to incompatibilities in their native firmware, while others once worked but a recent firmware update has made them incompatible. In part one, I liked to this plug:
I know it is compatible and it’s a pretty good deal at $10.99, so I’m using it to illustrate the process. You can find a list of compatible plugs here (though not every compatible plug is listed there – we have hundreds to choose from, after all):
https://blakadder.github.io/templates/plug.html
Assuming you have a viable plug on hand, you next connect to your Raspberry Pi via Putty, just like in Part I. In order to complete this, you’re going to need two mobile devices or one mobile device and a computer that connect to a Wi-Fi network – you’re going to need to connect to the Raspberry Pi’s access point with one device and connect to the plug (after flashing it) with your other device.
Next, go to the Tuya Convert Github Repository: https://github.com/ct-Open-Source/tuya-convert
Scroll down to the “PROCEDURE” section. Follow the instructions on screen copying the commands displayed to paste into the Pi. Remember, skip the # at the beginning of each line and the space following it. You don’t need to paste those into the Pi!
When you’ve select and copied the line of text from Github, right click the Putty screen to paste it. Press enter and follow the prompts on screen.
git clone https://github.com/ct-Open-Source/tuya-convert
cd tuya-convert
./install_prereq.sh
./start_flash.sh
The flash script is what you’ll run again in the future if you want to flash other devices – you won’t need to reinstall Tuya Convert.
After reading the warning, typing “yes” and pressing enter, you’ll need to connect a mobile device to the Pi’s AP, named “vtrust-flash” with the password “flashmeifyoucan”
Set your smart plug in AP mode now – usually holding the button for 5 seconds and releasing does the trick. Occasionally, you will either have to press the button again after holding it or else hold it for 10 seconds instead of 5.
Now press Enter on your screen and let the magic start! It can take a few moments for Tuya Convert to connect to some devices, while with others, it can be almost instant. I’ve basically trained myself to wait until I see at least two whole rows of dots before I start thinking that it won’t work (and event hen, don’t give up just yet, I’ve seen it kick in on 4 rows of dots). This week, I’ve attempted to flash 17 different Wi-Fi plugs from 5 manufacturers, covering 4 distinct models of plug. Some worked, some didn’t, and sometimes plugs from the same brand and model had different results.
I am not worried about the ones that didn’t flash. Either the firmware was newer or the flash process failed. I’m sure a new version of Tuya Convert will come out to handle firmware updates that break the process. And, for plugs that just failed, I can always open the enclosure and flash them manually – I’ll cover how to do that with a wire jig instead of soldering in an upcoming post!
Once the backup of firmware is complete, you’ll see a screen like this. Enter this command:
curl http://10.42.42.42/flash3?url=http://10.42.42.1/files/thirdparty.bin
And press enter in order to flash the plug to Tasmota. You can replace the bin file with your own firmware if you want. The process will still work (assuming the firmware is good).
Once the device is updated with the new firmware, it will restart and you’ll see a new AP available, with a name like sonoff-2302. Connect to the “sonoff” network and then browse to 192.168.4.1 – you should see a screen that looks like this:
You can either type in your network name or tap “Scan for wifi networks” to find the correct SSID. Enter the correct password. Free advice – set up a second SSID with no password – if you have a problem connecting to the 1st network, you can set up a router with the same name as the second SSID and no password to recover the device!
Tap Save. Your plug should restart and connect to your WiFi. Check your router to find the IP address and navigate there in a browser, like this:
Note – If you like to assign static IP addresses, this is a good time.
Many devices are already defined in the database (link below), but there are thousands of variations on the popular devices out there, so here is how you configure one on your own!
- Click the “Configuration button”
- Click “Configure Module”
- Select “Generic (18)” for module type and click SAVE
- Wait for the device to restart
- Click the “Configuration button”
- Click “Configure Module”
- Ignore GPIO 0 and GPIO 1. Set 8 of the remaining 9 GPIOs to Relay1 through Relay8 – don’t start with the i (inverted) relays – and click SAVE.
- When the device reboots, cycle through the 8 buttons at the top of the page to pinpoint which relay(s) are attached to which GPIO(s) as well as the LED.
Remember, if you click a button set to 1, changing it to 0, and the relay triggers or LED turns on, you’ll want to use the inverted (i) version of the LED/Relay/whatever when you do your final configuration. - Note each button number and what function is tied to it. In our case, the relay is button 5 and the LED is button 8 (inverted).
- Click the “Configuration button”
- Click “Configure Module”
- Set GPIO12 to Relay1 and set GPIO15 to LED1(i), with everything else changed back to None and then click SAVE.
- Click the “Toggle” button – the LED and the relay should work in sync.
- Click the “Configuration button”
- Click “Configure Module”
- Set the remaining GPIOs (besides 0 and 1) to Switches (there will be 7), then click Save
- When the device resets, click Console.
- Type Status 8 and press ENTER. Note the state (on or off) of each switch.
Press and hold the button on your plug and execute Status 8 again. Note which switch has changed state – in our case, switch 5. - Repeat that for each button on your device, then press Main Menu.
- Click the “Configuration button”
- Click “Configure Module”
- Change the switch that changed status (5, or GPIO13, for us) to Button 1.
- Change all other switches to None. Click save.
- When the device reboots, press the button – if the device was off, then the relay and LED should now be on – if the device was on, you may need to cycle off and then on to synchronize.
- Click the Console button, type Template 255, and press enter. Copy everything displayed between the two curly brackets (along with the brackets) and save it in a text editor/file/etc.
- Click Main Menu
- Click Configuration
- Click Configure Other.
- Paste the string of values you obtained from “Template 255” into the “Template” field. Change the name “Merged” to your choice to identify the device and enter a useful name in the “Friendly Name” field.
- Check the “Activate” box and click Save.
You’ve now configured the device and it’s ready for whatever you want to do with it.
If you have to go through the process of creating a template, you should share it. Here’s a link to the Templates Database, where you can submit it for inclusion: https://blakadder.github.io/templates/
The final entry for this project will show how to configure the plug for use in Hubitat!
SmarterHome.club is the website for our Facebook community, The Smarter Home Club – which is an umbrella for all kinds of smart home technologies – home automation, security, custom electronics, weather stations, alternative energy, you name it. DIY focused.
If you’re interested in joining the Smarter Home Club’s Facebook group, please follow this link:
The Smarter Home Club on Facebook