Using With Sonoff 4CH¶
ESPHome can also be used with Sonoff 4CH wireless switches. These devices are basically just an ESP8266 chip with 4 relays to control power output, a few buttons on the top and a few status LEDs.

Sonoff 4CH WiFi switch.¶
This guide will step you through setting up your Sonoff 4CH and flashing the first ESPHome firmware with the serial interface. After that, you will be able to upload all future firmwares with the remote Over-The-Air update process.
Note
If you’ve previously installed Sonoff-Tasmota on your Sonoff 4CH, you’re in luck 😀. ESPHome can generate a firmware binary which you can then upload via the Tasmota web interface. To see how to create this binary, skip to Step 3: Creating Firmware.
Since firmware version 1.6.0, iTead (the creator of this device) has removed the ability to upload a custom firmware through their own upload process. Unfortunately, that means that the only way to flash the initial ESPHome firmware is by physically opening the device up and using the UART interface.
Warning
Opening up this device can be very dangerous if not done correctly. While the device is open, you will be a single touch away from being electrocuted if the device is plugged in or connected to a high voltage ‘mains’ power supply.
So, during this entire guide never ever plug the device in or have it connected to mains power. Also, you should only do this if you know what you’re doing. If you, at any step, feel something is wrong or are uncomfortable with continuing, it’s best to just stop for your own safety.
It’s your own responsibility to make sure everything you do during this setup process is safe.
For this guide you will need:
Sonoff 4CH 😉.
A USB to UART Bridge for flashing the device. These can be bought on Amazon (or other online stores) for less than 5 dollars. Note that the bridge must be 3.3V compatible. Otherwise you will destroy your Sonoff.
Jumper wires to connect the UART bridge to the header pins.
A computer running Home Assistant with the ESPHome Home Assistant add-on.
A screwdriver to open up the Sonoff 4CH.
Have everything? Great! Then you can start.
Step 1: Opening up the Sonoff 4CH¶
The first step is to open up the Sonoff 4CH. Note that you do not have to run the original firmware supplied with the Sonoff 4CH before doing this step.
Warning
Just to repeat this: Make absolutely sure the device is not connected to any appliance or connected to mains power before doing this step.
While the device is not plugged in, turn the device so you are viewing it from the top, then unscrew the long screws in the four corners of the top cover.

There are four screws on the front of the Sonoff 4CH.¶
After that, you should be able to remove the front cover and should be greeted by the main board. The chip we’re interested in here is the “big” one encased in an aluminium cover.

The main chip of the Sonoff 4CH and the header pins we’re going to use to flash our custom firmware.¶
Step 2: Connecting UART¶
Now we need our computer to somehow establish a data connection to the board. For this we will have to connect the four wires on the UART to USB bridge to the UART pins of the Sonoff 4Ch.
Fortunately for us, exactly these pins come pre-populated with a few header pins. You can identify
these by the VCC33
, RX
, TX
and GND
markings on the silk-screen.
Now go ahead and connect these pins to your UART to USB bridge as seen in the below image. Make sure
that you connect these correctly, especially the VCC33
and GND
parts as you can otherwise
destroy the chip.
VCC33
should be connected to the 3V3
(not 5V) pin of the UART bridge, GND
to GND
and the same with RX
/TX
.
When you’re done, it should look something like this:

Note
On some older 4CHs, the RX
and TX
pins are swapped (sometimes even the written silkscreen is
wrong). If your upload fails with an error: espcomm_upload_mem failed
message it’s most likely due
to the pins being swapped. In that case, just swap RX
and TX
and try again - you won’t break
anything if they’re swapped.
Step 3: Creating Firmware¶
The Sonoff 4CH is based on the ESP8266
platform (technically it’s the ESP8285
, but for our purposes
they’re the same) and is a subtype of the esp01_1m
board.
With this information, you can step through the ESPHome wizard (esphome sonoff_4ch.yaml wizard
),
or alternatively, you can just take the below configuration file and modify it to your needs.
esphome:
name: <NAME_OF_NODE>
esp8266:
board: esp8285
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
api:
logger:
ota:
Now run esphome sonoff_4ch.yaml compile
to validate the configuration and
pre-compile the firmware.
Note
After this step, you will be able to find the compiled binary under
<NAME_OF_NODE>/.pioenvs/<NAME_OF_NODE>/firmware.bin
. If you’re having trouble with
uploading, you can also try uploading this file directly with other tools.
Step 4: Uploading Firmware¶
In order to upload the firmware, you’re first going to need to get the chip into a flash mode, otherwise
the device will start up without accepting any firmware flash attempts. To do this, while the UART
bridge is not connected to your USB port, press and hold the bottom-left push button labelled FW/IO0
and continue to do so while plugging in the UART bridge into your computer. Keep holding the button for
another 2-4 seconds. The 4CH should now be in a flash mode and should not blink any LED.

You need to press the button labelled FW/IO0
during startup.¶
Now you can finally run the upload command:
esphome sonoff_4ch.yaml run
If successful, you should see something like this:

Hooray 🎉! You’ve now successfully uploaded the first ESPHome firmware to your Sonoff 4CH. And in a moment, you will be able to use all of ESPHome’s great features with your Sonoff 4CH.
If above step don’t work, however, here are some steps that can help:
Sometimes the UART bridge cannot supply enough current to the chip to operate, in this case use a 3.3V supply you have lying around. A nice hack is to use the power supply of NodeMCU boards. Simply connect the NodeMCU’s 3.3V to VCC and GND to GND. Do not connect mains power to the device in an attempt to overcome this problem while troubleshooting.
In other cases the
TX
andRX
pin are reversed. Simple disconnect the device, swap the two pins and put it into flash mode again.
Step 6: Finishing Up¶
If you’re sure everything is done with the 4CH and have double checked there’s nothing that could cause a short in the case, you can put the front cover back on and screw everything together.
Now triple- or even quadruple-check the UART bridge is not connected to the 4CH, then comes the time when you can connect it.
Happy hacking!