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

ITEAD Smart Home Products

https://www.itead.cc/wiki/Sonoff_Smart_Home_Solution

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.items:

//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 https://github.com/arendst/Sonoff-Tasmota/wiki/openHAB


Flashing in Progress

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

41 Likes

(reserved)

2 Likes

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.

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.

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.

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:

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.

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.

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 192.168.4.1”. You can use your smartphone to connect to the wifi and browse http://192.168.4.1
    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.

3 Likes

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

http://r.ebay.com/VsCj3w

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.

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 https://www.itead.cc/sonoff-pow.html

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:

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
https://www.itead.cc/smart-home/inching-self-locking-wifi-wireless-switch.html
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 (https://www.itead.cc/4-channel-wifi-wireless-switch.html)
https://github.com/arendst/Sonoff-MQTT-OTA-Arduino/issues/47

Hello!
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:

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?

Regards,
Csongor

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!

Mike

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    ############################################
mqtt:broker.url=tcp://localhost:1883
mqtt:broker.clientId=openhab
mqtt:broker.retain=true

mqtt-persistence:broker=broker
mqtt-persistence:topic=/uselessBox/%1$s
mqtt-persistence:message=%3$s

mqtt-eventbus:broker=broker
mqtt-eventbus:commandPublishTopic=/openHAB/out/${item}/command
mqtt-eventbus:stateSubscribeTopic=/openHAB/in/${item}/state

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"
    when   
            Item kitchenPIR changed from OFF to ON
    then   
            counter = counter + 1
            //sendCommand(br_x10_lamp, ON)
            sendCommand(kitchenDownlights, ON)
    end

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

from the rules on the sonoff

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

    else
        gpio,12,0
        Publish /backroomFloorLamp/gpio/12,0
    endif
endon

settings file for lamp

And in zip format Perhaps better

2 Likes

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

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:

mybroker.url=tcp://localhost:1883

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 (arduino.cc) 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.