ESPurna smart socket

After a busy month I decided to spend some energy on doing hardware instead of software and the result was the ESPurna board I posted about just yesterday. The goal was to have a device based on the ESP8266 I could fit into my house wall gangs, with an SPDT relay to work with multi-way switches and power monitoring using the same IC the Sonoff POW uses: the HLW8012.

As a side project today I’ve been searching on the box of the TODO projects and I have rescued a KEMO STG15 [Ebay] plug housing with socket. These sockets are somewhat expensive and really bulky but the good thing is that there is quite some room to fit some electronics inside, but not a Sonoff board, too big.

But, what about an ESPurna board?


ESPurna inside

The ESPurna-H board is released under the Creative Commons Attribution-ShareAlike 3.0 Unported License (CC-BY-SA 3.0) and follows the terms of the OSHW (Open-source hardware) Statement of Principles 1.0. It can be checked out at my ESPurna board repository on Github.

The socket has some placeholders to screw a board inside, but the form factor does not match that of the ESPurna board. They draw a rectangle of 52x34mm while the ESPurna board has holes disposed in a square of 44x44mm. Then I thought about hot-gluing the board somehow. Problem is that the HLK-PM01 gets hot when operating and didn’t feel hot gluing was a good idea.

Then I started thinking about the ventilation dents on the sides of the socket. From the inside they look like rack slots with 6mm step between them. Maybe I could rack the board there? The ESPurna board is 50mm width. I needed around 60mm to rack it in both sides of the socket so I cut an adaptor from a piece of methacrylate of 60x50mm with holes for the ESPurna board.

The 2mm width plastic sheet fits tight in the vents. There is still room to let the air flow and even to add a case mounted push button and a notification LED. Finally I did add some hot glue on these two to prevent the cables to come loose inside the box.



The ESPurna board, fully populated with the methacrylate adator behind.


Connections to the push button and LED. I hot-glued them to prevent the cables to come loose inside the case.


The adaptor fits nicely inside the KEMO STG15 between the side vents. You can also see the hot glued contacts for the push button and the LED.


All connections made. Ground to ground (yellow-green), neutrals connected to both N terminals in the ESPurna board (blue) and the power line to the NO terminal of the relay (brown).

Final result

The final result looks quite nice. Not as slim as the Itead Studio S20 but this one has power monitoring capabilities and flashed with the ESPurna firmware it supports MQTT and Alexa amongst other goodies.


Now it’s time to play with it. I’ve been monitoring my house power consumption for a few years already, now I have the tool to do it for each appliance and manage them remotely from my cellphone or from Node-RED based on different inputs.

CC BY-SA 4.0 ESPurna smart socket by Tinkerman is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

18 thoughts on “ESPurna smart socket

    1. Xose Pérez Post author

      It doesn’t look like having an ESP8266 inside, so I’m afraid it’s not compatible…

  1. Ayre Neek

    Great post. I was also working on a small form factor design that is capable of being fitted into a single gang wall outlet. Would you recommend the use of this design for such a situation?

    1. Xose Pérez Post author

      A would probably change a few things for the next iteration. I’d like to find a way to place the ESP12 antenna further from the mains transformer. Maybe also trying the ACS712 as current sensor (better isolation, but only current monitoring so no active power calculation) and smaller SSR, enough to switch lights.

      1. Ayre Neek

        Thanks for your reply. Could you comment on the use of a transformer-less power supply to reduce the footprint of the board.

        1. Xose Pérez Post author

          It would be smaller but not that much. After all you need a big X capacitor for the step down and another big one for the filtering. This time my bet has been to not reinvent the wheel and use a trusted transformer.

  2. Owen

    Hi Xose,
    Nice design.
    I’ve been looking for something to do this type of thing for many years (X10 and the like), and it seems that now things are starting to get there without a stupidly large price tag. I tried some dedicated RF switches, but they were unreliable, and sat on the face side of the outlet (not behind the wall).
    I have an application (want/wish) to mount these to the *rear* of Australian power outlets to provide a means of control over appliances, some of which might be plugged in behind cabinets and have no easy switch access, and others where I might not want the appliance used (eg: TV in kids room is turned off – no matter what – at 8pm). Power monitoring is an added bonus!
    I would be interested in discussing further how this would fit to the inside-wall-side of Australian outlets. Fitting new outlets is not a problem, but I would like to make minimal outlet modifications and still maintain a high degree of safety… having a heat-shrunk lump in-line with the outlet (even inside the wall) is not only untidy, but would probably violate some regulations as well.
    I assume your software (espurna?) can control these direct over WiFi (eg: direct from a smart phone) and not require an internet connection (or phone connection) to operate?

    1. Xose Pérez Post author

      Yes, it’s getting more and more accessible for anyone to DIY her own’s smart switches. Some companies (mainly chinese) are pushing down really hard in the price but still most of the companies in the market offer end-to-end solutions, which might fit most users needs. If you really want to own a device you either need an open API or a custom firmware (ESPurna is one of them for ESP8266 devices, there are other options as well). Or you can create your own hardware. Price-wise you cannot beat the chinese ones.

      And yes, ESPurna lets you control your devices using WIFI, either through the embedded web interface, via MQTT (Node-RED, Domoticz, Home Assistant,…) or using custom server-side components (that can talk MQTT or REST).

      1. Owen

        I am wary about all Chinese ‘devices’ sold on the cheap (eg: eBay), particularly when they involve mains or batteries. I no longer buy such products after seeing so many dangerous examples – some which just went direct to the bin rather than risk life/property.
        Chinese devices sold through Australian retailers will *likely* have gone through some sort of accreditation process, so I will buy that stuff – if it can be found. In a lot of cases, the ‘cheap’ stuff is not available because it simply will not pass proper inspection.

        In a nutshell, price is important, but safety is much more important!

        With regard to your design, I can’t see any links to parts/assemblies. Is it available as a kit? Blank PCB? CAD files only?

        1. Xose Pérez Post author

          You are right safety goes first. If you are not confident about a design just don’t do it.
          Everything about the ESPurna board project is open source, but I’m not selling it, neither as product, nor as a kit or the PCB alone. The later you can buy it from OSH Park.

  3. Roman Mikulka

    hello, have you any idea why homeassistant spam log with warnings?
    WARNING (MainThread) [] Client esp8266a75d40 is reconnecting too quickly, make it wait

    by MAC address it is sonoff with latest ESPurna firmware. It is about twenty rows by one second and then it is okay for a while, after a few minutes it warns again…

  4. GNUtoo


    The ESPurna board looks really nice:
    – It can be integrated in a wall or in a standalone socket.
    – It can measure power consumption, if it is big enough:
    – It looks friendly to the free and open source community, and seem well supported.

    However it’s sad that no companies are selling CE/RHOS certified versions.
    As I understand, if I want something close to the ESPurna, but with some certifications, I’d need to reflash some commercial board.

    I also wondered if the ESP8266 or ESP32 can be used without relying on non-free libraries. As I understand, several toolchains are using some non-free libraries from the chip maker. states:
    “ESP8266 IoT SDK from Espressif Systems. This component is only partially open source, (some libraries are provided as binary blobs).


    1. Xose Pérez Post author

      Thank you, already working on a new version. But I’m not in a position to certify the board, so it will still be AS-IS and with extreme caution.
      As for the SDK, I’m not 100% sure about the state of the matter.

  5. Pingback: #Hack : Sonoff 4CH Pro avec le firmware MQTT Espurna, inclusion dans Domoticz (Partie 1 : installation d'une image pré-compilée) - Projets DIY - Domotique et objets connectés à faire soi-même

  6. GiovanniC

    hi, I have looked the project and schematic mainly for the HLW8012 chip which I can find very little docs around 🙁
    I’ve a question (if you tried): the chip datasheet assume Live and Neutral in a given connection (L-IN to pin 2, L-OUT to pin 3 and L (with voltage divider) to pin 4 of HLW8012) but as this plug when closed can be inserted in the wall outlet either way, will it function anyway? or will it not measure if “upside-down”? even worst can the PCB being damaged/burn/explode if plugged wrongly?
    Thanks for your feedback and by the way nice project 🙂

    1. Xose Pérez Post author

      I have connected either way without issues. My understanding is that the connection from the L-OUT to logical ground sets a reference potencial for the voltage monitoring, and that would do either way.


Leave a Reply (all comments are moderated, be patient)

This site uses Akismet to reduce spam. Learn how your comment data is processed.