A Smart Switch Board For The ESP8266

With a plethora of IoT projects and inexpensive commercial smart light fittings and mains switches appearing, you might be forgiven for thinking that another offering in this crowded marketplace would be superfluous. But there is always room for improvement in any field, and in this particular one [Xose Pérez] has done just that with his Espurna board.

This board is a very well executed ESP8266 mains relay, with an on-board mains power supply and power monitoring. It was designed with his Espurna (“Spark” in Catalan) custom firmware in mind, which offers support for Alexa, Domoticz, Home Assistant and anything that supports MQTT or HTTP REST APIs.

Best of all, it’s a piece of open source hardware, so you can download everything you need from his GitHub repository to create your own. For the ultimate in convenience you can even order the PCB ready-made from OSH Park.

As a demonstration of the Espurna board in a real application, he’s produced a smart socket project neatly enclosed in a wall-wart style box with an inbuilt Euro style plug and socket.

We’ve featured [Xose]’s work several times before here at Hackaday, he’s something of an IoT wizard. Most recently there was his work with Alexa and the ESP8266, but before that was his MQTT LED array for his laundry monitor.

20 thoughts on “A Smart Switch Board For The ESP8266

  1. Using an optocoupler to control a relay coil seems a bit pointless. If you need a relay with high-pot isolation (up to 2.5kV, or whatever standard) between the coil and the contacts then just buy an appropriate relay, and the relay serves as the isolation device.

    If an optocoupler is used to control the relay then you need two separate isolated power supplies, one on either side of the isolation barrier. If they’re just connected to the same power supply then there is no galvanic isolation – so what does it acheive? Where the energy-metering IC is referenced to the AC line it’s certainly not isolated at all.

    If you want part of the system to be isolated, it might be better to keep the optocoupler(s) after the energy metering IC, isolating the digital interface from there to the microcontroller, so the microcontroller isn’t at mains potential. Or consider energy metering ICs with built-in galvanic isolation, such as the Silicon Labs Si8901 or similar.

          1. No, you don’t.

            There isn’t even something as “approval for manufacturing” except your chosen manufacturer saying that he is able to build the device. So that your PCB is manufacturable with a given (supposedly cheap) technology.

            You need approvals and declaration of conformity and all that legal stuff, if you want to sell it. But you do not need any isolation between output and mains side to achieve this. Because the output relay is connected to the mains anyway. There was the same discussion about the Itead Sonoff Switch. Also if it’s supply has sufficient creepage distance. NO, it doesn’t, it doesn’t need it – because its output is connected to the mains input anyway.
            And a decent relay provides the necessary isolation if you need it and if your PCB design and your enclosure support it.

            Similar with a cheap 4 relay board from Aliexpress, which used optos. I just did not remove these completely useless part, because it just worked and was not worth the effort. But the grounds of both sides were connected together anyway.

  2. I too have often used an Opto as a level shifter. It is a convenient way to do it.
    But in this case I would have just driven the transistor (or a FET) directly.
    Maybe he wanted a logic inverter function too? There is certainly no isolation involved in the circuit as shown.

    1. It makes absolutely no sense to use an optocoupler as a level shifter if you are referring to the same ground. You can use a simple transistor.

      Judging by other weird things in the schematic, i would say the author has a few things to learn.

  3. I love using these big chunky overdesigned power supply modules, way better than some terrible wall wart waiting to give up the smoke. I usually accomplish this with similar components by stacking a few modular boards onto perf board and using Dupont jumper wires, not such a big deal as everything is one off inside a 3d printed case. But this is really nice fro a general purpose on-off gadget controller, I will have to grab a few of these Espurnas to try out.

  4. Am (somewhat) sorry for yet another compliance rant; but am old and cranky. You get to be old and cranky by either surviving stupid stuff or mitigating the stupid stuff.

    There are only three EU states that would allow this to be installed, even it if did meet BSI7671 or IEC60364, and the Low Voltage Directive – typically only Americans are free to putz with AC mains stuff, as it is our inalienable and constitutional right to be stupid. A big thing that would make this safe is an insulated/flame-rated enclosure, which the guy seems to have mitigated using the “wall switch base” per the web site.To his credit, he publishes some relevant disclaimers/warnings:
    – “This means that you should never ever connect the board to your computer while connected to mains. Never ever flash the board while connected to mains!”
    – “Please note that you will be using this board at your own risk. This product is meant to be plugged to mains and it requires a deep understanding of the perils of it. I disclaim any responsibility, risk, liability and damages arising out of death or personal injury resulting from assembly or operation of this product.”

    At first glance, a conformity assessment reveals:
    1. The MOV (varistor) is not properly rated per IEC61643-331 and 61051-2, which are normative references in both IEC/EN60950-1 and IEC/EN62368-1.
    2. The PCB material is not rated per DSR requirements.
    3. The terminal block is may not properly rated, but not certain.
    4. Component and PCB spacings do not meet material requirements for other than OV categories I and II.
    5. PCB not correctly marked.
    6. The cat and dog are bored with me sitting at the bench all day.

  5. another completely unrelated possible point of criticism would be the use of a non-latched (monostable) relay, depending on your application. It means that the relay coil will need to draw power continually (in this case: > 360mW, with margin probably more than half a Watt) for the contact to be closed. If you don’t care about that or if you KNOW in advance that the relay will stay switched off for the vast majority of the time, that may be fine. Otherwise anyone designing such a controlled relay board might want to consider a bistable (latching) relay that doesn’t draw current except during the short switching itself. but yeah, bistable relays do cost slightly more.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s