Back when those ultra cheap WiFi switches from Sonoff flooded the market, I invested in a few and started to tinker with writing my own code for them in the Arduino IDE. I learned the basics from KmanOZ and my home automation project began to grow. A few years later, these ESP8266 devices are everywhere and people have developed great software for them like Tasmota, ESPhome and ESPEasy. My original sonofff switches (I have around 10) were looking a bit basic. They have no ability to update firmware over the air, no ability to change WiFi password or MQTT host over the air. So I decided recently to update all these devices to the Tasmota firmware, which does all the above and much more.
However, the task of pulling out 10 sonoff switches from wherever I had embedded them in the house and taking them apart to upgrade them via a UART/FTDI link, didn’t thrill me. I also remember in the early days, having problems with getting the UART link to work correctly and having the right supporting software on my P.C. etc…What a pain! But thankfully this process is so much easier now. So here is my cookbook for currently the quickest way to flash a sonoff device with minimum fuss.
Do not have mains electricity plugged in whilst doing any of the below!
- If its not already set-up on your computer, download and install Python 3.7+ for windows.
- Once installed, go to the Python installation directory and go into the folder called Scripts. Check that there is a windows executable called pip.
- Open a windows command terminal (not a python terminal) and type ‘pip install esptool’. This will download esptool to the Scripts directory.
- Go to the Tasmota website and download the sonoff firmware. I was delighted to find a well documented github page and wiki. There are lots of firmware versions, but for the basic Sonoff switch, the only file I needed is the file called sonoff.bin.
- So now we have all the software we need. We have Python, Pip, and Esptool. Esptool is the program that manages the firmware upload to the sonoff switch.
- Open up your sonoff device and attach your FTDI cable – 3.3v,Tx,Rx,Gnd. I have used an FTDI to USB interface cable based on the CP2102 chip for years and it’s still working good. Similar ones are available on EBAY.
- Hold down the power button on your Sonoff switch and Plug the FTDI into your PC USB port. This will put the esp8266 CPU into firmware upload readiness.
- Run the following command (substituting any file paths and COM ports as needed)
“C:\Python\Python37-32\Scripts\esptool.py –port COM15 –baud 115200 write_flash –flash_size=detect –flash_mode=dout 0 C:\Users\robert\Downloads\sonoff-6-4-1.bin”
- If all goes right then the sonoff firmware should start uploading and after a successful upload you will see a screen like below.
- Pull out the usb plug on the FTDI cable and re-insert. This will reboot the Sonoff switch.
- Using your mobile phone, search and connect to a new Wifi SSID which identifies as Sonoff_xxxx. Make a note of this ID for later.
- Open your mobile phone browser and type ‘http://192.168.1.4’. This should now present you with the Tasmota web page on your newly flashed device.
- At this point you can toggle the switch on and off to check that your device is working.
- Enter the menu ‘Configuration’ and then ‘configure WIFI’ and choose to scan for wifi networks. You can now set it to the Wifi network of your home and save to configuration.
- Lastly, on your home router, search for the new device called sonoff_xxxx, so that you can establish the IP address that has been allocated to it on your home network. You can now browse to this IP address on your PC browser to explore the Tasmota software.
As I had 10 devices, I had to do this 10 times, but at least I got very efficient at it and because Tasmota software is configurable over the air, I shouldn’t have to ever do this procedure again (unless I buy more Sonoff switches that is).
If you are having problems getting the software to upload you can try the following.
- Re-insert the FTDI USB plug whilst holding down the Sonoff switch button to make sure it went into bootloader/firmware upload mode.
- Check your COM port is correct in Windows Control Panel device manager.
- Check windows has recognised the FTDI cable. Windows may need to download a driver file to recognise a CP2102 chipset.
- If you have a very old sonoff switch it may need flash_mode=qio instead of flash_mode=dout, because they changed out the EEPROM on newer devices.
- Don’t get frustrated and remember google is your friend.
Now the pain of converting to Tasmota is over you can install the excellent ‘Tasmo Admin’ add on for Home assistant and management of all your sonoff devices in the future is a doddle.