Close

How to install ESPHome on Sonoff 4CH Pro R2

In this tutorial, we’ll see how to flash a Sonoff 4ch Pro R2 to install the ESPHome firmware. This IOT device has a lot of hardware : 4 switches, 4 Relays, 1 LED and 3 GPIO available for sensors ! And, as always, adding it to Home Assistant is a breeze.

What is ESPHome ?

ESPHome is an ecosystem which allows to control the hardware connected to ESP8266/ESP32 devices.

Using simple configuration files, it’s able to control LED strips, temperature sensors, inputs, outputs, i2c devices and a lot more.

Have a look at their site to see what it can do.

ESPHome
ESPHome

Material

Also used

Wiring

First, you need to remove the 4 screws on the back to open the Sonoff’s case. Then we can just pull the PCB out.

Once done, we have to solder a 5 pins header to the J1 port, located at the bottom left of the board.

As the other ESP8266 devices, it must be powered with 3.3v. Same thing for the serial transmission (RX TX). Using 5v serial adapter will damage your device.

Connect the Serial Adapter to the Sonoff 4ch

                  Serial Adapter      Sonoff 4ch
                       3.3v ------------- 3.3v
                       TXD --------------- RX
RXD --------------- TX GROUND ------------ GROUND

Install ESPHome

To use Python to upload the firmware, we need a Python 3 installed, this can be found here if you don’t already have it.

A Python package already exist to manage everything around the configuration and the upload. I can be installed by running the following command :

pip install esphome

Configuration File

Here is the basic configuration to control the 4 relays and the blue LED. Just like the standard firmware, I mapped each switch to toggle each outputs.

On your controller (Home Assistant or anything else), you’ll be able to see the 4 relays, the LED and the 4 buttons.

Also, in order to have a feedback of when it booted, the blue LED will automatically turn on.

Just copy that configuration in a file on your computer.

Enter in Programming mode

Putting a Sonoff Basic into programming mode is pretty easy : Press the button while it’s unplugged and plug it. For the Sonoff 4ch Pro, it’s the same process, the only problem is that there is no button.

So to enable the programming mode, on this one : 

  • Disconnect the serial adapter
  • Apply the Ground to GPIO 0, which is located on the upper right of the ESP chip (See bellow)
  • Now, reconnect the 3.3v. If nothing happens (AKA no Blue LED)

Congrats, it’s in programming mode ! 

Upload the Firmware

Your device is now ready for the firmware upload, it can be done with this command :

esphome my_awesome_node.yaml run

Add to Home Assistant

Since Home Assistant version 0.85, ESPHome is natively supported through the integrations. This can be configured directly from the UI, which means that we don’t have to play with the configuration files !

All the inputs and outputs from the Sonoff 4ch Pro R2 are now available on Home Assistant. 

What's next ?

I’m working on 2 other tutorials related to ESPHome and ESP8266 :