ITEAD Sonoff switches and sockets - cheap ESP8266 Wifi+MQTT hardware

Tags: #<Tag:0x00007fd322072360> #<Tag:0x00007fd3220721f8> #<Tag:0x00007fd3220720b8>

( ) #1

ITEAD Smart Home Products

These very cheap modules come with their special smartphone app but are all actually based on the famous ESP8266. It didn’t take long till the tinkerer community got a hold of that and started hacking. After opening up the cases, all you need to do is solder a few header pins and connect your FTDI breakout programmer. Alternative firmwares are ready to provide nice MQTT based Wifi SmartHome endpoints without the need to either pay a lot of money, resort to special or propitiatory communication links or build open hardware from scratch.

What you’ll need

Firmware Flashing and Usage

I hate to repeat information :innocent: That’s why I added all instructions needed to get the Sonoff-Tasmota firmware onto your Sonoff modules and into your network in the project wiki, please check there for details:

The process is quite easy:

  1. Order whichever modules you want to use (obviously, check compatibility)
  2. Access the on-board serial interface (check the wiki Hardware section)
  3. Flash Sonoff-Tasmota via PlatformIO
  4. Connect to AC power
  5. Configure Wifi by using one of the provided configuration modes: Button Usage
  6. Connect to the device webpage
  7. Select the correct Sonoff module type from the configuration frontend
  8. Configure the MQTT broker connection, choose a unique topic, e.g. “sonoff-A00F9D”
  9. Test communication with the MQTT client of your choice (e.g. mqtt-spy)
  10. Integrate with openHAB!

openHAB Integration

The Sonoff modules with the Tasmota firmware will connect to your local Wifi and MQTT broker. If you do not already utilize an MQTT broker or are unaware of “MQTT”, please read up on that now.

The usage with openHAB is straight forward. Activate the MQTT binding and configure the connection details to your MQTT broker as described here, then define appropriate items linked to your desired MQTT topics (depends on module type). Examples:


//Sonoff Basic / Sonoff S20 Smart Socket
Switch LivingRoom_Corner_Light "Indirect Corner Light" <light> (LR,gLight)
    { mqtt=">[broker:cmnd/sonoff-A00F9D/power:command:*:default],
            <[broker:stat/sonoff-A00F9D/POWER:state:default]" }

//... please visit wiki for more ...

More examples for different Sonoff modules can be found at

Flashing in Progress

Flashing without soldering, using Pogo Pins (P75-LM2 / P75-LM2 or P75-T2):

Openhab with raspberry pi and Arduino using MQTT
Washing Machine State Machine
Zwave technology replacement
Itead wifi sockets
WiFi Relay
Washing Machine State Machine
Example step by step to add a hardware device to newly installed openhab2
MQTT Sonoff itead
Washing Machine State Machine
Sonoff Th16 Easyesp mqtt openhab2
Sonoff - basic question on flashing arendst firmware
New to openHAB, looking for suitable relays and sensors
Generic Wi-Fi plugs
Need Help in configuring Openhab to Tasmota Firmware Sonoff switch
Sonoff touch And Openhab
Xiaomi smart plug Without Hub
Help with configuration of mqtt using Sonoff switch with ESP Easy
Mosquitto errors
Smart socket recommendations
openHAB2 + Sonoff TH10 Tasmota Temperature problem
Items and things and MQTT April 2017
What dimmer switch for LED Bulbs (UK)?
openHAB zmote binding
How to connect generic PIRs to OpenHAB?
MQTT connection lost
Power outage
[SOLVED] MQTT for SONOFF/TASMOTA this is difficult
New to Openhab looking for info on reverse engineering?
What do these errors mean and how to fix?
ITEAD Sonoff Flashing Problems
Problem with MQTT & JSONPATH transformation
How to identify compatible hardware?
Washing Machine State Machine
Rule for SML Reader: iteration problem with HashMap
Zwave technology replacement
Please help! Generator integration with OH1.8.3?
Socket switch and power measurement
My new Smart Home Automation System with OpenHab2 - Work in progress
MQTT Binding (v1.11) Getting Started 101
Arduino Sonoff Binding
SonOff POW > Play Station > 120 mins
Newbie but willing - openhab with Sonos
Sonoff temperature configuration
How to create OH2 Item to send mqtt command to Sonoff 433 RF Bridge
Home renovation from Scratch
New in OpenHAB - Tasmota and RFLINK
Openhab with raspberry pi and Arduino using MQTT
How to build a WS2812B LED strip with ESP8266 NodeMCU?
Sonoff-Tasmota linking to openhab
Sonoff POW - How to read Voltage, Current, Power,
Receiving from MQTT
Refrigerator Temperature Sensors
Just Starting Looking For Ideas (NOOB) [SOLVED]
Simple Contact Closure Device Needed
Simple Contact Closure Device Needed
SOLVED: Sonoff 10A, MQTT and openHAB
How to convert MQTT into command?
[SOLVED] openHABian starting Mosquitto
Sonoff switch for including classic PIR in OpenHab
Inspiration needed for relays-controller
New Terrace - What Outdoor LED Spots and Driver / Controller should go with?
I'm starting my home automation project, but I need some advice
[SOLVED] Change the status of the mqtt switch
( ) #2


(Ben Jones) #3

Nice one @ThomDietrich - I have a few of the simple relay modules (Sonoff) running Homie all being controlled by openHAB. They are incredibly cheap and useful little devices. I see they have just released a new version of the relay module with energy monitoring as well!

Nice post BTW.

( ) #4

I decided to flash and recommend the (specialized) firmware by arendst but I also saw that Homie provides an example for the Sonoff. I’m using Homie for another application. Do you see any upsides in preferring it here?

Regarding the power measurement: Exactly. I’m pretty excited about them. I’ve ordered two of them and already contacted arendst to hopefully help to integrate it in his firmware.

Tutorial for openHAB Getting Started
(Ben Jones) #5

I haven’t tried arendst’s firmware so can’t comment on the pros/cons. I came across Homie early on and have been very happy with it, so never investigated any others. Great to have a few options however.

( ) #6

I tried arendst’s firmware and “have been very happy with it, so never investigated any others.” :stuck_out_tongue_winking_eye: Looking at the complexity in this device, I guess there is not much one can do wrong here. When time comes, maybe we can introduce power measurement into the Homie example as well.

Speaking about it, you know what you could do!? In the sake of open source, create a PR and correct the first line here :nerd:

( ) #7

One more question: which sketch are you actually using. I suspected the example but of course it could be your own. There is also this.

(Ben Jones) #8

Most of my sketches are here. Very simple, but that is the beauty of Homie - all the complicated connect/reconnect logic for WIFI/MQTT is done for you.

( ) #10

Hey Joe,
from what you are saying I think you will be quite happy with either the Sonoff or the S20 (more or less a Sonoff as a Socket Adapter). If you decide to go with the Sonoff, consider investing the few more Euros to get the Sonoff Pow - if you need it.
Before I go into detail: Of course there are other solutions out there. This solution is especially interesting as it is cheap and only relies on Wifi.

Sadly you are right with the conclusion that the linked tutorials are not too good. But let me assure you, the process is really simple/comprehensible. Here are the steps as I remember them:

  1. Open up the Itead module and solder the 4-5 pins to it. Minimal soldering experience, pins and jumper cables are required (have a look at the four pictures above) (If you have access to a soldering iron but neither pins nor jumper cables, you can solder wires onto the PCB and the Programmer… not recommended)

  2. Connect to the programmer as in the pictures. Be careful to not mix up the order

  3. Connect to PC via USB

  4. Install Arduino IDE and the needed libraries as described here. You can skip the second part beginning with “Install php…”

  5. Go to the main page and click “Clone or Download” -> “Download ZIP”. Extract and open the file sonoff/sonoff.ino with the Arduino IDE

  6. After the configuration in (4.) you should now be able to set up and then upload the program as described here

  7. After successful upload, reconnect the USB cable to reboot the device. After a few seconds it should be up and ready to connect to your Wifi. The default setting is to make a connection via WPS. Push the WPS button on your router and the device should connect and be visible in your routers list of devices (not tested by me),
    Alternatively, you can ask the device to create it’s own Wifi. As written here: “four short presses start Wifi manager providing an Access Point with IP address”. You can use your smartphone to connect to the wifi and browse
    There are a few more options. The obvious one would be to set your Wifi SSID and password in the file user_config.h before uploading. I did not follow that path as I plan to move my device to another Wifi soon and do not want to open and reprogram it every time…

  8. After everything went well and your module is connected to your wifi and got an IP address you can browse its web interface with all options and details.

  9. The big idea behind the “Sonoff-MQTT-OTA-Arduino” firmware is to provide MQTT capabilities. You should look into that. It’s a good way to go. I can not tell you for sure if you can switch the device by a simple HTTP request (and can not test right now) but that would be very easy to implement… I guess it’s in there :wink:

Good luck!

I wanted to answer here for others to find. If you have further questions you can not at all express in english, contact me via german PN.

( ) #12

Did you make sure to order a 3.3V one? This one has both 5.0 and 3.3, which is nice… it’s actually the one I own

(Seaside) #13

The Sonoff Pow still seem quite expensive, 24$ compared with Sonoff smart switch for around 5-8$ (Looking on ebay and aliexpress).

I guess they will drop in price when more are produced and it’s really new as well.
I have ordered two regular sonoffs, will look at Pow once they drop in price.

( ) #14

Update regarding the Sonoff Pow: the module is quite new and there was no firmware available yet. However arendt, the developer of the Sonoff alternative firmware, was amazingly quick and professional in adding support:

Regarding the price: Sellers on ebay and aliexpress are ripping you off on a new product. Go to the official store and you’ll see that they go for $10.50

( ) #16

It’s the very common size of 0.1" / 2,54mm pin headers. If you own some tinkering hardware like an Arduino or similar you should already have them lying around. You will also need jumper wires as seen in my pictures. The links are random examples… Good luck :wink:

(Lionello Marrelli) #17

Thank you for this very informative thread.
Itead is adding more cheap devices and I’ m wondering if they can be programmed in the same way as the other sonoff products treated in this thread. In particular, I’m referring to this one
Such a device should be useful for replacing a wall mounted thermostat that controls a gas boiler.

EDIT: I’ve seen that Arendst has written an experimental firmware for a similar product (

( ) #18

Itead provides a few great products indeed… This module is not supported directly but I can tell you that arendt is more than helpful in adding support for new modules, you just have to be ready to test. The other thing is that there is no picture of the bottom side nor are there schematics in the wiki. While it would be more than logical for this module to be based on the ESP8266 and thereby compatible with arendts firmware, I can not state for sure. You should just order one and find out :wink:

(Csongor Varga) #19

Hi All,

Has there been any development on this? I got my Sonoff from ebay, I flashed R120 of the ESP Easy firmware. I configured the devices and settings. But I cannot get it working. I mean it is not responding to the MQTT commands.
Does anyone have details on the the settings in the Device and Advanced menu? And how to publish commands in MQTT to turn the relay on and off?


(Michael) #20

Was trying to decide which technology (Z-wave etc.) to use but now I need look no further. Many thanks for pointing me towards these devices!

Received my first one this week and have just ordered two more. As I have used Arduinos/ESP8266s before it was easy for me to get it working using my own MQTT code (based on the MQTT/ESP8266 code you find with a google search).

The chip used is the same as the ESP-07 I’ve used and if the 433 module isn’t fitted, all the GPIOs should be available for other inputs and outputs if required. GPIO14 is the easiest to get access to and I have this working (pin 5 of the programming connector), GPIO0, 13 (LED) and 15 go to resistors so are solderable, GPIO2, 4 and 5 would require very delicate soldering so I won’t be touching these!


(Blair Thompson) #21

Talk me through what you have done…

Have you installed a broker (mosquitto perhaps)?
Have you installed the MQTT binding?
Have you configured the binding?
What does your items file look like?

from openhab.cfg

#################################   MQTT    ############################################



from my items file…

Switch	hallLamp	"Hall Lamp"	<light>	(hall)		{ mqtt=">[broker:/hallLamp/gpio/12:command:ON:1],>[broker:/hallLamp/gpio/12:command:OFF:0],<[broker:/hallLamp/lightState/Switch:command:ON:1],<[broker:/hallLamp/lightState/Switch:command:OFF:0]" }
Switch	hallLampState	"Hall Lamp"	<light>	(hall)		{ mqtt="<[broker:/hallLamp/lightState/Switch:command:ON:1],<[broker:/hallLamp/lightState/Switch:command:OFF:0]" }
Switch	bedroomLamp1	"Dresser Lamp"	<light>	(bedroom)		{ mqtt=">[broker:/bedroomLamp1/gpio/12:command:ON:1],>[broker:/bedroomLamp1/gpio/12:command:OFF:0],<[broker:/bedroomLamp1/lightState/Switch:command:ON:1],<[broker:/bedroomLamp1/lightState/Switch:command:OFF:0]" }
Switch	backroomDeskLamp	"Sideboard Lamp"	<light>	(lights,backroom_lights)		{ mqtt=">[broker:/backroomDeskLamp/gpio/12:command:ON:1],>[broker:/backroomDeskLamp/gpio/12:command:OFF:0],<[broker:/backroomDeskLamp/lightState/Switch:command:ON:1],<[broker:/backroomDeskLamp/lightState/Switch:command:OFF:0]" }
Switch	backroomDeskLampState	"Sideboard Lamp"	<light>	(family_rooom)		{ mqtt="<[broker:/backroomDeskLamp/lightState/Switch:command:ON:1],<[broker:/backroomDeskLamp/lightState/Switch:command:OFF:0]" }
Switch	backroomFloorLamp	"Floor Lamp"	<light>	(lights,backroom_lights)		{ mqtt=">[broker:/backroomFloorLamp/gpio/12:command:ON:1],>[broker:/backroomFloorLamp/gpio/12:command:OFF:0],<[broker:/backroomFloorLamp/lightState/Switch:command:ON:1],<[broker:/backroomFloorLamp/lightState/Switch:command:OFF:0]" }
Switch	backroomFloorLampState	"Floor Lamp"	<light>	(family_rooom)		{ mqtt="<[broker:/backroomFloorLamp/lightState/Switch:command:ON:1],<[broker:/backroomFloorLamp/lightState/Switch:command:OFF:0]" }
Switch	frontroomLamp1	"Squeeze Lamp"	<light>	(lights,frontroomLights,lounge)		{ mqtt=">[broker:/frontroomLamp1/gpio/12:command:ON:1],>[broker:/frontroomLamp1/gpio/12:command:OFF:0],<[broker:/frontroomLamp1/lightState/Switch:command:ON:1],<[broker:/frontroomLamp1/lightState/Switch:command:OFF:0]" }
Switch	frontroomLamp1State	"Squeeze Lamp"	<light>	(lounge)		{ mqtt="<[broker:/frontroomLamp1/lightState/Switch:command:ON:1],<[broker:/frontroomLamp1/lightState/Switch:command:OFF:0]" }
Switch	frontroomLamp2	"Lamp"	<light>	(lights,frontroomLights,lounge)		{ mqtt=">[broker:/frontroomLamp2/gpio/12:command:ON:1],>[broker:/frontroomLamp2/gpio/12:command:OFF:0],<[broker:/frontroomLamp2/lightState/Switch:command:ON:1],<[broker:/frontroomLamp2/lightState/Switch:command:OFF:0]" }
Switch	frontroomLamp2State	"Lamp"	<light>	(lounge)		{ mqtt="<[broker:/frontroomLamp2/lightState/Switch:command:ON:1],<[broker:/frontroomLamp2/lightState/Switch:command:OFF:0]" }
Number	backroomTemperature	"Family Room Temperature [%.1f °C]"	<temperature>	(family_room,Temperatures)		{ mqtt="<[broker:/backroomDeskLamp/environment/Temperature:state:default]" }
Number	backroomHumidity	"Humidity [%.1f %%]"	<climate>	(family_room,Sensor)		{ mqtt="<[broker:/backroomDeskLamp/environment/Humidity:state:default]" }
Switch	kitchenPIR	"Kitchen Motion Sensor"	<kitchen>	(Sensor)		{ mqtt="<[broker:/KitchenMood/pir/Switch:command:ON:1],<[broker:/KitchenMood/pir/Switch:command:OFF:0]" }
Switch	kitchenDownlights	"Kitchen Downlights"	<light>	(lights)		{ mqtt=">[broker:/KitchenMood/gpio/12:command:ON:1],>[broker:/KitchenMood/gpio/12:command:OFF:0]" }

from my rules

var Number counter = 0
var Number lastCheck = 0

rule "kitchenLightOn"
            Item kitchenPIR changed from OFF to ON
            counter = counter + 1
            //sendCommand(br_x10_lamp, ON)
            sendCommand(kitchenDownlights, ON)

rule "kitchenLightOff"
		Time cron "0 * * * * ?"
            if(lastCheck == counter) {
                    counter = 0
                    lastCheck = -1;
                    //sendCommand(br_x10_lamp, OFF)
                    sendCommand(kitchenPIR, OFF)
                	sendCommand(kitchenDownlights, OFF)
            } else {
                    lastCheck = counter

from the rules on the sonoff

on lightSwitch#Switch do
    if [lightState#Switch]=0
        Publish /backroomFloorLamp/gpio/12,1

        Publish /backroomFloorLamp/gpio/12,0

settings file for lamp

And in zip format Perhaps better

( ) #22

@Justblair, @Csongor_Varga are you sure you chose the right firmware? You should consider switching over to arendst very good Sonoff specific firmware…

(Michael) #23

I’m using a raspberry Pi2, with the latest Openhab2 and the Mosquitto broker. MQTT is installed using Paper Ui. There is nothing to configure other than the mqtt.cfg file:


In ‘items’ I currently have a simple switch:

Switch Light_Computer  "Security Light"    (gCR, Lights) {mqtt=">[mybroker:home/sonoff/1:command:ON:1],>[mybroker:home/sonoff/1:command:OFF:0]"}

I use MQTTLens (from Chrome) on my PC to test for MQTT messages.

I’m using the Arduino IDE ( with the ESP8266 Board Manager plug-in.

I agree with @ThomDietrich that those unfamiliar with ESP8266 programming should use specific firmware like arendst. I just like programming with Arduino/ESP8266 so use my own simple code.