How arriving home is a welcome sight

I’m continuing to try out different combinations of sensors and devices at home with the aim of automating different aspects of my daily life.  Whilst its unlikely to reach the level that Mark Zuckerberg announced in the past week, I’m finding that with a bit of thought you really can combine different bits of tech quite easily to provide a benefit.

A few nights ago, I had one of those “what if?” moments, in this case it was, “What if, when I could come and go from home in the dark (early mornings & late night returns from work!), the lights on the porch and hallway light automatically?”.  Within an hour or so I’d put together a simple system!

Not my house!

The main components needed were:

So how does this all plug together?  I’ve broken it down into a couple of sections which means you can pick and choose from these if you want to do bits of this yourself!  Note that this is more of a summary of how to get this system running – more detailed posts are coming on how to implement the actual components.  If you’re techy enough, you’ll get the gist from the notes below.

Spotting when I come home (or leave the house)

I wanted to use whatever technology I already had available, and so buying Bluetooth gateways etc. was out of the question.  The key thing I always have with me is my phone, and this connects/disconnects to my wireless when I arrive/leave home.  This was what I used to recognise when I was in or out.

First of all, it was necessary to configure the address reservation of my Sky router to always give my phone the same IP address.  This meant, the monitoring software would be able to see that IP address appear on my home network as soon as I got home.  A quick test showed that on pulling up outside the house, I was on the network within a few seconds – perfect!

Secondly, to monitor for the phone arriving, I built a node-red workspace which pinged the IP address of my phone every 5 seconds, and then reacted when the phone connected/disconnected to the network (more on this later).

Managing the house lights automatically

I already had some Milight bulbs in the house – these look pretty much like normal light bulbs, but via a controller (and free mobile app) you can manage their brightness and colour.  The bulbs were moved to the hallway and porch, and I checked that the Sky router also had a designated IP address for the controller.  At this point its also worth using one of the free apps to assign each bulb to a separate group so you have finely grained control.  My hall light was assigned to group 1, and the porch to group 2.

Testing the light colours out

I knew it was possible to control the lights via a PHP library I’d seen the past, so after a quick Google later, I found the code on GitHub.

As this was PHP, and because i’m lazy, I always find its easiest to kick bits of code off via a web server, so I installed WampServer on my home PC which provides you with a really quick way to get Apache2, PHP and a MySQL database installed.

To try out the PHP code, I dropped the LimitlessLED library into the webserver root, reconfigured the example to point at the IP address of the controller, and then flash a bulb group on and off.  Then it was a case of calling it via a the web browser.  It worked straight away.

To keep it really simple, I just copied the example a few times, and saved a number of additional PHP files for:

  • HallLightOff.php
  • HallLightOn.php
  • FrontDoorLightOff.php
  • FrontDoorLightOn.php

Quick and dirty code, but it would work.

The glue in the middle to automate the process

Now I just needed the “glue” in the middle act on my arrival/departure – this is where a node-red workspace came into its own!


I’ve included a view of the workspace, as it makes it easier to explain, but it works like this:

  • Ping the IP address every 5 seconds – the node responds with either false or a response time
  • If response is false, pass straight through to RBE (Report by Exception node) – i.e. we only need to know once if I’ve arrived or left, otherwise the lights are going to turn into a disco!
  • If response is a number, then convert that to true and pass to RBE
  • If the response if different to the last one, i.e. I’ve left or arrived pass through to the switch
  • At the switch, if the response is true then flow moves to “David Home”, if false, “David Away”
  • The relevant http request from node-red then calls the web server with the appropriate PHP code, i.e. if I arrive home, then HallLightOn.php and FrontDoorLightOn.php is called.
  • The “Auto-Home” node you can see is a “Notify My Android” node which sends a notification to my phone confirming the activity – this is just for debug at the moment.

That’s all there is to it!

What next?

Obviously this is just fairly basic so next steps are:

  • Only manage the lights if its actually dark, so I’m going to integrate with a web service which indicates if, where I live, its past dusk (and before dawn has broke)
  • Account for the fact other people may still be at home, and so if I leave the house for example, I may not want certain lights to switch off
  • Add other lights into the mix (on order!)

Leave a Reply

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