In the previous article, we discovered the Sonoff 4CH Pro, a control box that allows to control by WiFi and by radio 433MHz up to 4 relays. In this new tutorial, we will see how to install the Tasmota alternative firmware developed by Theo Arends. The Sonoff 4CH Pro can be installed in a control cabinet on a DIN rail. The EWeLink home application developed by Itead (the manufacturer of Sonoff products) allows you to control all devices in the range from a smartphone or tablet and create small scenarios. Everything goes through the Itead servers. This allows you to access your devices even outside your home when you have a 3G/4G connection (which is the case in 99% of the time, I hope!). This solution may disturb some users. First, EWeLink is totally closed. Can not create a bridge to a 100% DIY home automation server. On the other hand, you have no control over your personal data. This is a very sensitive issue right now. Here is how to install the Open Source Tasmota firmware from Theo Arends. All the steps in this tutorial can be applied to all Sonoff modules, including a technical comparison on the price comparator.
- 1 Introducing the Tasmota firmware for Sonoff / Itead products
- 2 Before going further
- 2.1 Electrical Hazard Warnings and Warranty
- 2.2 Can this tutorial be applied to other Sonoff devices?
- 2.3 #Deal: Sonoff Basic, WiFi smart switch compatible Google Home,...
- 2.4 #Deal: Sonoff RF, 1x WiFi and RF 433MHz smart switch relay com...
- 2.5 #Deal: Sonoff DUAL, WiFi smart switch 2 relays compatible Goog...
- 2.6 #Deal: Sonoff POW, WiFi smart switch module with power consump...
- 2.7 #Deal: Sonoff TH10, WiFi smart switch 1x 10A relay with temper...
- 2.8 #Deal: Sonoff TH16, WiFi smart switch 1x 16A relay with temper...
- 2.9 #Deal: SONOFF 4CH: 4x smart switch relays for mounting on DIN ...
- 2.10 #Deal: Sonoff 4CH PRO, 4x smart switch relays with WiFi and ra...
- 3 What software do you need? esptool.py, PlatformIO
- 4 Preparing the Sonoff 4CH Pro
- 5 Connect the FTDI cable
- 6 Find the Sonoff 4CH Pro COM Port
- 7 Back up the original firmware and erase the memory
- 8 Download the firmware from GitHub
- 9 Install the Tasmota firmware on the Sonoff 4CH Pro
- 10 Configure the module
- 11 Inclusion of Sonoff 4CH Pro in Domoticz
- 12 Create control buttons for relays
- 13 Pilot the Sonoff 4CH Pro from Domoticz
- 13.1 #Deal: Sonoff Basic, WiFi smart switch compatible Google Home,...
- 13.2 #Deal: Sonoff RF, 1x WiFi and RF 433MHz smart switch relay com...
- 13.3 #Deal: Sonoff DUAL, WiFi smart switch 2 relays compatible Goog...
- 13.4 #Deal: Sonoff POW, WiFi smart switch module with power consump...
- 13.5 #Deal: Sonoff TH10, WiFi smart switch 1x 10A relay with temper...
- 13.6 #Deal: Sonoff TH16, WiFi smart switch 1x 16A relay with temper...
- 13.7 #Deal: SONOFF 4CH: 4x smart switch relays for mounting on DIN ...
- 13.8 #Deal: Sonoff 4CH PRO, 4x smart switch relays with WiFi and ra...
Introducing the Tasmota firmware for Sonoff / Itead products
The Tasmota firmware is developed and maintained by Theo Arends (its GitHub page and personal site). It is designed on a principle similar to the Homie firmware. It adds a configuration interface accessible via a web browser from any computer, tablet or smartphone on the same local network. It then uses MQTT messaging to communicate with a home automation server, an online server, a mobile application iOS, Android …
The Tasmota firmware will therefore subscribe to an MQTT broker (read this article for more information). We can send him orders. Essentially “active” or “disable” relay X.
In return the firmware Tasmota will publish (send messages) to the broker MQTT:
- The relay has been activated (or not)
- It may send measures:
- Temperature, humidity if a probe is connected (there are pins still available on the modules, cool)
- Power consumption for the Sonoff POW module
The advantage of this firmware is that it is totally dedicated to Sonoff devices. As it is specialized, there is very little configuration to do. You will be able to install the same firmware on all your Sonoff home automation devices (if you are a fan of the brand of course!).
We will return in more detail to the features proposed in a future article. Now let’s turn to a practical case and see how to install this firmware on the ESP8285 that equips the Sonoff 4CH Pro.
Before going further
Electrical Hazard Warnings and Warranty
Before I start, it seems important to me to recall some safety rules. First, you will modify an electrical appliance. These modifications will void any manufacturer’s warranty. On the other hand, this tutorial can be applied to all Sonoff modules. With the exception of the 4CH Pro, they are powered with a voltage of 220V.
Can this tutorial be applied to other Sonoff devices?
Yes, the method presented in this tutorial can be applied to almost the entire range. The main difference is the setting of the module in flash mode. You will find on the WiKi the procedures to follow for the other models of the brand:
- Sonoff Basic
- Sonoff Dual
- Sonoff Pow
- Sonoff RF and Slampher
- Sonoff RF Bridge 433
- Sonoff Touch
- Sonoff 4CH
- Sonoff B1
- HuaFan Smart Socket
The following table summarizes the main specifications of the Itead Swich Smart Home Sonoff switches
What software do you need? esptool.py, PlatformIO
It is possible to install the Tasmota firmware from most development software:
- IDE Arduino
- PlatformIO on the GitHub ATOM Editor
- Visual Studio Code with the PlatformIO plugin. This is the solution that I advise you. Visual Studio Code is much lighter and more stable than Atom
- esptool.py, the python script of the Espressive SDK
Installation from the Arduino IDE is not the easiest method. It is necessary to modify the IDE by adding the support of the module ESP8285, to install libraries … As this tutorial is addressed first and foremost to the beginners, I propose you to opt for PlatformIO which takes care of everything. Follow this article to install PlatformIO on your PC or Mac. Once installed, it will be possible to update it over-the-air using the SonOTA python script or by downloading the firmware directly from the configuration interface using a web browser.
Finally, you will need to install esptool.py tools from the Espressif SDK ESP8266. Follow this tutorial for macOS (also works for Linux) and this one for Windows. The esptool.py script will allow to save the old firmware, and to erase the flash memory before installing the new one.
Preparing the Sonoff 4CH Pro
Like all models in the Sonoff range, we will have to solder a connector on the circuit. Start by opening the module (note, there is no warranty cancellation label, Itead leaves everyone free to change the firmware).
The connector must be soldered just next to the ESP8285 module (below the LEDs). Here I opted for a male hearder (easier to cut out), choose according to your Jumpers. To put the module in flash mode, it will be necessary to connect the pin GPIO0 to the GND to the ignition. I advise you to add a small female connector on a GND pin of the circuit. For example, on the unpopulated connector located above the S6 switch.
Before each firmware download, connect the GPIO0 pin to the GND with a jumper and then turn on the module (either by connecting the VCC pin of the FTDI cable, or with a 5-24VDC power supply). Just wait 1 or 2 seconds before releasing the jumper. If the blue LED indicates a WiFi activity, it means that the module is not in flash mode. We must start again.
It’s ready !
Connect the FTDI cable
The FTDI cable will allow us to communicate with the ESP8285 / ESP8266 via the serial port. Nothing special except that the pins are reversed on some models. Depending on your FTDI cable and the Sonoff module, you may have to fumble a bit. For the tutorial, I used this Adafruit cable.
Obviously, I started by plugging the connector of my cable to the serial port freshly welded on the 4CVH pro. And there, nothing at all! Do not panic, just find the pins RX and TX on the cable (google is our friends) and use 3 jumpers (GND, RX, TX) to make a manual connection. Normally, we have to reverse the jumpers between RX and TX but this is not the case on most Sonoff products because there is a misregistration on a PCB. Try first without reversing. If that does not work, reverse RX / TX.
Put the Sonoff 4CH pro in flash mode (programming mode)
Now place the jumper on the GPIO0 pin of the ESP8285 and the GND pin. Pin GPIO0 is the second pin of the module. Turn on the module using the 5-24VDC power supply. No LEDs (the blue one in particular) should light up. The module is in flash mode! Everything is ready to install the new firmware.
Find the Sonoff 4CH Pro COM Port
On Windows, connect the FTDI cable. Wait for the drivers to install if it’s the first time. Open PowerShell and execute the mode command. The COM port on which Sonoff is connected is listed. If it does not, go to the control panel to verify that the drivers for your FTDI cable are correctly installed
On macOS or Linux, open the Terminal and run the ls /dev/tty.usb* command. In return you should have COM port in the form
Back up the original firmware and erase the memory
Open PowerShell or a Terminal and run the following command replacing the COM port to back up the original firmware on your computer.
esptool.py --port PORT_COM read_flash 0x00000 0x100000 image1M.bin
The dump (copy) of the flash memory is saved in the image1M.bin file in the executable directory of the esptool.py script.
Now, run this command to completely erase the old firmware from the flash memory of the ESP8285. Modify the COM port before running the command.
esptool.py --port PORT_COM erase_flash
To restore the old firmware, run this command by changing the COM port.
esptool.py --port PORT_COM write_flash -fs 1MB -fm doubt 0x0 image1M.bin
Download the firmware from GitHub
Go to GitHub to download the project repository.
Install the Tasmota firmware on the Sonoff 4CH Pro
Launch PlatformIO and open the project from the File -> Open Folder menu. Specify the project GitHub repository path. Open the user_config.h file and look for the STA_SSID1 key. Replace the WiFi login and password. You can specify a second alternative network.
Then open the platformio.ini configuration file at the root of the project and uncomment the target env_default = sonoff. Go to the PlatformIO menu and compile the firmware with the Build option. PlatformIO takes care of everything!
Once finished, start the installation from the PlatformIO menu and upload. At the end of the installation, the reboot module. The blue led flashes the time to connect to the WiFI network and then lights up continuously. Bravo! You have completed the installation. Return to the menu and open the Serial Monitor.
Choose the COM port on which the Sonoff 4CH Pro is connected.
Wait for PowerShell or the Terminal to launch. Unplug and reconnect the Sonoff to obtain the Tosmata firmware boot log. What interests us here is the IP address that was assigned to Sonoff 4CH pro.
Configure the module
Open a web browser and enter the IP address retrieved from the serial monitor. Here is the new configuration interface.
The first thing to do is to indicate the module used. By default, the Sonoff Basic is selected. Go to the Configuration page and then Configure Module. In the list, choose Sonoff 4CH Pro (# 23) and then Save. The reboot module.
You can now control relays from the Web interface but also from the 4 command buttons that are always available. The different modes are also supported by the firmware (Self-locking, Interlock and Inching presented in the previous article). To control relays independently, configure the selectors as follows:
- S6: out of 1
- K5: all about 1
- K6: all of 0
Inclusion of Sonoff 4CH Pro in Domoticz
The Tasmota firmware makes perfect sense when you have a home automation server.
Prepare the MQTT Broker
All exchanges with Domoticz will be via an MQTT broker. Start by following this tutorial to install it on your system.
Adding an MQTT gateway
Now that you have an MQTT broker, we will connect Domoticz. It will thus be able to receive messages from the firmware: change of state of the relays, acknowledgment of receipt of an order, measurement record (temperature, humidity, level, etc.). It will also be used to send commands to Sonoff modules manually or according to a scenario.
Go to settings then Hardware. In the list of types, choose MQTT Gateway Client with Lan Interface and fill in the various parameters
- Give a name. For example Mosquitto
- Remote address: the IP address of the broker MQTT or localhost if it is installed on the same machine
- Port: default 1883
- Login and Password if access to the broker is protected. Leave empty otherwise.
- Publish Topic: do not change anything.
- Finish by clicking Add
Adding a virtual device
Now that we can receive and send messages, we must create a virtual hardware to which will be attached buttons and possibly measuring instruments. In the Type list, choose Dummy, and give a name. Finally add.
You can now create as many virtual buttons as you have relay on your Sonoff. 4 in the case of Sonoff 4CH Pro. To create a virtual button, click Create Virtual Sensors in the Dummy Device Type column just created.
In the dialog box that appears, choose Switch and give the desired name.
Then go to the Devices (Settings -> Devices) to find the 4 virtual buttons that will allow to control the 4 relays. What interests us here are the Idx attributed by Domoticz. Here from 14 to 17.
Configuring the MQTT and IDX Domoticz broker on the Sonoff 4CH pro
Log in to the Sonoff administration interface and go to the Configuration -> Configure Domoticz page. Report the IDXs found previously. End with Save. The reboot module. As you can see, everything is already ready on the Tasmota firmware to manage other sensors (Temperature, Temp + Humidity, Barometer, energy + power Sonoff POW, brightness Sonoff SC, counter).
After the restart, go to the Configuration page and then Configure MQTT. Fill in the Broker connection settings:
- Host: the IP address of the broker
- Port: 1883 by default
- User and Password if access to the broker and controlled by a password
- You can leave the other parameters with the default values.
- Save. The Sonoff reboot.
Pilot the Sonoff 4CH Pro from Domoticz
From Domoticz, go to the Switches tab. You will find the 4 command buttons created previously. Press a button. If all is correct, you will hear it “snapping” and the corresponding LED will turn it on to indicate that it has been activated.
Here. In the next tutorials we will see how to include Sonoff modules on other home automation servers (Jeedom, Home Assistant) or a dashboard for connected objects (Node-RED …).
I am not the author of (all) the tips proposed in this tutorial. We can thank Blair Thompson who has already contributed to the Sonoff S20 Hack.
The following table summarizes the main specifications of the Itead Swich Smart Home Sonoff WiFi switches.
- ESP8266, Deep Sleep mode test, wake up with a PIR motion detector
- HC-SR04 (ultrasound) vs Sharp GP2Y0A02YK0F (IR) vs VL53L0X (Laser), which solution to choose for distance measurement with Arduino or Raspberry Pi
- Test and Calibrate Sharp GP2Y0A02YK0F Asian Clone proximity Sensor
- Install Grafana on macOS and Raspbian for Raspberry Pi. Example dashboard for connected object MySensors with Node-RED and InfluxDB [Update]
- Install InfluxDB on Raspberry Pi, Windows, macOS. Discovery of the Shell. Create a database, retention [Update]
- New Raspberry Pi 3 Model B+ 2018 @1.4GHz, Gigabit Ethernet, Ethernet POE Daughter Card, Flash Sale at $49.99 on Gearbest