19 Feb 2022
Tuya-convert is a method of flashing Tuya devices without opening the device. In this article I will be using a Raspberry Pi to flash various Tuya devices such as Gosund UP111 smart plug with power monitoring.
To complete this task a Raspberry Pi with Ethernet and Wireless support is required. Raspberry Pi models that support this are:
Take a look at the community for supported Devices and Templates before you flash, we’ll be using templates.blakadder.com later in this guide.
WARNING!! - Use this software at your own risk!. The fact that you can flash Tasmota on your device does not mean all of its features are currently supported. Please research before purchasing to see if other users have successfully flashed the device and are able to use it fully.
If you are happy to take the risk, lets crack on!
Using the Raspberry Pi Imager tool, flash “Raspberry Pi OS Lite (32-BIT)” on to an MicroSD card.
Using the Cog for Advanced Options, set a hostname, enable SSH and provide a password for the default account Pi.
Then proceed by clicking the “Write” button.
Remove once complete.
Plug the Raspberry Pi into power and Ethernet then SSH into it.
You’ll need its IP address or host name.
ssh pi@tuya-convert
Once logged in set your Wi-Fi country via the Raspi-Config tool
sudo raspi-config
Navigate to “Localisation Options” > “L4 WLAN Country”, I have configured GB for Britain (UK).
Finish using the Raspi-Config tool and reboot.
Then log back in and make sure to update the repositories and upgrade any existing packages using the below command.
sudo apt update && sudo apt upgrade -y
Install Git as its required to pull the Tuya-Convert repo.
sudo apt install -y git
Clone the GitHub repository and run the install prerequisite script.
git clone https://github.com/ct-Open-Source/tuya-convert
cd tuya-convert
./install_prereq.sh
The script will take a minute to complete as it downloads all the prerequisites required to make Tuya-Convert work.
Run Flashing script by using the following command.
Make sure to have your devices ready to complete the flash.
./start_flash.sh
The script will prompt to terminate:
Accept both. - I noticed that I had to re-run the script after terminating DNS
The script will pause at the following screen
The Raspberry Pi will now be broadcasting its own Wi-Fi called “vtrust-flash” connect your mobile device to this Wi-Fi and ensure to continue using this network even without an internet connection.
Next place the Tuya device into pairing mode or flashing mode, to place most devices into EZ mode do the following:
You’ll know when its in pairing mode as the LED or bulb will flash. Continue by pressing “Enter”.
Tuya-Convert will then complete the pairing and automatically creating a locally stored backup of the device’s firmware.
Next a menu will appear with the following options:
I’ll be flashing Tasmota, so I’ll select option 2) flash tasmota.bin.
Give Tuya-Convert a few seconds to flash the device. A success message should appear and we can then flash another device or quit.
The flash has been completed and we can power down the Raspberry Pi and save the MicroSD card for later use.
The Tuya IoT device, flashed with Tasmota should now be broadcasting a new Wi-Fi called “Tasmota-xxxx”.
Once connected a pop up window will appear.
Fill the AP1 SSId and AP1 Password fields with your network Wi-Fi credentials.
Save the configuration and the IoT device will restart and connect to our Wi-Fi.
You’ll see the device in your DHCP server with a new address, which you can connect too.
Now we will apply our Tasmota Template. Find the template which is applicable to your device on https://templates.blakadder.com/.
I will be using the Gosund UP111 template, copy the Configuration.
Open Tasmota and navigate to “Configuration” > “Configure Other”, and past the Configuration into the Template field and check the activate button.
Upon saving the device will restart with the appropriate configuration, as shown in the screenshot below.
This device is now ready to be added into your preferred Home Automation system, such as Home Assistant.
Finally add a password to the device to secure against unwanted tinkering. Navigate to “Configuration” > “Configure Other” and enable “Web Admin Password” and provide a password.
I will briefly cover calibrating a device, although details of this process can be found on the Tasmota GitHub. To complete this you’ll need a Kill-a-meter or calibrated multi-meter and a resistive load device, which draws a constant amount of power such as a light bulb.
Steps
Before are the readings from the Kill-a-meter.
Commands are issued through the console on Tasmota Web UI.
Power
PowerSet 9.4
- enter your load’s power rating in Watts or reading from kill-a-meterVoltage
VoltageSet 237.7
- enter the standard voltage or reading from kill-a-meterCurrent
P(W)/V(V)=I(A)
CurrentSet 65
- enter the calculated current in milliAmps)Confirm
In the figure below the commands can be seen.
Before is a figure showing the Gosund plug before calibration.
Although there wasn’t much of a difference between the before and after, there was a current difference which can be seen, and the Power Factor is closer to 1.0.