Sonoff, a (smart) wifi switch, which you can buy for appr. 6 dollars on several Chinese websites. Sonoff is a cost effective smart home solution designed and produced by ITEAD. It’s a ESP8266 based WiFi wireless switch that can connect to appliance of different types and brands.

Standard it will be delivered with a Chinese app, which means the ‘cloud’ is necessary to operate this device. I don’t like the cloud when it comes to control and or monitor my smart home. I did a search on the internet en some guys were able to flash the ‘esp easy’ firmware to it 🙂

 

sonoff

Do a search on Youtube like “sonoff esp easy” and you will find many tutorials how to accomplish this.

What do you need?

  • Sonoff R1 (wifi only, I don’t have the version with RF 433 Mhz)
  • Solder headers (male or female, it’s up to you). Those are not delivered with the Sonoff, but you have to solder at least 4 headers to the pcb
  • USB-TTL converter ( CP2102 serial converter chip) 6 pins TTL connector for 3,3V, RST,TXD, RXD, GND and 5V.
  • At least 4 jumper wires to connect the Sonoff headers to the USB_TTL (which are male connectors)

I’ve connected the USB-TTL converter – without any wires connected- once to my computer, so I was sure the device is recognised correctly, and a COM-port was visible in device manager.

Connecting wires

Connect the jumper wires between the Sonoff and the USB-TTL converter as following:

Sonoff (up to down) wire setting:

  • Red: 3.3V
  • Purple: RX
  • Yellow: TX
  • Black: GND
  • Empty: GPIO 14

sonoff-int              Sonoff-jw

In the most online tutorials the jumperwires are in different order, but in my case the purple and yellow are switched, (This is explaned there too. If flashing the firmware is not working, you have to switch the RX/TX wires, in my case the yellow and purple wires).

USB-TTL converter (up to down) wire setting:

  • Red: 3.3V
  • Purple: TXD
  • Yellow: RXD
  • Black: GND

Be sure the 4 wires are connected correctly between the 2 devices.

Flashing firmware

While holding down the button on the Sonoff (long black pin next to led), connect the USB to your computer.

Once it’s connected, you can release the Sonoff button. This bring the Sonoff in programming mode.

Download the ESP easy firmware and flash tool on the following website: http://www.letscontrolit.com/wiki/index.php/ESPEasy

When downloading the latest stable firmware version 120, the download included also the flash tool:

ESPeasyflash

Start “Flash.cmd”.

The prompt, will ask 3 questions, which has to be entered, and confirmed with ENTER.

  • Comport: in my case 5 (see device manager for the correct one)
  • Flash size: 1024
  • Build: the firmware version in above overview = 120

startflash

Now the firmware flash procedure will start automatically.

If you receive “connect failed” messages, close the prompt window.

Switch the TX/RX wires on the USB-TTL converter. Leave the 3.3V and GND untouched, so the Sonoff will stay in programming mode.

Once the 2 wires are switched, start the “flash.cmd” again and enter the above values again.

Uploading is started, and many dots will follow at the bottom of the screen:

espupload1

Finally, “flush is complete” and the command screen can be closed to press any key.

espupload2

The ESP easy firmware is now successfully flashed on the Sonoff.

The Sonoff is now ready for configuring, via one of the following connections:

  1. Leave the Sonoff connected via the USB-TTL convert on the PC (unplug and plugin the USB to the computer once, so the Sonoff will reboot)
  2. Disconnect all jumperwires from the Sonogg and connect it to 230V.

Sonoff configuration

The Sonoff will create it’s own wifi network. Use your phone, tablet, wifi connection to connect to the “esp_0” network. In some cases the new wifi hotspot is not visible, a restart of the Sonoff the device is required. In my case, it’s a matter of reconnecting the USB-TTL device to the pc.

Start your browser on this device and go to a random webpage. Normally it will go directly to the start page of the ESP easy configuration. if not, go to http://192.168.4.1, which is the default page.

Here the available wifi networks are displayed and you have to select your wifi network and add your own wifi password.

Click Save.

The Sonoff will reboot and get an ip address from your router. The same webpage will show you the new ip address of the Sonoff. The device (phone, tablet) will disconnect automatically,

Open the ip address of the Sonoff in your web browser.

On the same website as were you have downloaded the firmware (http://www.letscontrolit.com/wiki/index.php/ESPEasy), you have a tuturial what you can do in it’s setup, but the tutorial below will explain the minimum but necessary configuration.

 

Basic config

In the next steps, the basic necessary steps are showed, and how to switch the Sonoff via http commands.

Go to tab “Devices”, you will notice all Tasks are empty.

Click on the first “Edit” button at the first Task (1):

sonoff-devices0

Enter the details below as displayed.

Note: Name can be changed into any name, but you need this name later in a script.

When Ready, Press Submit and Close. The settings are saved now.

Sonoff-devices2

The Task is now created as shown below:

Sonoff-devices1

Rules

To use tab “Rules”, we need to first activate this option.

Go to tab “Tools” and scroll down to the setting “Rules” and select the checkbox as shown below:

rules0

Click at the bottom of the page on “Submit”. You will notice that the tab “Rules” will become visible.

 

Scripts

Go to tab “Rules”. Here we will define a script, so we can call it via a http command.

A script could be like:

Note: On “name”, this will be called as Event name in the http command.

On TurnOn do
gpio,12,1
EndOn
On TurnOff do
gpio,12,0
EndOn
  • The http command to switch the Sonoff to On will be: http://<ip-of-Sonoff>/control?cmd=event,TurnOn
  • The http command to switch the Sonoff to Off will be: http://<ip-of-Sonoff>/control?cmd=event,TurnOff

Or if you just want to have a toggle switch:

Notes:

  • “switchsonoff1” is the name of the script, which will be called via the http command below.
  • “relais” is the name of the switch, which is used in the Devices tab, at the earlier created Task1.
On switchsonoff1 do
if [relais#Switch]=1
gpio,12,0
else
gpio,12,1
endif
EndOn

The http command to switch the Sonoff on/off, will be: http://<ip-of-Sonoff>/control?cmd=event,switchsonoff1

You can have mutiple scripts in the same Rules tab.

Specifications

sonoff-parts-without-433

 

  • Voltage range: 90-250v AC(50/60Hz)
  • Max current: 10A
  • Max Wattage: 2200 watts
  • Dimensions: (L)88*(W)38*(H)23mm
  • Color: White
  • Humidity: 5%-95%
  • Wireless Frequency: 2.4Ghz
  • Working Temp: ﹣20℃-75℃

Link to datasheet: http://dl.itead.cc/IM151116002/0A-ESP8266_Specifications_v4.1.pdf

************** Update 15-02-2017 **************

Activate led

Select in tab “Hardware” at “Wifi Status Led” from the dropdown menu the option “GPIO-13”.

sonoff-led

Activate physical button

To control the Sonoff via the black button on top of the case, add the following configuration:

Add a new device via tab “Devices”, with the following parameters:

(The IDX/Var could be any digit)

Sonoff-button1

In tab “Rules”, add the following script:

Notes:

  • “button” is the name of the task, which is created in tab “Devices”
  • “state” is the value name in the created task.
on button#state do
if [button#state]=0
gpio,12,0
gpio,13,1
else
gpio,12,1
gpio,13,0
endif
endon

When pressing the button on the Sonoff, the internal relais will be controlled, including the led.

Example: When the light is switched on (=GPIO 12), the led(=GPIO13) will be switched on too (green color).

 

Privacy Preference Center