Search code examples
nest-api

Does Nest provide an API for my app to auto-detect/discover a new device being added


I created an app using the API instructions at developer.nest.com website. So the app can get a list of existing devices and control them the way I want.

But what if I want the app to do something special anytime I add a new device? Is this possible today? Has anyone done this successfully?


Solution

  • you can listen to updates several different ways. It depends on what you're using: Firebase, Rest Stream, Rest polling, etc. Basically, you'll need to create a Listener in your code, and after that check on triggered events. You can listen to different levels: structure or the whole account (root level).

    If you have a Rest stream, you can check out this curl command to see what's getting triggered in JSON:

    1.Open console and Nest developer tool

    1. Run this at the console (root level) with the access token* you have for your client : curl -L -v "https://developer-api.nest.com?auth=" -H "Accept: text/event-stream”

    3.Remove any thermostat from your virtual account.

    4.Check the triggered events in the console: you'll have your JSON missing the data for the thermostat you just removed.

    5.Now go one level up to the structures: curl -L -v "https://developer-api.nest.com/structures/?auth=" -H "Accept: text/event-stream”

    1. Repeat the same procedure with the virtual devices.

    *To get access token for your client go here: https://developer.nest.com/documentation/cloud/how-to-auth

    In case you want to check this out on a code level, you can find it in the Nest Sample Code. All of the samples have Listeners which allow you to see any changes happening to the thermostats in the account/structure.

    P.S. It's better to use Firebase or Rest Stream if you want those events to be triggered real-time.