Here are two similar but also rather different WiFi controlled mains switching relay modules that both use the ESP8266 WiFi SoC. Both come with a nice case, can be reprogrammed with your own firmware and are exceedingly cheap for what you get.

I’m using these with MQTT and Node-RED so that they seamlessly integrate with the other WiFi and 433MHz remote mains devices that I already have. In day to day use there will be no way to tell which type of device is controlling a particular light or appliance which is just how it should be.

Itead Sonoff

The first is the Itead Sonoff which I’ve had for a while now and has been well covered elsewhere, this board comes in two flavours, with and without a 433MHz receiver. The one I have is without.

The Sonoff is designed to be used with Itead’s own mobile app but can easily be flashed with other firmware if you solder some headers on or use pogo pins to connect to the power and serial pads on the board. It’s a fully customised board with the ESP8266 chip integrated onto the PCB (not using a module) and has 1MB flash.

GPIO usage:

The relay is on GPIO12, active high
The green LED is on GPIO13, active low
The push button is on GPIO0*

I like this board, it’s all integrated on the one PCB, the isolation looks reasonable, the AC tracks are thick and/or have additional solder applied to increase the current handling capacity, there is a MOV for over voltage protection and it all looks well made. Itead state the max load is 10A and that seems reasonable.

Itead also make an E27 light bulb adapter called Slampher which uses a similar board but I haven’t tried one of those.

Electrodragon WiFi IoT Relay Board

The second board is a new one from Electrodragon. This has two independent relays compared to the one in the Sonoff and comes with headers already soldered on for programming. It only has the standard AT firmware loaded so reprogramming will be a must for anyone using these units.

Unlike the Sonoff which integrates everything onto the PCB the Electrodragon board uses a standard ESP-12F (4MB flash) module and a separate AC to 5V module (feeding an AMS1117 regulator to produce the 3v3). One advantage to this design is that by removing the power module and bridging the inputs and outputs for it, it would be easy to convert this into a low voltage relay board which might not be a bad idea.

Electrodragon don’t explicitly state the maximum current that their board can handle, only quoting the spec of the relays (10A @250V) but the long tracks down the side of the board don’t look anywhere near heavy enough to handle 20A (10A per relay) and I’d only be confident using this for low current applications.

Personally I’d also like to see a bit more isolation in a couple of places too (input to power module and output from one of the relays to the ground pour) but I’m not an expert on this and it might be acceptable. The build quality of the power module isn’t great either (see below).

One definite design problem with this module is that the case was clearly only ever designed for one pair of terminals at each end and they have tried to cram two sets in for the output of the two relays resulting in one that is partially obstructed potentially leading to crushing and disconnection or worse, shorting. There is no way that cover would go on with two sets of cables either and I’d not be happy using both outputs without modding the case.

Electrodragon relay module cable exit

Also on the board are two miniature push buttons connected to GPIO0 (for flashing) and GPIO2 and three on board LEDs (one for each relay and one connected to GPIO16) but none of these are accessible from outside the case.

There is also a footprint for a DHT11/22 temperature & humidity sensor but I’m not sure how useful this would be as mounting the sensor directly on the PCB won’t be much use inside the (unvented) case and right next to the power module and 3v3 regulator where it is going to be affected by circuit heat. I did wonder if the intention here was to monitor for over temperature situations but you wouldn’t use a DHT for that. Still, it is another easily accessible GPIO if nothing else and the sensor could be connected on leads and placed outside the case I suppose.

GPIO Usage:

Relay 1 is on GPIO13, active high
Relay 2 is on GPIO12, active high
The user LED is on GPIO16, active high
BTN1 is on GPIO2
BTN2 is on GPIO0
DHT sensor is on GPIO14

Programming Pinout:

The header is pre-populated and labelled on the PCB, it gives access to power and serial as well as access to several more GPIO pins and the ADC.
Helpfully the pins are labelled and give access to:

I’m not really as keen on this board, some design decisions that seem a bit odd to me and I do wonder if they have just added the second relay in an attempt to “one up” the Sonoff. There is some potential there though, the access to the extra GPIO pins and the modability for low voltage use are plus points.

Here are the boards from both units, the green one is the Sonoff, red is the Electrodragon.

MQTT Firmware options

As my home automation is all MQTT based all I am interested in is being able to turn the relay on/off via MQTT. Initially I was going to use a simple version of my own then I came across this from Theo Arends on Github which is available in both native C and Arduino flavours and supports OTA updates which is a very nice feature to have.

What I am actually using at the moment is ESPEasy, this has a wealth of features built in and supports GPIO control via MQTT or a REST interface and supports lots of sensor devices and is all configurable through a web interface including OTA updates. As the name suggests it is very easy to use.

Once you have a USB to TTL converter attached programming either of these modules is as straightforward as with any ESP8266 device, hopefully it should be obvious that the AC should not be connected while messing around with these things like this or things won’t go well!

Power up while holding down the button (Sonoff) or BTN2 (Electrodragon) and the ESP8266 will go into programming mode.

I use esptool.py so uploading is something like:esptool.py –port /dev/ttyUSB1 write_flash 0x00000 ESPEasy_R78_512.bin

Once flashed, power cycle the device and check for a new wireless access point named ESP_0, connect to that and then browse for any web page and you should be redirected to the setup page (or just enter http://192.168.4.1) which will list nearby WiFi networks, select the one you want to use, enter the password and click connect. The device will restart and then show you its IP address on the network you just selected.

Back on your WiFi network, connect to the new IP address for the device and you will get the System Info screen, click Config and on that screen you need to set the following at a minimum:

Name: eg. sonoff1

Unit nr: This must be unique to the device

Protocol: Select OpenHAB MQTT (this is just standard MQTT, it doesn’t matter if you aren’t using OpenHAB)

Controller IP: Set to your MQTT broker address

Set port,user,password if required for your broker

Now go to Tools, Advanced and set: the Subscribe Template to the the topic you want to use to control the device, eg. %sysname%/# where %sysname% gets replaced with the name you entered in the config page.
Not necessary if you are not using any sensors etc. but you can also change the Publish Template to set the topic for information coming back from the device.

Sending Commands

You can now control the device via MQTT, for example you can set GPIO 12 high (turns the Sonoff relay on) by sending a message of 1 to the topic sonoff1/gpio/12 or set it low by sending message of 0

If you don’t speak MQTT you can use the equivalent REST interface like this: http://sonoff1/control?cmd=GPIO,12,1

So two very useful and very cheap boards, for the reasons mentioned above I prefer the Sonoff but both boards seem to be reliable so far and I can see more being deployed here. I’ve not fully explored the sensor side of ESPEasy yet but what I have seen so far is very impressive, definitely one to watch.

Interesting, looks like a big improvement in board layout plus the addition of a MOV and is that a PTC? Revised 5A rating with new relays a lot more reasonable, esp given the thicker tracks.

From the pics it looks like there was also an intermediate version with thicker AC tracks but still with the Songle relays. Don’t know about the Hongfa relays v the Songles, never had a problem with the latter and they are very common in all kinds of equipment.

Glad to see they are still working on improving it, much happier with the new design base on the photos. Now they just need to find a case that actually has proper outlets for all the terminals!

I have a few of the intermediate boards (thick tracks and songle relays) and they have a horrible flaw: a resistor on the mains line (right after the header block) which burns out as soon as you power even a light load across the relay 🙁

After a good email exchange with electrodragon, it looks like a 60W load (a 0.5A fan@120V) is too much for the fusible resistor on my particular board revision which seems wrong.
They will be sending me new boards with better components which should address the issue.

I’m just having a nightmare with both of these boards, trying to get anything beyond a simple “println” sketch. I can upload various example sketches which by all means SHOULD work, and do work on NodeMCU V3 boards, but I just can’t get anything to go in the terminal except the 3 characters of garbage. I’ve read all about the power issues, and have a bench power supply providing 3.3v, but it still just seems to reset (I can’t see the serial output with the bench power supply plugged in I don’t think?). I’m wondering if you can provide any guidance on what I could do here?

With the electrodragon, I just get nothing in the terminal when powering by usb, and when powering by the bench supply I see the blue light on the esp8266 flash every 10 seconds, along with the status LED, and the power draw increases from ~0.06A to ~0.1A which I’m taking to be a reset.

How did you power your devices when testing, via mains, USB or other power supply?

I’m losing my mind a little on this – have had about 4 attempts over the last month.

Hi Nathan,
Great article, I am also running MQTT at home, with my own firmware over OTA on the Electrodragon boards. I do have a question, I uploaded the firmware by connecting the pins and since I am used to doing this only the first time I installed the Electrodragon boards in a difficult to reach place. Afterwards I wanted to add another feature to the firmware but I don’t seem to be able to program them via OTA. The authentication works but the upload doesn’t. Do you have experience with ArduinoOTA and the Electrodragon boards ? Is it because their flash button needs to be pressed ?
Thanks.
Vincent