Keeping a Nest Thermostat in Home Mode Automatically
Keeping a Nest Thermostat in Home Mode Automatically

Keeping a Nest Thermostat in Home Mode Automatically

UPDATE: Recently IFTTT added the ability to utilize a Maker channel. This channel allows you to directly access the script and not need Dropbox. The fix is simply to remove the top three lines of the script. 

UPDATE 2: Nest has added geofencing to its app so the below can be done natively within the Nest App. However, you can add additional functionality using the Maker channel and link it to other smart devices.

The Problem

I was working from home this week as I was recovering from a wicked head and chest cold. At some point in the afternoon I started to feel cold and started shivering a bit. At first I had figured my cold was coming back, but then I had an “ah ha” moment. My Nest Thermostat had entered away mode. See, the Nest is on the first floor and the office is on the second floor. With the wife and kids out doing their normal routine, there was nothing preventing the Nest from entering away mode.

How I Did It

I used a few different pieces of technology to fix this problem:

If This Then That (IFTTT)

I used IFTTT to set up two simple recipes that do the following. When leaving a geofence area, set the Nest Sense Auto-away flag to true. This allows the Nest sensors to determine if someone is home. If not, it will enter away mode. The second recipe was the more important one. When I enter a geofence area (as dictated by my phone) it sets home mode to true and disables the sensor that triggers auto-away. Note: Screenshots below show the recipe “If Android Wear Button Press” as initial condition as it was easier to test. Actual recipe uses “If Android Location” as triggering condition. 

Screen Shot 2014-12-11 at 8.57.52 AM
IFTTT recipe to enable auto-away mode
Screen Shot 2014-12-11 at 8.58.18 AM
IFTTT recipe to disable auto-away mode

Dyn Standard DNS & Web Server Running PHP

It’s no secret I have a few servers running at home. I use Dyn’s Standard DNS to manage the DNS for my domain so that I can always reach my home server. I used a PHP library posted on Github as the basis for my script.  I created two files. First was away.php. The header section generates a bogus text file to upload to Dropbox. However, the PHP script must execute first. The script uses the PHP library to enable the Nest Auto-Away.

The second file is home.php. It is very similar to the away file except that it disables Nest Auto-Away and sets Home mode to true. Snippets from the files are below. Note they also use the nest.class.php file.

Home.php

<?php
header('HTTP/1.1 200 OK');
header('Content-type: text/plain');
header('Content-disposition: attachment; filename=delete-me.txt');

require_once('nest.class.php');

// Your Nest username and password.
$username = 'NEST USERNAME';
$password = 'NEST PASSWORD';

// The timezone you're in.
// See http://php.net/manual/en/timezones.php for the possible values.
date_default_timezone_set('America/New_York');

// Here's how to use this class:
$nest = new Nest($username, $password);

echo "Setting home mode...\n";
$success = $nest->setAway(AWAY_MODE_OFF); // Available: AWAY_MODE_ON, AWAY_MODE_OFF
var_dump($success);

echo "Setting auto away mode...\n";
$success = $nest->setAutoAwayEnabled(false);
var_dump($success);

Away.php

<?php
header('HTTP/1.1 200 OK');
header('Content-type: text/plain');
header('Content-disposition: attachment; filename=delete-me.txt');

require_once('nest.class.php');

// Your Nest username and password.
$username = 'NEST USERNAME;
$password = 'NEST PASSWORD';

// The timezone you're in.
// See http://php.net/manual/en/timezones.php for the possible values.
date_default_timezone_set('America/New_York');

// Here's how to use this class:

$nest = new Nest($username, $password);

echo "Setting auto away mode...\n";
$success = $nest->setAutoAwayEnabled(true);
var_dump($success);

Now I’m Comfy…Automatically

The scripts work perfectly. One thing I did notice was that if you have IFTTT on your phone and tablet, you are going to want to make sure you bring both the phone and tablet with you as the geofence can get confused with one device home and one not. Otherwise, it worked great.