The Dark Secret of Smart Sockets and How I Fixed it! (DIY or Buy)

**A Tale of Two Outlets: A DIY Smart Outlet Project**

As I embarked on a journey to create my own smart outlet, I couldn't help but wonder if I could make it better than the ones I've bought before. After all, who doesn't love tinkering with electronics and trying to push the boundaries of what's possible? In this article, I'll take you through the highs and lows of creating a DIY smart outlet, from the initial design to the final product.

**The Problem with AC Voltage and Current Measurement**

One of the biggest challenges I faced was how to measure the AC voltage and current safely. While it's possible to use a voltage divider and current shunt, this approach is not exactly safe as you could easily get shocked. To avoid that risk, I opted for a more traditional method using a voltage transformer and current transformer, which are galvanically isolated from the mains voltage.

**The Voltage Transformer: A Slightly Unconventional Choice**

I must admit that I was initially drawn to using a super small transformer that can produce a suitable lowered mains voltage for my IC. By attaching suitable resistors to its input and output side, as recommended in the datasheet, it became a viable option. On the other hand, the current transformer was relatively simple to use by hooking up one resistor across which I could measure the lowered AC current flowing through the wire.

**Adding a Resistor and Capacitor Network: A Necessary Evil**

At this point, I also added a rather complicated resistor and capacitor network to the voltage and current input of my IC as recommended in the datasheet. This was necessary to prevent value surges and get rid of unwanted frequencies. With this step complete, all that remained was programming my ESP through Home Assistant, which proved to be surprisingly easy.

**Fine-Tuning the Voltage and Current Gain Values**

The final step involved fine-tuning the voltage and current gain values in the code by comparing what values a cheap power meter spits out and what my ESP is producing. Once this was done, I was satisfied that the power measuring functionality seemed to work.

**A Word of Caution: Mains Voltage Safety**

I want to emphasize that we are dealing with mains voltage here, so if you're interested in replicating this project, please do so at your own risk.

**Why Not Test the Relay Functionality and 5V Power Supply?**

To be honest, I didn't test the relay functionality as well as the 5V power supply with my ESP because the complimentary components and circuits were relatively simple and straightforward. I decided to skip them and jump straight into Altium Designer Software to create the schematic.

**Creating a Schematic: The Easy Part**

Using the Library Loader add-on in Altium Designer Software made creating the schematic an absolute breeze. This allowed me to focus on designing a functional smart outlet without worrying about finding suitable components.

**Designing a PCB: A Bit of a Challenge**

After completing the schematic, I used the software to create a PCB design whose outline needed to be as wide as the buy socket but slightly longer due to more components. The reason for this was that I wanted to reuse the actual socket part of the buy version, which is something I couldn't make on my own.

**PCB Design Completion: A Satisfying Feeling**

After around 4 hours of working on the PCB design, I was pretty happy with it. Even the 3D model looked promising, which is why I continued by uploading my Gerber files to JLCPCB who offered me a fantastic price for the PCBs.

**The Prototype: A Few Design Mistakes**

Unfortunately, my first prototype had a few design mistakes. The footprint of the transformer was incorrect, and I messed up the orientation for the choke. Worst of all, I wired up the SPI pins of the power IC to the wrong pins on the ESP because I couldn't resist wiring up to the SPI terms.

**Fixing Design Mistakes: A Second Chance**

Despite these errors, my prototype still worked when it comes to the relay switching and partly the power measurement. I fixed those mentioned errors in the schematic and PCB design and got myself another round of PCBs.

**The Final Product: An Improved Smart Outlet**

After soldering all the SMD and THT components in place and uploading the final code, my smart outlet worked fine as well as the complete power measurement. The final touch involved designing an enclosure for my outlet, 3D printing it, securing the PCB with screws in there, mounting the socket with hot glue, soldering on all the wires, and finally closing it all up.

**A DIY or Buy Comparison**

To answer my DIY or Buy question, I created a little chart comparing both solutions. For me, DIY is the clear winner here, but then again, I can't tell you for sure how much better more pricey smart outlets would perform.

**Conclusion: A Smart Outlet Project Well Done**

And that's it! I made my own improved smart outlet that will hopefully last for a long time. It's been an enlightening experience to design and build something from scratch, and I'm proud of the final product. Who knows? Maybe you'll be inspired to create your own DIY project too!

WEBVTTKind: captionsLanguage: enWhat you just saw was a relay that closedand opened its contacts and through whichthe maximum allowed current flowed.And since no contacts close perfectly withouta bit of bouncing around, you got yourselfsome sparks.Now I think everyone can guess that thosesparks are not good for the relay.And yes; they do not only destroy the contactmaterial, but sooner or later they will weldthem together so that the contacts can notopen anymore when unpowering the relay.And only a well placed smack can separatethem once again.This occurrence is called relay sticking andI hate it because the relay which I used asa test subject here is actually from a wirelesssocket that I have been using for a while.Such sockets are great for properly disconnectingyour appliances from the grid and thus gettingrid of the standby current.But so far in my life I tried 3 differentwireless socket sets which all eventuallyfailed due to this relay sticking.That means it is finally time for me to comeup with a solution which yes does exist.And while I was already tinkering with wirelesssockets, I thought why not create the ultimatesmart outlet that comes with tons of modificationsand extra features.So in this episode of DIY or Buy let's doexactly that in order to find out whetherI should simply accept the faults of the commercialversion or switch over to a DIY solution.Let's get started!This video is sponsored by the Altium DesignerSoftware and JLCPCB.They are a wonderful combination when it comesto designing your custom PCB and then actuallyordering them.But more about them later during the video.First off why don't we have a closer lookat the buy socket relay and its datasheet,maybe we can find something suspicious.But no; it only tells us nicely all the juicycurrent and voltage details without offeringa clue why the sticking occurs.So I had to investigate on my own by simplyadding a low resistance current shunt in seriesto the main current path in order to properlymeasure how much current was actually flowing.And as you can see we got a short currentpeak here with a value of 13.3V which convertedinto amps is around 53.2A.That is way above the maximum current ratingof the relay and is definitely the reasonwhy the sparks are so powerful that they caneasily weld the contacts together.Now you might be saying though this currentpeak only occurred because I shorted a labbench power supply with tons of capacitorson its output.And yes that is partly true; but when usingthe relay for AC appliances that you can geta similar short current peak as well becauseall your connected appliances also want toquickly charge up their internal capacitors.So what we need to solve this problem is arelay that can handle a big inrush currentand that is exactly what I searched for nexton the internet and I quickly found out thatthe contact material plays a major role here.In the case of the buy socket relay it isa Silver alloy which is common for generalapplication relays.But we want is either Silver Tin Oxide orSilver Cadmium Oxide as the material becausethey are more resistant to the welding athigh current peaks.So I searched for a while on Mouser to finda suitable relay and I think this one shoulddo the trick.It comes with the desired Silver Tin Oxide,features a rated switching current of 30Aand a relay voltage of 5V is possible.So needless to say I got myself some of themand immediately opened one up to repeat thesame experiment as before.Now as expected the arcs were still presentbut way less noticeable and during my testingsession I never got the relay to stick.The contacts of course also suffered a bitbut way less than the other relay.And that basically means that such a relaycan be a solution to the sticking problemand what bothers me the most here is thatthe high inrush current relay only cost 2€more than the general purpose one.Meaning that if they would use such relaysfrom the start they could extend the lifetimeof their product and thus produce less electronicswaste; but of course that would also reducetheir profit.But anyway at this point we could simply replacethe relay in the buy socket and be done here.But since that would be not a very safe electronicsjob, I instead decided to make my own smartoutlet.To improve it even further I firstly wantedto get away from the capacitive dropper powersupply the old socket featured and insteadutilize such a small enclosed 5V power supply.Also I wanted to add an ESP8266 with WiFicapability to the system to not only easilyreprogram it but also to make it compatiblewith my HomeAssistant system about which youcan learn all about in one of my previousvideos.Last but not least I wanted to include a powermeasurement IC that measures the AC voltageand current and then calculates the real powerI am currently using.So my initial goals were set for me and Ithink not half bad but getting it all to workin the end was not that easy.To start off though; I searched for a suitablepower measurement IC and found this CS5460Aone which is not only supported by HomeAssistantbut also comes as a breakout board.So after receiving one, I positioned it onthe breadboard along with an ESP and connectedthem according to this schematic so that theycan talk to one another through SPI.That was pretty simple to do but what wasa bit more complicated was how to measurethe AC voltage and current.There is of course the same potential methodby using a voltage divider for the voltageand a current shunt for the current but thismethod is obviously not that safe becauseyou could more easily get shocked.To avoid that I instead went with a voltagetransformer and current transformer approachwhich are galvanically isolated to the mainsvoltage making them more safe.But what I didn't like was the big size ofthe voltage transformer as well as its distortionsit was adding to the lowered mains voltage.So I searched for an alternative for thatand discovered this super small transformerwhich by attaching suitable resistors to itsinput and output side like its datasheet recommendsit, can easily produce a suitable loweredmains voltage for the IC.The current transformer by the way was evensimpler to use by only hooking up one resistorto it, across which we can then measure thelowered AC current flowing through the wire.Now at this point I also added a rather complicatedresistor and capacitor network to the voltageand current input of the IC like the datasheetrecommend it to prevent value surges as wellas getting rid of unwanted frequencies.With this step complete all that was leftto do was programming the ESP through HomeAssistantwhich was super easy to do and then fine adjustingthe voltage and current gain values in thecode by simply comparing what values a cheappower meter spits out and what the ESP spitsout.And just like that the power measuring functionalityseems to work but at this point I kind ofhave to warn you that we are dealing withmains voltage here so if you want to replicatethis project then it is at your own risk.But anyway, next I actually didn't test therelay functionality as well as the 5V powersupply with the ESP because the complimentarycomponents and circuits were so simple andstraightforward that I simply skipped themand instead directly jumped into the AltiumDesigner Software to create the schematic.I recently found out about its Library Loaderadd-on which make it even simpler than beforeto find the right components for your project.Because of that creating the schematic wasdone in a breeze and the only components hereI haven't mentioned before are a 3.3V regulatorto power the ESP and Power IC and two pushbuttons and a couple of resistors to laterlet the ESP enter programming mode so thatI can obviously program it.And with the schematic completed I used thesoftware to create a PCB design whose outlineneeded to be as wide as the buy socket buta bit longer due to more components.The reason why I used the same wideness isthat I wanted to reuse the actual socket partof the buy version because that is somethingI can not make on my own.And after around 4 hours of working on thePCB design I was pretty happy with it.Even the 3D model looked promising which iswhy I continued by uploading my Gerber filesto JLCPCB who offered me a fantastic pricefor the PCBs and while I was at it I alsoordered a stencil for the solder paste.After a week my PCBs and stencil arrived andsince its quality was like always pretty flawless,I was very excited to giving it all a try.But long story short I did make some designmistakes with those first PCBs.Not only was the footprint of the transformerincorrect, I also messed up the orientationfor the choke and worst off all wired up theSPI pins of the power IC to the wrong pinsof the ESP because I apparently couldn't resistwiring up to the SPI terms.In the end though I got my prototype to workwhen it comes to the relay switching and partlythe power measurement.So I fixed those mentioned errors in the schematicand PCB design and got myself another roundof PCBs.And after once again soldering all the SMDand THT components in place and uploadingthe final code it seems like the relay stillworked fine as well as this time also thecomplete power measurement.And that meant for the final touch I designedan enclosure for my outlet, 3D printed it,secured the PCB with screws in there, mountedthe socket with hot glue, soldered on allthe wires and finally closed it all up.And just like that I made my own improvedsmart outlet that will hopefully last fora whole lot longer.And to answer my DIY or Buy question I madethis little chart comparing both solutionsand for me DIY is the clear winner here butthen again I can not tell you for sure howmuch better more pricey smart outlets wouldperform.With that being said thanks for watching andif you enjoyed it then consider supportingme through Patreon.As always don't forget to like, share, subscribeand hit the notification bell.Stay creative and I will see you next time.