Friday, 28 December 2012

Do you want to save money this winter? Geo-fence your boiler using your iPhone!

Introduction

With the advent of Apple's iOS 6 comes the ability to use geo-fencing, a way of sending notifications based on your location.

I have often thought about how much money I could save by switching my heating off when no-one is at home, but constantly adjusting the boiler control is impractical given life's changing schedule. However, I set myself the challenge of automating the process as soon as iOS 6 was released.

Warning: This project involves wiring mains voltage and altering your boiler controls. This is hazardous to health and may also break your boiler and void its warranty. Please do not attempt anything I describe below unless you understand these risks.

Required ingredients

  • Single channel USB relay (plenty are available on eBay
  • A smartphone capable of Geo fencing (in this case an Apple iPhone 4) 
  • A server (in this case a Windows 7 PC, but in principle you could use something as basic as a Raspberry Pi
  • A dedicated email account with POP or IMAP access 
  • A script to read emails and control the USB relay (I wrote mine using Python)

Wiring up to the boiler

Here are some wiring pictures for the boiler control and thermostat.

Addition of the black wire (sent to USB relay)
Finished product - no visible changes!



USB relay box. Note the three spare relays, hmm what should I control next...

You will see that I have inserted the relay as a switch between the thermostat and boiler control, so all three devices retain control of the boiler.

Note that I have wired the relay up as normally closed. This makes sure that the boiler reverts back to normal if the PC suddenly dies. 

Setting up the smartphone

Here is how I setup my Apple iPhone. I created two notification conditions within the 'Find Friends' app to send an email to my dedicated address for when I leave and arrive at my home address. Luckily (for Apple), everyone in my house has an iPhone and so this process was repeated on each phone in turn.

Free from the Apple App Store

Notification options within the app
Bespoke email address for the boiler!


Creating a script

Here is the script process:


You will receive emails from Find Friends with the subject field reading "Benjiosaur has arrived/left Home". Therefore you set a list of rules to decide whether anyone is in your house, and if not, switch the heating off. I can send you example code if you wish - just send me a message.

Testing


I have tested this app over the last month and it does work well. Notifications are sent from the iPhones within 2-3 minutes of leaving or arriving home, and so far it hasn't let me down. I have thought about a few modifications which may improve the kit:
  • Trigger the boiler to also switch on once you leave a destination (e.g. work) so your house is pre-heated upon arrival.
  • Replace the boiler controller and thermostat with custom software using temperature probes in and outside the house for optimum efficiency.
I have yet to calculate actual savings for this winter - I will clearly save money if I arrive home late, but I am not so sure if I were to leave for just half an hour or so. When I get some spare time I'll see if I can run a few calculations.

Overall cost

Since I already have an always-on server and iPhone, the cost was literally just for the USB relay (~£30) and a few hours for wiring it in and writing the code.

Goodluck!

Comments and suggestions are welcome, thanks for reading!


25 comments:

  1. Hi
    I'd love the sample of the code you used for this.
    Please email me at pieterkdevilliers@me.com
    Thanks
    Pieter

    ReplyDelete
    Replies
    1. Hi Pieter,
      I've sent you a sample, please check your emails!
      Regards,
      Benji

      Delete
  2. dhcconsulting@gmail.com25 January 2013 at 02:06

    Hi,
    This looks really cool. Could you please send me some sample code
    dhcconsulting@gmail.com

    Thanks

    ReplyDelete
    Replies
    1. Hi,
      Please check your emails.
      Regards,
      Benji

      Delete
  3. ditto for the sample code. Perhaps a wiring diagram as well? thanks.

    ReplyDelete
  4. oops, martgadget at gmail.com

    ReplyDelete
    Replies
    1. Hi sorry for the delay! I will send you the code shortly. Benji

      Delete
  5. Hi Benji, good work. Will be looking to do something similar. I had
    been looking at RF control, but your method looks great. Am interested
    in knowing more about the wiring. I've not used a USB relay before ...
    Am looking at having a RaspPi sending a signal to override my Drayton wireless thermostat, I will be keeping a simple day pattern but allowing to send early on/off commands. Perhaps link in with a calendar as well.
    Here is the current diagram of my Drayton control board .. http://farm9.staticflickr.com/8226/8456171912_7e99bf5373_z.jpg

    I do know a plumber well, so can also get a bit of help with the actual implementation, if necessary!

    ReplyDelete
    Replies
    1. Hi there,
      Your project looks interesting - you can also get standalone wifi/ethernet relays if you wanted to locate your RaspPi elsewhere.

      The USB relay that I used really isn't anything else other than a mains switch. It draws it's power from the USB bus and so it's a simple three wire setup. Looking at your wiring diagram as reference, my relay switch is put between the ON on your thermostat and the Live on your boiler.

      Goodluck!

      Delete
    2. I've got further. Mainly in that I've a combi boiler and would like to default back to normal Drayton wireless control if Raspberry Pi fails. This is how I envisage my wiring .. does it make sense? http://farm9.staticflickr.com/8366/8467518805_feef28b680_z.jpg

      From there, I have a c script working which I can call to turn my relay on/off .. I am calling this from RPi from PHP at moment. Works fine. As I have some older Pi's lying about and some old wifi dongles, this seems to workout cheaper than wifi relay. (Here's a video of a test script ... http://www.youtube.com/watch?v=GExIa8L0C3w&list=UUuvp87JvDZbGS0dGeJfCHcw&index=1) ...
      I'd be interested to know what you thought of the wiring schematic and to find out what "volt free contacts" means. Is the Call For Heat just completing the circuit i.e. like a reed switch?

      Delete
    3. Hello - apologies I was on holiday this week,

      The 'call for heating' on my boiler circuitry means 'supply me with 240v' to activate the boiler. You could perhaps interrupt this wire with the raspberry pi controlled relay, through the normally closed connection? That way if the Pi dies or loses power, the wire will be completed and full control will return to the Drayton?

      I believe the volt free contacts mean that the switched load is independent from the supply powering the relay, which is certainly what you need given that boilers generally use mains!

      Delete
  6. hi, very cool, would be keen on having a look at the code? trying to get my gate to open with geofencing ... thebays @ gmail.com ... thanks

    ReplyDelete
    Replies
    1. Hi, please check your emails!
      Regards,
      Benji

      Delete
  7. Fantastic idea. Looking to do something similar. I am using a raspberry pi with Domotiga home automation software. Any chance of a look at the code.

    Ian

    ReplyDelete
    Replies
    1. Hi Ian,

      Please send me your email address and i'll forward you the code sample.

      Benji

      Delete
    2. ian at de7 dot co dot uk

      Also, how do you get the iphone to set these notifications to be recurring rather than once only?

      Delete
    3. I'll send you the code via email shortly.

      So within Find Friends goto 'Me', then 'Notify' and select either a new or an existing notification. From there you should have a 'Repeat Every Time' option? I can send some screen shots if this would help?

      Benji

      Delete
  8. Hi Benji,
    that looks really good. Can you please sent me the example code you used. I am currently building my home automation using FHEM (www.fhem.de) and there are really nice use cased to have a functionality as you described. Please sent to dummy at it-gemein.de
    thx a million

    ReplyDelete
    Replies
    1. Hi there,

      Sorry for the delay, I have sent you the code sample.

      Regards,
      Benji

      Delete
  9. Hi. Love your project. I am looking to do exactly the same thing, using a RPi as the server. However I cannot understand how to control the relay using a email with the RPi. Can anyone point me in the right direction? Has anyone coded this already.

    ReplyDelete
    Replies
    1. Hi there,

      I haven't had any experience with a RPi yet but will most likely purchase one in the future.

      I can send you my sample python code if this would help?

      Regards,
      Benji

      Delete
  10. Thanks Benji, It would help greatly. I intend to update details to the web, once it is up an working. My email is M8R-jl85tj@mailinator.com

    ReplyDelete
    Replies
    1. I have just sent you the code, I look forward to seeing your progress!

      Thanks,
      Benji

      Delete
  11. Send me too please! It is very interesting idea! My e-mail doo@mail.ru

    ReplyDelete
    Replies
    1. Hi Oleg,

      I've sent you the code.

      Goodluck,
      Benji

      Delete