Using a Raspberry Pi to control Maplin power sockets

remote-controlled-mains-socket-set-singleFor a while now I’ve been intrigued by the idea of home automation, but despite a large amount of research I’ve yet to take the plunge and buy anything. The one thing I do have is a bunch of these Maplin remote control sockets. These are simple things which just plug into any wall socket, then have a socket which you can plug any device into, a simple RF remote offers 8 buttons, on and off for each of the four sockets. The remote lets you choose from one of four channels meaning you can have four sets of four remotes all working within range of one another. I bought these originally because we had a few power sockets in awkward to reach places – who wants to move the sofa every time you want to turn a light on? – but never considered the possibility of using a computer to  control them.

That was however, until I spotted a intriguing sounding tweet from Chris Swan directed at Andy Stanford-Clark:

Oh really Mr. Swan, now this does sound very interesting. I asked for some details and Chris pointed me at this blog post which explains pretty much everything I needed to know. The post linked to this library from Duncan McGregor which did the hard work and linked to the source of the transmitter I would need. Sorted then, this sounded simple enough!

10534-01aI bought one of the transmitters and a ribbon cable with a plug that fitted the GPIO connector of the Pi. I planned to snip all but three cables from the ribbon, shorten the remaining ones and solder these to the 3 pins on the TX, the hope was with a very short wire from the GPIO plug to the TX I’d be able to hide it inside my existing case. The pin out of the GPIO and the connections you need to make are listed on Duncan GitHub repo in the Readme. But in short it goes like this:




Tx PinRaspberry Pi Header Pin
Pin 1 GNDPin 6 0V (Ground)
Pin 2 Data inPin 11 GPIO 0
Pin 3 VccPin 2 5.0 VDC Power
Pin 4 ANT173mm antenna wire (not on the Pi!)

Once I’d soldered the connections, I plugged the ribbon cable onto the GPIO and booted the Pi. One quick clone of Duncans repo later and I ran the following:

sudo ./ --channel 1 --button 2 --gpio 0 on

And hey presto my fish tank light turned on. *minor celebration* 🙂

I wanted to try and avoid sudo access, but reading a few, things, decided that sudo was probably safest! So be it.

I’m pretty terrible at remembering that the fish tank lights are channel 1, button 2 so I wrote a short python script which accepts room names and a simple on or off:

It essentially just uses a Python dictionary to store the room to channel and button mapping:

switches = {
'bookshelf': { 'channel' : 4, 'button' : 1 },
'tank':      { 'channel' : 4, 'button' : 2 },
'sofa':      { 'channel' : 4, 'button' : 3 },
'outside':   { 'channel' : 4, 'button' : 4 },
'spareroom': { 'channel' : 3, 'button' : 1 },
'all' :      True

I’ve put this script ‘’ into a repo in my Github account here. You run it like this:

./ -s tank -a on

The success of all this lead me to consider actually building a remote control for these things that I could use on my phone, partly because it sounded like a neat thing to do and partly because finding the remote when the kids have been using it is non-trivial.  The added, actually useful feature would be to turn lights off remotely when I go out and forget to turn them off.

So I pondered for a bit and sketched out a plan for a simple HTML UI running on a web server, somehow talking to the Pi to do the work.   I didn’t want to expose the Pi to the internet because I already have a Linux box with a public IP and apache running on it and didn’t want two entry points into the house.  I just needed a way of getting a command from a client browser, via the other linux box and onto the Pi.  Then it dawned on me, I already use Mosquitto, the open source MQTT broker for moving temperature readings around, I could just use that.  A bit more hacking lead me to write which is a variation of and simply subscribes to the MQTT broker and listens for messages containing commands.

I wrote it to expect JSON messages in the following format:

{ "channel": 3,"button": 2,"action": "off"}

Testing this is as simple as using the command line MQTT publish client:

% mosquitto_pub -h trin -t foo/bar -m '{"action": "off", "switch": "spareroom"}'

So now I just had to write a simple web UI which could publish messages of the correct format. I’ll write about that at another time because I hit upon something which changed my plans slightly 🙂

4 thoughts on “Using a Raspberry Pi to control Maplin power sockets

  1. Steve

    I looked at hacking these. The chipset in them (SC5272 / SC5262) is pretty simple to work with, but limited as it really only wants to encode an array of switches, and the Maplin plugs run out of addressibility when you have 16 of them. Sure you can fake this out with some gpio but it’s clunky.

    An alternative hack that I have done is to replace the little pcb inside the Maplin plugs with a home-brew one that supports an ESP8266 and made them wifi connected. That way you get full MQTT support and your (hacked) Maplin plug can now be controlled from Node Red. (And you could support as many as your DHCP server will serve…)
    The Maplin plug is a handy case for the mains pins and socket. The relay, inrush limit resistor and thermal fuse get used on the new pcb. I had to beef up the power supply a bit (0.68u cap rather than 0.47u) in order to supply both the relay and a ROF78E3.3 for the ESP power. I added a temperature probe, ambient light level detector and a footprint for an optional humidity sensor too.
    I have a dozen of these running round the house.

  2. Gareth

    I wonder is Steve has blogged about how he’s used the esp8266, with a bit more detail for us mere mortals to use…??

  3. Jeremy Bullock

    I’ve set these up for my Raspi and here is the code logic:

    The 25 character string is formed of 3 parts – The channel (I – IV), the socket number (1-4) and the Status (On – Off). The codes below works for all the possible permutations.

    Channel Binary
    I 111010101
    II 101110101
    III 101110101
    IV 101010111

    Number Binary
    1 11010101
    2 01110101
    3 11010101
    4 01010111

    State Binary
    On 01010101
    Off 01010111

  4. Roger Beal

    I have 15 of these sockets that I want to sell if anybody is still interested in this project since Maplin closed down. Sorry, in advance, if this is an inappropriate post.

Leave a Reply

Your email address will not be published. Required fields are marked *