Automatically set your Nest thermostat's away status via requests.
My roommate and I had recently purchased a Nest thermostat, and while it was mostly great and worked well, it had one major flaw. The Auto Away functionality didn't work on his phone. The meant that our apartment wouldn't go into Away mode when we left for work, and we'd literally be throwing money out of the window. Nest support was decent, but never really got to the bottom of the problem, and rather than spend more time in queues and re-explaining my problem, I decided to whip up my own solution.
Note that my installation assumes that you're putting it into /usr/local/bin/, obviously it can be put elsewhere, but you'll have to mess around with the configuration to get everything working fine.
- Clone/Unzip the files into
/usr/local/bin/empty-nest. - Update the
token.jsonandconfig.jsonfiles.- Get a Nest API token. You'll first have to create an OAuth client here, and then connect it to your Nest here.
- Update the
usersJSON array inconfig.jsonto account for all of the users in your house that you want to be able to control the Nest's away setting. Just give each these users a unique username. - Update the
structure_idvalue inconfig.jsonwith your structure's unique id. You can get this with a simple GET request to the Nest API. See this link's "Read structures and devices" section for an example query.
- Run with
python code/empty-nest.py(assuming you're in the root directory.
If your system uses systemd, then you can also use my service file to have this program run automatically.
- If you didn't install empty-nest into
/usr/local/bin/empty-nest, then update the paths inempty-nest.service. - Move
empty-nest.serviceto/etc/systemd/system/ - Activate and run the service with the root command:
systemctl daemon-reload && systemctl enable empty-nest && systemctl start empty-nest --no-block - Now you can control empty-nest like any other service using
sudo service empty-nest start|stop|restartand etc.
If your system doesn't use systemd, then you can just as easily set up a cronjob to run empty-nest.py on boot.
With your server running empty-nest and taking requests, simply:
- Download IFTTT onto the phones of the users in your household.
- Add the appropriate trigger to denote when you're in your house (I like the Location (Enter an area) and Connect to specific Wifi ones).
- Tell IFTTT to POST a web request using Webhooks to your server. The request should be of type
application/json, and will look something like this:{"user": "<username>", "away_state": "home"} - Save, and try testing the applet!
You can also do the same for firing a request when you've left your house by:
- Add the trigger to denote when you've left (Again, I like the Location (Exit an area) and Disconnect from specific Wifi ones).
- Again, use Webhooks to POST a request to your server, using
application/jsonagain. The body will be almost the same, but theaway_statevalue will beaway. For example:{"user": "<username>", "away_state": "away"}. - Save, and test!