Tech Guide: How to Flash Tuya WIFI Switches with Tasmota with Tuya Convert
Flash Tasmota on Tuya Device using Tuya-Convert
The Tuya-Convert project allows you to free up from the cloud most of the Tuya devices that are based on the ESP8266 chipset. The device then can be used with newly flashed TASMOTA frimware with openHAB or other home automation servers without the need for a cloud server. This in turn gives you privacy and rapid respose compared to cloud based automation systems.
The 3-gang switch I have is based on ESP8266 chip, but it also has another chip (Tuya MCU) controls ESP8266 chip by sending and receiving commands between device buttons and the network. I has a standard protocol and I’ve tried to crack some of the data that can be used on the automation system such as power usage, voltage reading etc. I have the necessary links to the documentations and the way I setup my switch below.
There are some hardware requirements that you need to fulfil to perform this hack. There are other options available, I found this one worked flawlessly for me.
- Raspberry Pi 3 with Raspbian Installed. Use latest version available
- I smart phone or tablet to connect to the Wifi created by the script running on Raspberry Pi
- If you’re using Raspberry Pi 2, you will need a Wifi Dongle that is Linux Compatible. Some seem to work better than the others, so, check the reviews before investing.
Download and install the Tuya-Convert Project
1. Clone the Tuya-Convert project.
git clone https://github.com/ct-Open-Source/tuya-convert.git
2.Navigate into the Folder
Once the clone job is finished, a tuya-convert folder will be created in the home folder
This is a very long process, it can take 20 to 30 minutes so go get yourself some coffee while you wait.
1. Have your phone in handy to connect to the wifi that the script will create.
2. Start the Flashing Process
The first screen will show you the usual disclaimer. Please, keep in mind that you are doing this at your own risk and you could potentially brick your device.
Type yes, hit enter and get ready to start the flashing.
3. Open a second window to monitor the logs.
cd tuya-convert/scripts/ tail -f smart*
tail -f smart*
the logs files are created the first time you execute the script so you won’t see anything until you start the flash job by connecting to the WIFI vtrust-flash.
4. Before you proceed with the next step make sure of the following 2 messages show up
It will be required for you to be able to flash the device.
==> smarthack-web.log <==
Listening on port 80
==> smarthack-wifi.log <==
wlan0: Interface state UNITITIALIZED→ENABLED
This means Raspberry Pi wifi network is now running in ACCESS POINT mode, which we will connect in the next step.
5. Connect your phone to the AP created by the script.
If everything went OK, you should see a wifi called vtrust-flash which you can connect using the password flashmeifyoucan. If you can connect to the wifi but there is no internet, review the logs (step 4 above) and check if there was an issue creating the AP.
6. Put the Tuya device Device in Pairing Mode
If you are using the device out of the box, never paired with Smart Home app on iOS or Android, when it is powered for the first time it will boot up in pairing mode. In this case proceed to step 7.
If the device previously paired and used with Smart Put the tuya device in pairing mode. Every device is a little different so check your user manual to make sure you understand how to do it in your device. After the device is in pairing mode, hit enter and wait for the magic to happen.
The 3-gang switch: Press 1st power button from the left for 10 seconds to put switch in pairing mode, LED flashes once every two seconds.
7. Backup Tuya firmware
After a few seconds (minutes sometimes) you should see a screen like this one:
The script is now backing up the current version of the firmware on the device and getting it ready to upload a new one. The process should not take more than a couple of minutes and after that, you should see something like this.
Before getting on with the next step, make sure the active user space is user2. If it is not, run the following command!!
8. Upload Tasmota Firmware
The following command will start uploading the firmware to the tuya device. The tuya-convert project should already come packaged with the latest version of Tasmota.
Almost instantly you will get the following message on the screen.
Wait for the device to boot up with TASMOTA firmware.
First time when the Tuya device starts up with TASMOTA firmware, it runs in Access Point mode, allowing you to connect to that WIFI and configure the device with your own network credentials.
Connect to the wifi which will be named tasmota-xxx suffixed with 4 digits of the device MAC address. MAC address is usually assigned at the manufacturing plant and should be printed on the device or documentation came with it. Wifi is an open network, no password is required.
9. Configure Tasmota
The first screen you will see when you connect to the tasmota-xxxx network is a page to enter the details of your home wifi as explained in the following steps.
1.Hit the link below to start searching for wifi’s within range.
2. Select your home wifi in the list that pops up.
3. Provide the wifi password (CRITICAL STEP)
Before saving the settings, make sure you entered everything correctly, if not, it is a lot of fiddling and research to fix it. The device will not be able to connect to the network, it needs to be reset put into AP mode. So don’t make any mistakes here.
In order to make finding your new device on the network enter a Hostname that is meaningful to you. Such as FamilyRmSW (family room switch)
That’s it, your wifi is configured. If everything went OK, the device should now connect to your home network.
Using the Hostname entered, open a web browser and enter:
http://FamilyRmSW or the IP address for the new device which can be found from your router’s web interface.
Upgrade the firmware
After we provide the wifi connection details, the tuya device will be assigned an IP from your router that you will need to access to it. Use the configuration page of your router to find out the IP of the new device. It should have a name similar to the name of the AP. Paste the IP on the browser to access the Tasmota configuration page.
Before we configure anything on the device, we should make sure you are up to date with the version of the firmware. Let’s go ahead a do a firmware upgrade. (New version uses TASMOTA instead of Sonoff)
Configure the Tuya Device
There is a huge repository of Tuya device templates available ready to be used to configure Tuya devices from different manufacturers from this link blakadder.
The 3-gang switch I have is from an unknown manufacturer and few templates I tried did not work correctly.
Go to the Tasmota configuration page
From the main page, [Configuration] / [Configure Module] Enter the Following
Module type Tuya MCU (54)
GPIO1 Serial Out Tuya Tx (107)
GPIO3 Serial In Tuya Rx (108)
All options are available from the drop down list.
Click on [Save]
Tuya device with TASMOTA will now reboot and web interface will be connected in few seconds. Upon re-connection main menu will appear with 3 switches that can be controlled now. Test it and make sure all switches are working as expected.
Configure MQTT Connectivity
The device is already flashed and functional but if you want to use it with openHAB or any other open-source home automation system through MQTT, it is a good idea to configure the MQTT Connectivity.
Make sure you provide a Topic name so you can identify the MQTT messages. You should at this point know your MQTT standards, apply your won standards or just use defaults given in the firmware. Click [Save] and all done and ready to be incorporated in you Home Automation system.
Set date Time for Sydney
The commands for various Tuya devices can be different so you may want to read carefully the commands page
This will set Standard time to 600 minutes before UTC from 1st Sunday of April at 2AM and DST Daylight saving time to 660 minutes from UTC from 1st Sunday of October at 1AM. Timezone simply implies to use the date/time based on the STD or DST. Time keeping is accurate and very reliable.