Skip to content

Demos how to build a Works with Nest integration using best practices. Specifically, secure your API credentials; provide a structure picker; listen and update fast; handle Home/Away; include confirmation and error messages; remove cached data; remove camera images; handle deauth and revoked auth.

License

Notifications You must be signed in to change notification settings

Gerguis/nest-python

Repository files navigation

Python Works with Nest Sample App

NOTE: This is not an official Google product.

1. Introduction

This is a simple web app that talks to the Works with Nest API using Python and
the Flask web framework. You'll use a Nest product to be accessed from the app.

—————————————————————————————————————

2. Requirements

  • The sample code
  • Basic knowledge of HTML, CSS, Javascript, and Python (to change the sample)
  • Python interpreter 2.7.x
  • At least one Nest device, such as Nest Thermostat, Nest Cam, or Nest Protect

—————————————————————————————————————

3. Install dependencies

This project uses Python's PIP to manage dependent packages.

  1. Install PIP and Python 2.7: https://zaiste.net/posts/installing_python_27_on_osx_with_homebrew/
  2. Download the sample app and install the dependencies.

In a terminal window, go to the python-sample directory and run the following commands.

Spin up a virtual environment:

$ pip install virtualenv
$ virtualenv env
$ . env/bin/activate

Install the dependencies (virtualenv):

(env) $ pip install -r requirements.txt

—————————————————————————————————————

4. Set up your Nest device

If you don't already have a Nest device set up and associated with your
home.nest.com account, use one of the following procedures.

Set up a Nest device with a Mac or Windows computer

-OR-

Set up a Nest device with the Nest App

-OR-

Use the Nest Home Simulator to simulate a Nest device

—————————————————————————————————————

5. Create a cloud product at console.developers.nest.com

Use the same account that you used for your Nest device.

For the redirect URI, use http://localhost:5000/callback

For the permissions, select read/write corresponding with your Nest product. For example,
if your Nest product is a Thermostat, select Thermostat Read/Write.

In order to authorize your Nest integration, you need a Product ID and Product
Secret. The next step is to set the product ID and product secret as environment
variables so these values can be retrieved by the application.

If you are using Linux or MacOS, open a Bash shell and type the commands below
(substitute your product ID and secret you copied from your product page):

$ export PRODUCT_ID = 'Your product ID here'
$ export PRODUCT_SECRET = 'Your product secret here'

—————————————————————————————————————

6. Run the app

If it's not already running, spin up the virtual environment:

$ virtualenv env
$ . env/bin/activate

Run app.py:

$ python app.py

If you are prompted, click to allow incoming network connections.

—————————————————————————————————————

Click Login.

When we log in, we are redirected to the Nest Authorization screen.
On the Nest Authorization screen, click Accept.

When we accept the integration, the Nest Authorization screen redirects to the
Redirect URL configured for our product integration (http://localhost:5000/callback).

—————————————————————————————————————

8. See the app in a mobile format

In Chrome, right-click the app and select Inspect.
In the Responsive pulldown menu, select another format, such as iPhone 6.
Click the icon that looks like a phone (Toggle device toolbar).

Companion codelab

10 Tips for a successful Nest integration

Contributing

Contributions are always welcome and highly encouraged.

See CONTRIBUTING for more information on how to get started.

License

Apache 2.0 - See LICENSE for more information.

About

Demos how to build a Works with Nest integration using best practices. Specifically, secure your API credentials; provide a structure picker; listen and update fast; handle Home/Away; include confirmation and error messages; remove cached data; remove camera images; handle deauth and revoked auth.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published