#Hack: SONOFF S20 plug to make it a super intelligent plug with ESP Easy

Black Friday on Amazon right now! Black friday Banggood Gearbest Black Friday
Extra 10% off For XIAOMI SUPER HOME TECH GADGET Sale

Smart Home kits, security camera, robot vacuum cleaner, air purifier ... *Excluding products already on promotion

Reveal
35 days left

Today I present a tutorial that was proposed to me by Bernard, a reader of DIY Projects. In this tutorial, Bernard explains how he hacked the ESP8266 from a connected SONOFF S20 plug. SONOFF specializes in the manufacture of power supply (Wi-Fi controlled plug, power supply …), relay card, etc. These devices are built around a Wi-Fi module ESP8266. SONOFF also markets its products are the bare card form to integrate into DIY home automation projects. SONOFF thought of the hackers leaving the serial port accessible on the map. To control its plug connected from Jeedom, Bernard installed the firmware ESP Easy. He also used the Rule system presented here to program the command button available on the facade. A very big thank you to Bernard for sharing his experience and the quality of his tutorial.

Warnings. Replacing the original firmware will void the warranty. It is not possible to reinstall the original firmware. The devices are not CE or FC. You are responsible for the use of SONOFF products. diyprojects.io can not be held responsible in case of accident, injury or deterioration of material.

Project display

Home automation is gradually being democratized with the continuous appearance of new connected objects.

On the communication protocol, two technologies stand out, wifi and bluetooth, allowing direct communication with smartphones without having to go through a gateway (ex RF433, Zwave, …). Wifi has the advantage of a wider range often allowing to cover the whole of a house, but it allows above all to communicate via Internet thanks to the domestic box and its integrated router.

So everywhere, out of home, one can interact with objects connected by wifi. But the constraining side of connected objects is that each manufacturer has its dedicated app on the smartphone. The idea is to move towards wifi links easily recognized by home automation solutions. For example, Jeedom, a free open source home automation solution, continually develops new interfaces thanks to its “plugins” concept.

And for wifi there is the Espeasy plugin that allows to interact with the equipment equipped with a wifi module Esp8266 “flashed” with the firmware Espeasy.

In general, WiFi modules operate with proprietary firmware, and the Esp8266, a wifi module that is very popular among makers, can be flashed with many firmware, especially Espeasy, which offers a user-friendly web interface. One of the basic components of the connected house is the power socket controlled to: simulate presence (light, music, …), trigger auxiliary heating, turn on the radio for its alarm clock, …

The object of this article is to transform a conventional wifi plug into a super communicating plug and capable of managing in addition various sensors: temperature, pressure, humidity, luminosity, …

On the market it seems that the SONOFF S20 is currently the only wifi plug equipped with a module Esp8266.

How to flash ESP Easy firmware on the SONOFF S20 plug

If you discover ESP Easy, I refer you to this general article before going further.

Necessary material :

The SONOFF S20 plug is supplied and configured for the E-Welink app. The flashing ESP Easy will obviously overwrite its initial configuration.

First remove the plug: remove the screw on the back (hidden by the red label), then unclip.

sonoff s20 prise connectee wifi esp8266 diy hack sonoff s20 prise connectee dos wifi esp8266 diy hack

A connection area with 4 terminals (VCC, RX, TX, GND) is located on the electronic board; The marking is not systematic.

Next, a 4-pin header on the board must be welded to form the flash connector (welds on the reverse side), and for the applications described below.

sonoff s20 connector serial rx tx sonoff s20 connector serial port rx tx hearder

The most tricky operation if one can say is to connect the socket properly to your PC via the FTDI serial converter with the following diagram:

Side SONOFF S20 Side FTDI
VCC VCC  (be careful to set the FTDI jumper to 3.3 V)
RX RX
TX TX
GND GND

Install the Espeasy firmware on your PC (download the R120 version from https://sourceforge.net/projects/espeasy/)

In deziping one obtains:

esp easy esp8266 firmware zip

Double click to launch flash.cmd

espeasy sonoff s20 flash

You must fill in 3 fields:

  • Comport: No USB port of your PC to which the FTDI is connected (on Windows: Settings -> Connected devices -> Device Manager -> Ports)

Tip: If you have the Arduino IDE, open the IDE and go to Tools -> Port

  • Flash size: 1024 (memory size of the Esp8266)
  • Build: 120 (Espeasy version)
  • Then Enter

Before uploading Espeasy, you must configure the Esp8266 in flash mode: before connecting to VCC, press the button on the socket (the GPIO 0 will be set to GND) and keep the power on during power-up.

Uploading is fast:

espeasy sonoff s20 flashing firmware

If the flashing fails, the FTDI may not supply sufficient current. In this case, power the Esp8266 VCC with a separate 3V power supply (eg 2 x 1.5V batteries) with GND pooling.

The youtube video demonstrates how to change and flash the SONOFF S20 plug.

Once the flashing is finished, Espeasy must be started and its main functionalities must be known. Everything is explained in this tutorial.

I nevertheless draw attention to the step where the screen appears with “Proceed to main config”, do not forget to reconnect on its Wifi network before launching Proceed to main config.

Now that Espeasy is installed how to drive the operation of the plug, first with the Espeasy web interface then with Jeedom.

The plug has a relay and a pushbutton for manual operation.

The relay is activated by the GPIO 12 (1 = ON, O = OFF) and the push button acts on the GPIO 0 (pressed = 0, released = 1).

To test the relay, use the “Command” function in “Tools”: enter “gpio, 12,1” then Submit; The relay slams. With gpio, 12.0 the relay returns to idle.

sonoff s20 esp easy test command

Let’s test the push button: nothing happens. This is normal, you have to create a program with the GPIO 0. For this we will use the programming editor Rules and create Devices.

Creation of 3 Devices:

  • SWITCH, linked to the pushbutton
  • GPIO12, linked to the relay
  • GPIO2, virtual device for programming needs

sonoff s20 hack esp easy devices

Configuring Devices:

sonoff s20 hack esp easy switch command

sonoff s20 hack esp easy switch command

sonoff s20 hack esp easy gpio-12

Devices GPIO2 and GPIO12 have been created to have status feedback from associated GPIOs.

By activating the relay via the gpio command, 12.1, the device GPIO12 changes to state 1.

Let’s move on to the programming logic: pressing the pushbutton must change the state of the GPIO12 regardless of the event that created its initial state.

To familiarize yourself with Rules I recommend reading this post and https://www.letscontrolit.com/wiki/index.php/ESPEasy#Rules_page

Here’s the script you just paste into the Rules field:

sonoff s20 hack esp easy rule

One tests: it works, and the blue LED lights up when the relay is activated.

But our catch has other resources that Esp. Remember the 4 terminals of the flash connector: VCC, GND, TX, RX.

These terminals are available to power sensors, indeed TX and RX are respectively connected to the GPIO1 and GPIO3.

The list of sensors and equipment managed by Espeasy is already quite consistent: https://www.letscontrolit.com/wiki/index.php/ESPEasy#Supported_Sensors.2FActuators

These sensors and various equipment are powerful and cheap (a few euros on Amazon, Ebay, Aliexpress, …)

Note that if you configure the GPIO1 and GPIO3 in SDA and SCL (I2C communication) you can connect several sensors or devices using this communication mode: for example a BME280 weather sensor (pressure, temperature, humidity) and a 4×20 LCD or Oled SSD.

Indeed Espeasy differentiates the I2c addresses of each device (I2C Scan function from the Tools menu).

On the practical level, a 3.5 mm jack with 4 connectors can be used to properly connect the sensors.

Thus, the advantage of a SONOFF S20 thus modified can be seen, for example, in order to independently regulate the temperature and / or humidity of a room with heating equipment, a dehumidifier; The lighting according to the brightness.

An example of weather sensor tested on a SONOFF module, and the S20 jack modified with a jack.

sonoff smart power sonoff s20 hack

But the best is to integrate our instrumented plug into a home automation solution.

Here again Espeasy is very user-friendly because it can communicate through many protocols: HTTP, MQTT, ThingSpeak, …

And with Jeedom it’s a breeze, see this post and this other.

The same process obviously applies to all SONOFF products integrating a wifi module ESP8266

Conclusion

In home automation wifi offers a very effective mode of communication in both flow and range. Thanks to the appearance of open components such as ESP8266 it becomes relatively easy to boost the capacities of cheap basic products such as a connected plug and integrate them in open domotic solutions like Jeedom, Domoticz or Home Assistant.

 

Subscribe to the weekly newsletter

No spam and no other use will be made of your email. You can unsubscribe anytime.

Tags:

DIY Projects