nest-hand

Integrate DAKboard with your Nest Thermostat

This is a guest post by DAKboard userĀ Jason McLeod. We noticed Jason’s blog comment discussing how he had usedĀ his Nest Thermostat to turn his DAKboard off when he was away. This sounded like an awesome integration, so we asked Jason if he’d be willing to document the steps he took, and he graciously accepted! So without further delay, here is Jason’s post!

About Me

My name is Jason McLeod and I work as a Configuration Manger specializing in process automation. My wife actually requested some sort of screen in the kitchen to make it a bit easier to keep track of where she and the kids needed to be day to day. DAKboard was a good fit and gave her the information she needed. Plus I’d been looking for a project involving a Raspberry Pi so it was a good excuse. In the end it only took a single evening to get everything pulled together and working the way I wanted.

img_4949

Then I got to thinking how to set the screen on and off when we were home, and remembered that the Nest Thermostat had that information.

Setup the Nest Python Bundle on the Raspberry Pi

Nest has a python bundle that allows you to pull information from your account.

Start by installing the Nest bundle.

sudo pip install python-nest

Then setup our script to tell us if Nest is set to Away.

nano /usr/local/bin/nest_away

Add the script, making sure to update the username and password for your Nest account.

#!/usr/bin/python

import nest

username = ''
password = ''

napi = nest.Nest(username, password)

for structure in napi.structures:
	print str(structure.away).lower()

Mark our script as executable.

chmod +x /usr/local/bin/nest_away

Running nest_away should now say false when you’re home and true when your Nest is set to away.

Turn the Monitor On/Off

Now we need to do something with our Away status! Lets turn the monitor on and off based on the status.

nano /home/pi/nest.sh

Setup our script

#!/bin/bash

last=$(cat /home/pi/.nest)
now=$(/usr/local/bin/nest_away)

if [ "$last" = "$now" ]; then
   exit 0
else
   echo $now > /home/pi/.nest
   if [ "$now" = "true" ]; then
      /home/pi/rpi-hdmi.sh off
   else
      /home/pi/rpi-hdmi.sh on
   fi
fi

nest.sh stores the last run results so that when we are away or home, we’re not spamming turning the display on or off when it is already in that state. We write the true/false value into a hidden file in the pi user’s home directory /home/pi/.nest. When the script runs and finds that the values are different, it decides to turn on or off the display.

Now we just need to add a cron job to run our new script.

crontab -e

Adjust the times to suit your own needs.

# Turn HDMI Off (12:59am)
59 0 * * * /home/pi/rpi-hdmi.sh off

# Turn HDMI On (6:30am)
30 6 * * * /home/pi/rpi-hdmi.sh on

# Test if we are away every 5 minutes but only during the hours we would have the display on.
*/5 7-23 * * * /home/pi/nest.sh

Mobile Push Notifications (Optional)

Bonus: I wanted to know that the script was actually running when I was away, since I wasn’t at home I couldn’t check. So I setup a push notification to my iPhone using Prowl.

apt-get install python-prowl

You’ll need to get an API key from your Prowl account at www.prowlapp.com

nano ~/prowl.py

Insert the script and update the key to yours.

import prowlpy
prowl = prowlpy.Prowl("Your_API_Key")
def str2bool(v):
    return v.lower() in ("yes", "true", "t", "1")
with open('.nest', 'r') as nest:
    data=nest.read().replace('\n', '')
if str2bool(data):
    prowl.add('Dashboard','Update','House is Away',None,None)
else:
    prowl.add('Dashboard','Update','You are Home',None,None)

Modify nest.sh to perform the push notification. We’ll add the prowl script inside the part of the if statement where we turn the display on or off.

#!/bin/bash
last=$(cat /home/pi/.nest)
now=$(/usr/local/bin/nest_away)

if [ "$last" = "$now" ]; then
   exit 0
else
   echo $now > /home/pi/.nest
   if [ "$now" = "true" ]; then
      /home/pi/rpi-hdmi.sh off
   else
      /home/pi/rpi-hdmi.sh on
   fi
   /usr/bin/python /home/pi/prowl.py
fi

img_4948

14 thoughts on “Integrate DAKboard with your Nest Thermostat”

  1. Would be great to be able to have Nest and other home automation information shown on the Dakboard. For example:
    1. Show current home temperature and humidity
    2. Integrate with SmartThings to display status of Things (see SmartTiles)
    3. Integrate with Samsung Artik to display real-time graphs e.g. power consumption, car fuel level, etc.
    4. Integrate with health dashboard like Samsung Health or Withings to show no of steps walked and weight graph
    5. An Alexa skill to be able to control a DAKboard given that it is likely that a DAKBoard does not have input, voice commands could be triggered on Alexa and sent to the DAKBoard

  2. @Jason McLeod

    Thanks for posting the steps. I have a question to ask you though. Do we need to own a Nest in order to go about this process? My goal is to get my Google Home to turn off my display when I am not at home. Using Nest as an intermediary is a great idea, however, I don’t own a nest so was just wondering if I can still use these steps without owning a Nest.

  3. This is great. I don’t have a nest but do have Ecobee 3 and 3 sensors, so I wonder if this can be done with my system?

  4. Hello! I’ve been following your blog for a long time now and finally got the bravery to go ahead and give you a shout out from
    New Caney Tx! Just wanted to mention keep up the great work!

  5. I’m having problems with this integration not working and am wondering if anyone else is seeing the same thing? Basically it does nothing but when I tried to troubleshoot I ran nest_away on it’s own and got the following error:

    raise AuthorizationError(response)
    nest.nest.AuthorizationError: Authorization Failed

    I double checked my credentials are fine and I left them in the single quotes when entering my home.nest.com user ID and password:

    username = ‘chris@bigchris.com’
    password = ‘mypassword123’

    Any ideas? Thanks

  6. I’ve been playing with Dakboard currently using Cron for timers. Perhaps we could use an old usb webcam for detecting movement and switching the screen on for 10 mins or so? Sadly my own programming ability isn’t up to any level to do this!

  7. Hi…Is this still working? I have the same error as mentioned above: raise AuthorizationError(response)
    nest.nest.AuthorizationError: Authorization Failed. Is there a way to use IFTTT to get this or similar functionality to work?

  8. I’m getting the same authorisation failed error. I wonder if this is because I have 2 factor authentication enabled on my Nest account.

Leave a Reply

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