0

I am trying to develop an ios app using the newly published NEST api but bit lost with their native documentation.

Question:I could get an access token but do not know the thermostat endpoint to query and update "Away" state

Any pointers will be greatly appreciated ..

1 Answers1

2

I'm presuming you intend to use REST to query and update the away state since you mentioned "endpoint"? If not the other alternative is to use the firebase API. This is documented in the introduction section

To get the away status you'll need to query the structure/s

curl -v -L https://developer-api.nest.com/structures?auth=<AUTH_TOKEN>

The response shows the away state in addition to the thermostats/smoke co alarms in that structure.

{
    "g-9y-2xkHpBh1MGkVaqXOGJiKOB9MkoW1hhYyQk2vAunCK8a731jbg": {
        "away": "home",
        "country_code": "US",
        "name": "Home",
        "smoke_co_alarms": [
            "0NBM7-QfoLwhMldZ2CoIkQ7hRJoe1Jye"
        ],
        "structure_id": "g-9y-2xkHpBh1MGkVaqXOGJiKOB9MkoW1hhYyQk2vAunCK8a731jbg",
        "thermostats": [
            "GM6Z9JpSKU6_ua8AfD6WRA"
        ],
        "time_zone": "America/Los_Angeles"
    }
}

To update the away state you would need to use the PUT http verb:

curl -v -L -X PUT "https://developer-api.nest.com/structures/g-9y-2xkHpBh1MGkVaqXOGJiKOB9MkoW1hhYyQk2vAunCK8a731jbg?auth=<AUTH_TOKEN>" -H "Content-Type: application/json" -d '{"away":"away"}'

Note that the ID used in the path parameter is the structure ID returned in the get response.

Hope that helps Nagesh

Community
  • 1
  • 1
Nagesh Susarla
  • 1,660
  • 10
  • 10
  • 1
    Nagesh, thanks..i got stuck with oAuth issues before i can test your approach ..any pointers on oAuth will be appreciated – user3777689 Jul 10 '14 at 02:21
  • What problem are you having with oauth? On the https://developer.nest.com/clients page you should be able to see the URLs necessary to perform the oauth. Note that a POST is required to fetch the access_token at https://api.home.nest.com/oauth2/access_token – Nagesh Susarla Jul 10 '14 at 05:01
  • Nagesh..how do i get g-9y-2xkHpBh1MGkVaqXOGJiKOB9MkoW1hhYyQk2vAunCK8a731jbg ..from the returned json ..i believe its dynamic – user3777689 Jul 12 '14 at 05:12
  • If you directly do a get on https://developer-api.nest.com/ with the auth parameter, you should get a JSON object that contains structures and devices. From here the "structures" object just contains a map of String => StructureInfo objects. In java, it would be defined as Map structures. From here you get the structure with a name that matches your requirement and use that structure_id to issue a PUT request. Gist to show you a java example: https://gist.github.com/nageshs/178239fd37016bdceede – Nagesh Susarla Jul 13 '14 at 07:08