Jump to content

Control your NEST with Raspberry Pi (or any other Unix)


xKing

Recommended Posts

Hi guys!

 

Thought this might help someone like me who does not have any Windows PCs at home to run EventGhost but has Raspberry Pi or other Unix-based system and wants ISY to be able to perform simple actions with the NEST.

 

Solution is based on the nest.py tool which is available here. All I did is modified it to run as a CGI script.

 

There is what you will need:

 

1) ISY with Networking module installed

2) Raspberry Pi or any other Unix box (I use FreeBSD 10) with Apache web server installed and running and python installed. Pi should be able to access internet.

 

First start with the CGI script nest-cgi.py

Place the file to the cgi-bin folder on your Pi, I think it is /usr/lib/cgi-bin but may vary, you can always find it using the following command

find / -type d -name cgi-bin

make sure file is executable

chmod +x nest-cgi.py

make sure 1st line of the file is pointing to the correct python binary on your system, for Pi (default) it would be /usr/bin/python, for FreeBSD it's /usr/local/bin/python - correct if wrong.

 

try to execute the file ./nest-cgi.py - it should complain about username or password being missing - that is OK. if you see python errors - that's bad, let me know and I'll try to help.

 

you should be ready to try it :)

 

fire up your favorite web browser and point to the script like that

http://1.2.3.4/cgi-bin/nest-cgi.py?user=me@example.com&pass=secret&cmd=show

replacing your username and password with your Nest credentials

 

that should give you a long list of variables showing a current status of your Nest(s) - if you see that - you are good to go!

 

there is a list of possible commands script can understand, note that if you have multiple Nest thermostats - you may want to add &index= option to the URL to address the specific one. If option is not present - it assumes index=0 which is your first thermostat, index=1 would be your second and so on. Which is which - experiment! :)

AWAY mode is set for the structure, not individual per Nest
http://1.2.3.4/cgi-bin/nest-cgi.py?user=me@example.com&pass=secret&cmd=away&away=away
http://1.2.3.4/cgi-bin/nest-cgi.py?user=me@example.com&pass=secret&cmd=away&away=here
 
http://1.2.3.4/cgi-bin/nest-cgi.py?user=me@example.com&pass=secret&cmd=mode&mode=off
http://1.2.3.4/cgi-bin/nest-cgi.py?user=me@example.com&pass=secret&cmd=mode&mode=cool
http://1.2.3.4/cgi-bin/nest-cgi.py?user=me@example.com&pass=secret&cmd=mode&mode=heat
http://1.2.3.4/cgi-bin/nest-cgi.py?user=me@example.com&pass=secret&cmd=mode&mode=range
 
for another Nest - add index:
http://1.2.3.4/cgi-bin/nest-cgi.py?user=me@example.com&pass=secret&cmd=mode&mode=off&index=1
 
http://1.2.3.4/cgi-bin/nest-cgi.py?user=me@example.com&pass=secret&cmd=temp&newtemp=72
 
http://1.2.3.4/cgi-bin/nest-cgi.py?user=me@example.com&pass=secret&cmd=fan&fan=on
http://1.2.3.4/cgi-bin/nest-cgi.py?user=me@example.com&pass=secret&cmd=fan&fan=auto
 
All you need now is to create Network Resources on your ISY!
I use POST method (it is possible to use GET as well but that would make your Nest username and password visible in the apache access.log file which is not secure)

 

Host: your Pi IP

Path: /cgi-bin/nest-cgi.py

Timeout: 5000 (it takes time to get to the Nest cloud service)

Mode: C-Escaped

Body: your command, for example: user=me@example.com&pass=secret&cmd=fan&fan=auto

please note that if you have special characters in your password - you may need to encode them in URL-safe way like "%2A" for star *, look at the ASCII table for reference.

Test your Resource and see if Nest reacts :)

 

I personally use it to set Nest AWAY and HOME as my alarm system status changes and I also have it set both Nests to OFF if my alarm system reports FIRE alarm (to shutdown possible air supply to the fire just in case).

 

 

 

Now how about the other way around?

I did some experiments and actually was able to set ISY variable to the current humidity level reported by Nest - I'm attaching the script nest.py

I just run it via cron every couple hours like that:

${HOME}/bin/nest.py --user me@example.com --pass secret --isyuser=user --isypass=secret2 --varnum=12 curhumid

and it does set ISY's state variable number 12 to the humidity level on my downstairs Nest.

 

 

 

 

Both scripts attached:

nestpy.zip

Link to comment

Updated the nest-cgi.py script so it does support index=-1 which would mean "ALL" for the cmd=mode like:

 

 

http://1.2.3.4/cgi-bin/nest-cgi.py?user=me@example.com&pass=secret&cmd=mode&mode=off&index=-1
 
http://1.2.3.4/cgi-bin/nest-cgi.py?user=me@example.com&pass=secret&cmd=mode&mode=range&index=-1
 

 

So you can shut off/turn on both Nests using a single network resource :)

Link to comment
  • 4 months later...

Is anyone interested in NODE.JS script that is using the NEST API (Firebase) and capable of reporting thermostat status back to ISY (as variables)?

 

It's pretty rough right now but if you understand NODE.JS (Javascript) you can customize it to your taste. 

Link to comment
  • 1 month later...

Hello,

 

I followed your instructions and have things set up. When I execute the script on the Pi itself, or enter the URL without the username and password I successfully get the message to try a user and pass arguments next time. My trouble comes in when I try and use the URL you give that should show me a list of variables. Of course I am using the IP address for my Pi and the correct credentials for my nest account. When I execute this I get a page that starts with '<class 'urllib2.HTTPError'>'. There is much more I can provide if it helps but it is quite long and didn't want to copy and paste it all if it wasn't necessary.

 

I would love to be able to get this working and would appreciate any help you may be able to provide!

Link to comment
  • 11 months later...
  • 10 months later...

This is a really fantastic solution, thanks xKing. I just implemented this on my server at home using Docker. I had to make some minor modifications to the package.json file but documented everything I did along with some howtos on github. I've forked your project for now, let me know if you'd be interested in merging this back into your version or have any suggestions. I'm also looking for someone to test the process and make sure it's repeatable. It took me a few hours to figure out how everything works.

 

Dockerized isynnode

Link to comment
  • 4 months later...

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...