Article Image

One of my colleagues introduced me to the joys of simple home automation - a simple Sonoff device.  However after borrowing his and trying to use the provided Android app I found whilst it did everything I wanted from a hardware point of view (safely containing mains voltage) the software provided wasn't quite what I wanted.  By the time I've got my phone out, launched the app, connected to the Amazon cloud and pushed the button I might as well simply get up and flick the switch.

However all is not lost!  Opening up one of these revealed unpopulated headers nicely left by the manufacturer.  A quick bit of soldering and I had some pin headers connected, and my eagle eye spotted the easily programmable ESP8266 soldered on the back of the board.  With a handy USB FTDI chip hooked up I quickly realised I could flash my own firmware to it.  Woop!  So, on went a nice straight-forward NodeMCU firmware package with MQTT support (kudos to Frightanic for their seemless NodeMCU custom builder)

Pin headers in place

I spy ESP8266!

With a dozen lines of LUA I'm safely and remotely turning on/off mains voltage.  So, what next?

Of course I want to hook this up to my lights.  And lights have light switches.  Which in the UK are live and switched live only - preventing any kind of powered switch being used.  Sigh - this is going to get tricky.

But I realise ... the ESP8266 could work here too.  Cue a visit to AliExpress and I've ordered a bunch of resistors, battery clips and assorted electrical boards and bits for under a tenner delivered.  A simple circuit later I've got a chip less than 1" square with a surface mount button and attachment for ESP8266 - with the chip initially in its low power state and the button used to poke it into life.  I initially toyed with MQTT (again using the NodeMCU custom builder) but realised time is of the essence - simply put after testing I realised I want to push the button and have the lights toggle ASAP and loading MQTT took too long.  Instead I decided to write a server-side application (running on my home's Windows Server) using C# that takes simple HTTP requests and outputs MQTT messages.

My little switcher board


Well - there are numerous Android MQTT clients - this is good as I don't want to write applications unnecessarily.  This means my "proprietary" switches can boot up and send a single packet over HTTP really really quickly to the server which in turn sends an MQTT message out to the Sonofff again really quickly!  And... if I want to control the switches from my mobile phone using any old MQTT client I'm free to do so.

So there we are, a simple home IoT project.  After testing I'm seeing reliability issues on the switch.  Specifically random ESP8266 resets, and it seems I'm not alone.  Watch this space!

Blog Logo




Jamie Akers

Lego Geek, QA Engineer and Tech Enthusiast

Back to Overview