Nest "binding" without a binding!

1,997 views
Skip to first unread message

Fred Bret-Mounet

unread,
Jul 28, 2014, 7:58:15 PM7/28/14
to ope...@googlegroups.com
So I wanted to implement the Nest binding, but gave up due to the complexity of the architecture...

But I wanted a read-only integration of the Nest into Openhab.
Here's the recipe:
  1. get a developer account @ https://developer.nest.com/ and create a client registration:

  2. Copy the authorization URL and open it in a new browser. Use your Nest login to approve the request. Once approved, you will get a "pincode".
  3. I used curl, but there are other tools out there to do an http post. In the "Access Token URL", replace the "AUTHORIZATION_CODE" with the pincode from step 3
  4. curl --data 'code=AUTH_CODE&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=authorization_code' https://api.home.nest.com/oauth2/access_token

    {"access_token":"[big long random string]","expires_in":315360000}

  5. We're done! The above access_token will give you access to the api for the next 10 years :-)
  6. To test, open the following url in your browser: https://developer-api.nest.com/devices/thermostats?auth=[big long random string from step 5]
  7. A json structure should be returned with all your devices. Get the "device_id" for your thermostat.
now in the openHAB world:
Items:

Number curNestTemp   "Nest [%.1f F]"  <temperature> (Weather_Chart,gFF) { http="<[nest:60000:JS(GetNestValue.js)]"}

Number curNestTargetTemp   "Nest Target [%.1f F]"  <temperature> (Weather_Chart,gFF) { http="<[nest:60000:JS(GetNestTargetValue.js)]"}

openhab.cfg:

############################### HTTP Binding ##########################################

http:nest.url=https://developer-api.nest.com/devices/thermostats/[DEVICE_ID from step 8]?auth=[big long random string from step 5]

http:nest.updateInterval=60000

GetNestValue.js:

JSON.parse(input).ambient_temperature_f;

GetNestTargetValue.js:

JSON.parse(input).target_temperature_f;


Simple! Now, every minute the current thermostat and target temperatures are refreshed. You can easily read any of the other properties of the thermostat as described here: https://developer.nest.com/documentation/api-reference.

For active control over the thermostat, you are on your own!

 -Fred





Kai Kreuzer

unread,
Jul 30, 2014, 1:17:33 AM7/30/14
to ope...@googlegroups.com, Thomas Eichstädt-Engelen
Hi Fred,

This looks nice!

> but gave up due to the complexity of the architecture…

You mean the openHAB architecture? It actually should not be too hard to encapsulate this code into a binding of its own. Most tricky part is probably the OAuth process, but there are other examples, how this can be handled (e.g. DropBox addon, Withings binding). Maybe somebody else is interested to take on this task?

Nonetheless, I think it would already be worthwhile to add your description to the wiki.
@Thomas, if you agree, what could be a good place for this?

Regards,
Kai


--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
For more options, visit https://groups.google.com/d/optout.

Thomas E.-E.

unread,
Jul 30, 2014, 3:40:24 AM7/30/14
to ope...@googlegroups.com, tho...@openhab.org
Hi,

nice work indeed!

I would suggest a new Wiki-Page named "Samples Nest Integration" which we then could list beneath the "Samples" section?

What do you think?

Best, Thomas E.-E.

To unsubscribe from this group and stop receiving emails from it, send an email to openhab+unsubscribe@googlegroups.com.

Fred Bret-Mounet

unread,
Jul 30, 2014, 12:31:24 PM7/30/14
to ope...@googlegroups.com, tho...@openhab.org
Folks, I'm happy to do it the "right" way by creating a binding, but the generated binding stubs scared me!
So with hand holding and peer review, I'm happy to take another stab at it - as long as there is demand and nobody's already working on it...

Otherwise, I'm happy to expand the content of the original email on the wiki.

Let me know!

Thanks

-Fred


To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.

d0t1...@gmail.com

unread,
Oct 21, 2014, 10:22:31 PM10/21/14
to ope...@googlegroups.com, tho...@openhab.org, freed...@gmail.com
Hi Fred,

I've been anticipating a way to tightly tie my Nest into OpenHAB via a binding with full control.  I had previously created a thread on this very topic, which summarizes how I did a crude first cut at this via script calls to an open source python NEST API implementation:

Any updates on Nest OpenHAB binding, anyone?  We should join forces, and get 'er done :)   

All the best,
.

Neil Renaud

unread,
Oct 22, 2014, 4:17:50 AM10/22/14
to ope...@googlegroups.com
I've just got my Nest
thermostat and hoping to get a Nest Protect soon.

I'm happy to help out with binding development.

Neil

Thomas E.-E.

unread,
Oct 22, 2014, 5:30:22 AM10/22/14
to ope...@googlegroups.com
Very great guys! It would be great if you could join forces.

Let us know if we could be of any help!

Best, Thomas E.-E.

Maximilian

unread,
Oct 22, 2014, 8:58:45 AM10/22/14
to ope...@googlegroups.com, freed...@gmail.com
HI,

see here for the sample wiki page:
https://github.com/openhab/openhab/wiki/Sample-nest-thermostate

kr,
Maximilian

Thomas Eichstädt-Engelen

unread,
Oct 22, 2014, 2:19:57 PM10/22/14
to ope...@googlegroups.com
Hi Fred,

what exactly scared you about the generated stubs?

Is it just the anatomy of the binding itself? I would then agree that quite some “boilerplate” stuff is generated but it is generated and the crucial part for the binding developer can be found in the XyzBinding and XyzGenericBindingProvider classes.

Best, Thomas E.-E.

watou

unread,
Oct 24, 2014, 9:20:23 AM10/24/14
to ope...@googlegroups.com, tho...@openhab.org
I've been working on bindings for both Nest and Ecobee thermostats, and support for the Nest Protect will be part of the Nest binding.  I expect to have source available for review for both of them in 2-3 weeks if not sooner.  (I wrote the equivalent "plugins" for the Vera home automation system and I'm deep into the openHAB equivalents at this point.)  Sorry for not having source up for review yet, but I'm almost there.

Regards,
watou
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
For more options, visit https://groups.google.com/d/optout.

d0t1...@gmail.com

unread,
Oct 24, 2014, 11:26:24 AM10/24/14
to ope...@googlegroups.com, tho...@openhab.org
Watou - awesome!  If you would like some help with testing, don't hesitate to reach out - I am more than willing to contribute however possible.  :)

Matt Watson

unread,
Oct 24, 2014, 12:06:35 PM10/24/14
to
I can help as a Nest Thermostat & Protect binding tester too.  I'd offer to help you code it as well, but my coding time is going to be very limited very soon.  You'd likely get some bug fixes coding out of me, but not a ton more.

watou

unread,
Oct 24, 2014, 3:26:31 PM10/24/14
to
When I have a binding ready for test, I will comment here with directions on what to download, etc.  Thanks for help!

Chris Graham

unread,
Oct 24, 2014, 7:15:39 PM10/24/14
to ope...@googlegroups.com
Well, I guess no one is going to need this read-only nest binding I through together over the last 48 hours after reading someone opted not to work on it: https://github.com/CrackerStealth/openhab/tree/nest-binding/bundles/binding/org.openhab.binding.nest

But if anyone wants to play with the binding until Watou finishes his version, have at it.

d0t1...@gmail.com

unread,
Oct 26, 2014, 11:44:37 AM10/26/14
to ope...@googlegroups.com
Very cool, Chris!

This helped me to better understand how OH bindings are written, though with my lacking Java knowledge this looks to be a challenge to develop from scratch.

Thanks a lot for sharing!  It may help Watou and maybe others working on a Nest binding...

While studying the NEST API I was bummed to see we cannot access import metrics via their public API, such as:

  • Nest Thermostat - humidity
  • Nest Protect - light
  • Nest Protect - motion
There are ways to get these values with unofficial implementations, but current public NEST API does not offer support for this.  Guess I'll have to add ZWave and a multi-sensor to achieve the same today.

Best regards,
-Mike

watou

unread,
Oct 26, 2014, 12:02:12 PM10/26/14
to ope...@googlegroups.com, d0t1...@gmail.com
Would it be worth it to openHAB users for there to be a binding that uses the "unofficial" API?  I am thinking of adding just enough abstraction internally to support either interface, but that will take a bit more work.

Pluses: access to quite a bit more information, including humidity, precise temperature in Celsius, battery voltages (thermostat and Protect), etc.?  Even with "unofficial" access, there is no access to motion/presence detection from either device type.  

Minuses: have to put your username/password in your openhab.cfg, unofficial access could cease functioning at any time (no expectation that they won't fundamentally break the interface whenever they choose to, but this means their mobile apps will also break until all users were to upgrade).  

My Vera plugin has continued to use the unofficial API simply because so many useful metrics are missing from the official API.  If/when Nest extends the official API to include the missing information, it is a no-brainer to switch to the official, OAuth2-based API.

d0t1...@gmail.com

unread,
Oct 26, 2014, 5:47:18 PM10/26/14
to ope...@googlegroups.com, d0t1...@gmail.com
Hmmmm, that's a tough call...

Previously when using my custom rolled scripts and the unofficial Nest API (leveraging https://github.com/smbaker/pynest ), Nest actually blocked my account due to over-polling after a few months of use.  They saw the repeated logins and totally blocked my ability to login.  Had to disable my custom OpenHAB/Nest scripts and jump through hoops to get their support to unblock my account.  I'm sure your approach (with both existing Vera and upcoming OpenHAB binding) is much more elegant (updating all OpenHAB metrics at once, vs my crude implementation which polled metrics one at a time resulting in many API calls), but it's still something to consider.  Security concerns of having plain text credentials are relevant here too.  Also I'd expect stuff will likely break going forward as Nest evolves, and building out/supporting the unofficial APIs could create ongoing development work...

I understand your reasoning here though - get all the metrics instead of only what the official API exposes in the interim.   Would be great to have such interoptability, and be to able to switch between the two, but I'd suggest keeping the initial release lean and tailored to only the official API.  Personally I will be reaching out to Nest to request they expand their official API's and add these other important metrics, and implore that everyone interested in this type integration with their Smart Home solution of choice to do the same!

Regardless, I still plan to add numerous ZWave multi-sensors anyway, so Nest's lacking official API is less of an issue for me.  Probably not the same for others just starting off with OpenHAB on a budget though.  Fundamentally I don't like the idea of relying on external web services to monitor my own home!  Local is always better... 

All the best,
.

Chris Graham

unread,
Oct 27, 2014, 2:03:34 AM10/27/14
to ope...@googlegroups.com, d0t1...@gmail.com
To be fair, there may be no direct access to the motion or presence detection in the official API, but there is the "away" JSON key in the "structures" object which can have the values: home, away, auto-away.

From this, you can get some of the same functionality that motion and precence detection directly. Realistically, the motion sensors in the Nest devices were probably never designed to do the same things we would use dedicated motion sensors on our OpenHAB implimentations for.

d0t1...@gmail.com

unread,
Nov 7, 2014, 12:32:34 AM11/7/14
to ope...@googlegroups.com, d0t1...@gmail.com
Watou - how are things progressing?  Anything we can do to help??

Best regards,
.

watou

unread,
Nov 7, 2014, 9:32:24 AM11/7/14
to ope...@googlegroups.com, d0t1...@gmail.com
Sorry for the delay; a work deadline appeared out of nowhere to slow me down.  I am nearly done with that deadline and I am chomping at the bit to plow on to submit both Nest and Ecobee bindings for review.  Again, sorry it's taken me so long.

d0t1...@gmail.com

unread,
Nov 7, 2014, 10:21:32 AM11/7/14
to ope...@googlegroups.com, d0t1...@gmail.com
Got you!  And no need to apologize  :)

Your timing may actually be better, as Nest is expected to release a new version of the app and firmware this week:


No indication this will affect the API, however...

Thanks,
.

Chris Graham

unread,
Nov 12, 2014, 11:39:37 AM11/12/14
to ope...@googlegroups.com, d0t1...@gmail.com

d0t1...@gmail.com

unread,
Nov 12, 2014, 12:13:16 PM11/12/14
to ope...@googlegroups.com, d0t1...@gmail.com
Great news, thanks Chris!

.

unread,
Dec 18, 2014, 10:03:55 PM12/18/14
to ope...@googlegroups.com, d0t1...@gmail.com
Watou - I don't mean to pester, but am curious to hear if you've found time to make progress on this OpenHAB Nest binding... Excited to test it out!  :)

Best regards,
.

watou

unread,
Dec 20, 2014, 4:23:25 AM12/20/14
to d0t1...@gmail.com
My month of November went sideways pretty badly, but at least I've got proper broadband Internet again.  It's the little things....  So sorry for the delay.  I've got the w.i.p. Ecobee binding checked into my fork, but I don't have the Nest ready for that yet.  I hope to have something before the end of the month, but my estimates have been pretty unreliable, so I will forgive you for being skeptical. :)  It will be solid when ready, I can confidently claim that much.

watou

.

unread,
Dec 21, 2014, 8:15:07 PM12/21/14
to ope...@googlegroups.com, d0t1...@gmail.com
All good Watou :)  I have no doubt, and will be patiently awaiting your OH Nest binding.  I'm sure others are too - for me this a final piece to my home automation puzzle:  proper climate control via OH! 

Thanks in advance for everything you are doing here!
.


On Saturday, December 20, 2014 4:23:25 AM UTC-5, watou wrote:
My month of November went sideways pretty badly, but at least I've got proper broadband Internet again.  It's the little things....  So sorry for the delay.  I've got the w.i.p. Ecobee binding checked into my fork, but I don't have the Nest ready for that yet.  I hope to have something before the end of the month, but my estimates have been pretty unreliable, so I will forgive you for being skeptical. :)  It will be solid when ready, I can confidently claim that much.

watou

On Friday, 19 December 2014 03:03:55 UTC, . wrote:

Sterling Taylor

unread,
Dec 28, 2014, 5:32:26 PM12/28/14
to ope...@googlegroups.com, freed...@gmail.com
Where should the GetNest*.js files reside within openhab?
Message has been deleted

.

unread,
Dec 28, 2014, 7:52:14 PM12/28/14
to ope...@googlegroups.com, freed...@gmail.com
Location for my setup is under:

configurations/transform

.

Sterling Taylor

unread,
Dec 28, 2014, 8:52:08 PM12/28/14
to ope...@googlegroups.com, freed...@gmail.com
Thanks all, this indeed works! These scripts can also be modified to get any property from the JSON message. 

--
You received this message because you are subscribed to a topic in the Google Groups "openhab" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openhab/0u1t3xyZlqk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openhab+u...@googlegroups.com.

To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
For more options, visit https://groups.google.com/d/optout.



--
Sterling G Taylor

ari...@nesys.it

unread,
Jan 20, 2015, 5:04:21 AM1/20/15
to ope...@googlegroups.com, freed...@gmail.com
Hi Watou, All

Another guy ready to test here :-)

How is progressing? I can't wait ... :-)

Thanks for your effort

Andrea

watou

unread,
Feb 26, 2015, 12:07:52 PM2/26/15
to ope...@googlegroups.com, freed...@gmail.com
Making progress bit by bit...  I've started updating the wiki:


I should have a pull request ready for testing by mid-March.  Sorry for the delays.

Critiques welcome. :)

Neil Renaud

unread,
Feb 26, 2015, 4:53:35 PM2/26/15
to ope...@googlegroups.com, freed...@gmail.com
Hi,

This weekend I decided to create a Nest binding using the Firebase Java APIs.



It's not been tested for very long by me but want to open it up early for testing. Anyone that wants to give it a go feel free and let me know of any issues. 

Neil
Reply all
Reply to author
Forward
0 new messages