Smart plugs (in the UK)

Sounds simple enough..  Get a smart plug in the UK that allows you to do the basic thing of switching something ON / OFF and vice-versa.

For once, I had a genuine requirement to do this - ah, ha! what is commonly known in the IT trade as a "business requirement"....that could then be technically fulfilled.

My requirement was simple: I have a solar panel setup (as you may have read about) and whilst I have an ATS (Automated Transfer Switch) in place, all this does it switch from the DC (battery) power over to the mains (240v) power when the battery power hits a low threshold and does the opposite when the battery hits a high threshold.  This will be great in the summer.  However, as it is kinda winter (okay, November, so close enough) we can have days of greyness and a severe lack of sunlight/daylight...and if the solar panels cannot re-charge the batteries, they are on a constant drain until they get below 12v and they are then defunct.  As a novel idea, I want to be able to re-charge the batteries when the ATS has switched over to 240v.  That's the requirement, took a while to get there, but get there we did.

Technical solution - hack the socket so that when the ATS switches over to the 240v it also turns on a ctek car battery charger and that will charge the batteries whilst on 240v.  sounded simple, until I then took a look at the way the wiring is setup.  There is ALWAYS a technical restriction of some sort.  Never simple.

What do I mean?  well, the 240v from the house is connected to a 2-way extension socket.  that extension socket has a light on it, so I know that the 240v is connected okay to my house, I did this for "debugging" purposes. Plugged into 1 of those sockets is a power meter, so that again, I can do "debugging" - it shows me 0w / 0amps when not in use and then shows me the 30watts on the screen to show me it is being used.


I have a plug that plugs in here and the other end has the 2-wires connected to the ATS device.  Then, when the ATS decides it wants power, it then "pulls" the power through the plug/socket and I see the numbers go up.  yay.  however, as I say, this just the one thing.  I did think abobut splitting the cable from the ATS to this socket plug, so that in theory when the ATS pulls from the 240v mains it would share that power with the ctek battery charger.  Even I thought this was a bit sketchy...even though I did purchase the components to make it happen, they are still sitting on the shelf.

So, what options were available to me?  Well, as I was in B&Q purchasing the above mentioned items, I noticed they had a "smart plug" on sale.  It was £20, now reduced to £8.  Why not throw one of those into the basket too....

I faffed about for a bit searching for open-source python code that could communicate with smart plugs, I found a few, but they were not correct for this type of plug.  What I didn't want to do, was the same as I complained about previously, I didn't want to have to download a custom phone app that then goes out to the internet just to be able to turn the plug ON or OFF.

I dicked around for a few days, trying out a few things...to no avail.  I even thought to capture traffic on the mobile phone and "see" what communications the custom app was doing.  I did discover that it was connecting itself to my home wifi, obtaining a valid local IP address, but it was also connecting to about 8 different IP addresses over the internet too.... hmmm... I also detected that it was using port 6668.  A quick nmap scan proved that was also true.  I used a couple of different apps on the phone to capture traffic packets and save them to pcap files for viewing later.  Scanning those I did see some hex/data being sent from the internet through my router and over to the smart plug on port 6668, I just couldn't really tell what the data was.  The amount of effort to potentially decrypt the content didn't match the desired result.  I did however find out that godaddy websites and certificates were being used in the equation - if I gave enough of a cr@p about this, I cold dig deeper and potentially crack this.  However, as I said, the "time invested versus reward" equation was unbalanced on this one.

I did plug the ctek charger into the smart plug and from my phone, I was able to turn it ON and OFF.. yay... look at me, doing "science".  This allowed me to charge the batteries for 3-4hours overnight to give them a little bit of a boost so they don't run flat.  

So, is the requirement met?  well...kind of. I can do the job.  But, from a technical perspective I think it sucks.  I don't want to have to use a custom app that goes out to the internet and back again to turn a switch ON and OFF again.

Open-source

What I was really wanting was an open-source hackable smart plug that works in the UK.  I set about doing a little bit of research....and being in the UK, it sucks.

I took a look at the Top 10 best smart plugs in the UK for 2022.  They all looked the same as the TCP Smart plug I already had.  Closed source...and I wanted:


I took a look at IoT recommendations


I started to notice a trend...a vast majority of the recommendations were for US 2-prong plugs, not UK.

Cloudfree looked really promising.. US only. :-( 


Then the TH3D smart plug - as used by lots of people along with 3D printers... US only :-(


Which led me to their GITHUB repo... which introduced me to the Tazmota website - at last an Open-Source protocol / firmware of sorts


Then I stumbled over some references to a UK company named Wifiplug.co.uk - I thought I was onto a winner there... the websit seemed to not be available, maybe that's a problem my end?

and then I did some further digging....

BUGGER :-(

... I was conceding that maybe I would just have to accept the usage of the TCP Smart plug for doing that single task...it just irks me that at any point in the future, just like wifiplug.co.uk, they could go bust, turn off their servers, or even decide to charge 50p per usage for the plug and I would have no option to go with it.  I don't like this being held to ransom by tech. companies approach.

...then I looked around my hoe / lab / office, whilst having a cup of tea.

I noticed I had an Arduino feather Huzzah ESP8266 WiFi board to hand - usage as yet unkown... I also had an 8-way relay module switch to hand - that I was using from the RPi to hack the controller of a small radio controlled tank...

...and my brain was thinking, hang on, the relay is controlled by GPIO pin code that switches ON and OFF when I want it to from code.  If I add that to my WiFi, I can then have something like a piece of code or node-red listening for a request to then perform that action and job done - a "smart plug".

I then doubted myself for a few minutes, thinking, hmmm... surely it cannot be that simple, surely there are complications that would result in the thing catching fire or something?...

Then I did a bit of searching and I found the following on Alibaba


Hmmm...I am usually suspicious of things being so cheap.  cheap usually means fire or failure.

However, good old AMAZON showed me that these things have already been cobbled together

1-piece smart plug make it yourself:


So, naturally, I bought the pack of 3:


This will require me to get the 3D printer dusted off and plugged back in, design and make up a few boxes for them to fit within, with enough ventilation / heat dissipation - may even make the boxes a lot larger than the units and add fans or something, that can be controlled by the ESP8266 GPIOs.

Then, I can do what I wanted to do all along.

I can, from my own code, send a signal over my home network to the device that will trigger the action of turning the relay ON or OFF.  Thereby resulting in turning the ctek battery charger on or off.

Requirement will be met and the technical solution will then be more to my liking.

I shall update my future progress, probably over the weekend as I need to figure out how to design / make stuff for the 3D printer!


Comments