Showing posts with label Home Automation. Show all posts
Showing posts with label Home Automation. Show all posts

Thursday, 19 June 2014

How to make your Nest Thermostat email you when "auto-away"

While Nest are still to release details of their API, some clever people have already deconstructed the methods by which your Nest Thermostat (and Nest Protect) talks back to Nest Cloud HQ and have released a PHP script which can pull data from Nest Cloud HQ, allowing you to do with it, whatever you want!

Some examples of the things that I am currently doing:

1. Graphing my internal Nest temperature reading using PRTG


2. Capturing and emailing me when Nest thinks I'm "away" and when i'm back.

3. Monitoring the internal battery voltage of the thermostat - could potentially be used to notify me of a power cut whilst away from home (for example, if the voltage drops below a certain level).

Gathering and using all this data first relies on capturing it with the improvised Nest API.

Here's what you'll need to do:

1. Visit the link above and download the nest.class.php file
2. Publish the above on a web server that supports PHP, and has Internet access
3. Create another PHP file that "includes" the above class and gathers and presents the data you want.  There are examples on GitHub, and I've included my own hacked together example here:


 <?php  
 header('Content-Type: text/xml');  
 require_once('nest.class.php');  
 // Your Nest username and password.  
 $username = 'your@nest.email.address';  
 $password = 'YourNestPassword';  
 // The timezone you're in  
 // See http://php.net/manual/en/timezones.php for the possible values.  
 date_default_timezone_set('Europe/London');  
 $nest = new Nest($username, $password);  
 // Get the device information:  
 $infos = $nest->getDeviceInfo();  
 // Start XML Output  
 echo "<nest>";  
 // Print the current temperature  
 printf("<nesttemp> %.01f </nesttemp> \n", $infos->current_state->temperature, $infos->scale);  
 // Print the current humidity  
 printf("<nesthumidity> %.01f </nesthumidity> \n", $infos->current_state->humidity, $infos->scale);  
 //Print Auto Away 0 or 1  
 printf("<autoaway>%.0f</autoaway>", $infos->current_state->auto_away);  
 //Print Manual Away 0 or 1  
 printf("<manualaway>%.0f</manualaway>", $infos->current_state->manual_away);  
 //Print Battery Level  
 printf("<battery>%.02f</battery>", $infos->current_state->battery_level);  
 //Close XML  
 echo "</nest>";  
 ?>  

When you GET this php file, it shows XML output like this:

 <nest>  
 <nesttemp>24.6</nesttemp>  
 <nesthumidity>39.0</nesthumidity>  
 <autoaway>0</autoaway>  
 <manualaway>0</manualaway>  
 <battery>3.94</battery>  
 </nest>  

4. Now using something like PRTG (free for a licence of 10 sensors) and the HTTP XML Sensor type, you can GET your PHP script every few minutes (I wouldn't recommend more than once every 5 minutes), and have PRTG automatically interpret the XML into sensor values.  All you need to do is tell PRTG the full web address of your php file and also which XML tags you want to capture.  The sensors it produces will look like the ones shown below:



5.  Lastly, once you have the data captured, graphed etc, you can set-up a notification within PRTG to send an email when a certain value is seen on a sensor.  In our case, to email us when the Auto Away sensor = 1


I've found that setting a single threshold trigger when the value = 1 and then another notification when the condition clears seems to work best - rather than 2 separate threshold triggers for 1 and 0.

There are numerous other things you could do with this depending on what you want to monitor and the Nest API allows you to SET certain parameters as well as GET them.



Tuesday, 20 May 2014

5 things I wish IFTTT.com would support

Having been less than complimentary about blog posts starting with "X things...." I now produce a blog post with exactly that title.

If you haven't heard or used IFTTT yet, you need to learn about it.  It's not an understatement to say that this service, or others like it, could become the backbone of machine-machine (software to software) automation.  For a home automation geek like myself, it opens lots of opportunities.  I'm already starting to use it for processing emails and alerting from my IP garage door project.

However, there are a few things I would love to see IFTTT include on their roadmap....


  1. AND functionality.  For example, I want to combine 2 triggers, so that if both of them are true at the same time, then the action is taken. Example: If you receive an SMS from The Boss AND it's after 6pm THEN reply with "I'll deal with this in the morning"
  2. Add an HTTP POST channel.  This would allow IFTTT to send an HTTP POST request to a web site/script of your choice based on a trigger.  The script (written in PHP for example) could perform, well, anything!  There is a work-around however.  For me, a great use of this would be to auto-generate a credit voucher for CheekySMS when I receive a specific SMS that tells me someone paid for credit.
  3. Introduce a Nest channel :) - I know Nest (Thermostats and Smoke Alarms) are already building an API, so wouldn't it be great if we could get things to happen based on temperature or potential dangerous events in our homes.  WeMo and Philips Hue are already supported so full home automation with IFTTT doesn't look too far away.  X10 aside, a standard home automation protocol has long alluded us, but with a service like this, it becomes less of a problem.  Device manufactures such as Nest, and Philips can focus on delivering great hardware (and APIs) and let services like IFTTT provide the middleware to translate between them all.
  4. Introduce a SIP voice channel - Alerting by SMS or email on your smartphone is all very well, but call me old fashioned, what really gets my attention is when the phone rings!  Just an automated, text to speech service would do!
  5. Introduce a text search capability - By this I mean, provide a specific web page URL to IFTTT and trigger on a content change or a specific item of text within that web page.  Great for alerting based on a price change on your favourite online store, or maybe getting an alert when tickets to a popular concert get released.


If you're using IFTTT already, share your stories, or let me know how you could make use of these ideas.


Monday, 19 May 2014

My DIY Garage Door IP Control

It wasn't until I was 100 miles from home that I remembered I'd left the door to my new garage wide open!  There was nothing I could do about it until I got home again 8 hours later, so it got me thinking about a way of controlling it remotely.  I already have a wireless key-fob, but I wanted something with a bit more range and so my search for an IP enabled garage door began.  There are some ready-made solutions by the big manufacturers but they are expensive and somewhat restrictive.

The first step was to see what I could do with the Garador Garamatic 7 electric "motor" I already used (in combination with the key-fob).  Luckily, like all Garador electrically operated doors, it's possible to add an external impulse button to start/stop the door travel cycles.  Effectively this is just an electrical short across 2 connections inside the control unit and is usually used for a push button start/stop or a manual key switch.  See figures 10/11 in the Garador manual.

Next I found an Ethernet connected relay that included an SNMP and HTTP interface, a really nice piece of kit with a thousand uses!  There are a number of these on the market, but this one came from a UK based distributor and most importantly had the HTTP interface/API that I planned to use to pass commands from my smart phone.  Additionally it also had digital inputs on board.  Although this wasn't essential, I figured that being able to sense when the garage door was closed was also quite important - I could have used a webcam I suppose - I might still do!



Lastly, the Ethernet connection to the garage was accomplished (in the short term at least) using a pair of TP-Link powerline adapters.  To my surprise, these worked across multiple RCD units.

The connection to the door motor control unit was made using 2-core cable, into the "Normally Open" and "Common" connections on the Ethernet relay.  In order to start the travel cycle of the door, the relay only needed to close for a second, so the pulse feature of this relay was ideal for this.  For each pulse of the relay, the door will open, stop, close, stop etc but it will also stop automatically when the door reaches the end of it's travel as normal.  During testing, I was using the web interface built into the relay.


Next was the sensor to detect the state of the door.  With the relay having the ability to take digital inputs, I decided to buy a cheap reed switch usually used with household burglar alarms.  The switch was placed in a static location at the top of the door frame, while the magnet - stuck to the door - would travel as the door opened and closed.  It took some trial and error to make sure they were positioned correctly, especially as the working space was very limited when the door was closed.  The wires from the switch could be hidden nicely along the door track with the help of some cable ties.



The reed switch wires came back to the digital input 1 and ground connections on the relay so that when the door was closed, the digital input was high.

That all worked nicely, but I was still controlling and monitoring it all from the web interface on my laptop.  What I really wanted was a quick Android App!  There is a generic app to control the relay available on the Play Store but I wanted something a bit more customised...

I've been using App Inventor since it's early days, and it is more than powerful enough
to code a quick UI with HTTP GET calls to the URL which controls the pulse command on the relay and the URL to get an XML status of the relay.  The XML status contains the status of all elements of the relay, many of which I wasn't using, so I had to parse the output to capture the Digital Input element I was interested in.   I also added a quick "pin pad" login in case my phone ever gets "borrowed".  It's very simple, ugly, but perfectly functional!

There are a number of improvements I will make over time, including tidying up the Ethernet and power connections to the relay.  I could also perhaps add a second reed switch to tell me that the door is fully open.  Therefore if neither digital input is reading closed, I know the garage door must be stuck half open.  However, generally I'm really pleased with the result, never again will I be caught out, miles from home wondering if I shut the garage door behind me!

UPDATE: I've now added a 1-Wire DS18B20 Temperature Sensor which I purchased on ebay, to the relay via it's dedicated 1-wire input pins.  It really was plug and play, and now I can also read the temperature in the garage.  You will need this DS18B20 pinout....