Nest announces smart home API

General discussion about Open Source Automation
Message
Author
rojolondon
Posts: 11
Joined: Sun Jan 25, 2015 9:34 am

Re: Nest announces smart home API

#11 Post by rojolondon » Mon Jan 26, 2015 2:14 am

@fiveHellions, also looking forward to a nest plug in! Good work!

I'm new to OSA, so also wanted to say Hello!

fiveHellions
Posts: 86
Joined: Wed Feb 06, 2013 12:12 pm

Re: Nest announces smart home API

#12 Post by fiveHellions » Thu Jan 29, 2015 8:01 am

Automate wrote:The Nest thermostat does have a USB port which allows some hacking. Nest sounds like they are going to leave this open for developers to use as they see fit. My hope is that someone develops some software to run on the thermostat and opens up some kind of web service API so that other automation can interact with the Nest without going over the internet.
I would love to eventually be able to talk to nest directly instead of through the official API and cloud. Let me know if you see any hackers out there make headway in this. I can incorporate it into the plugin as well.

fiveHellions
Posts: 86
Joined: Wed Feb 06, 2013 12:12 pm

Re: Nest announces smart home API

#13 Post by fiveHellions » Thu Jan 29, 2015 9:56 am

Here is the first beta version of the Nest plugin.

After installing the plugin you will need to go to https://home.nest.com/login/oauth2?clie ... tate=STATE. You will log in to your nest account and give access to the OSA client. You will then be given a pin code. Copy this code to the Pin property of your Nest object in OSA.

After you have provided a Pin run the 'Get an Access Token' method on your Nest Object. This will trade the Pin code for an access token. After that it will get your Nest data and automatically create objects for your structures, thermostats and smoke detectors.

It uses REST Streaming to get real time updates without polling. But there are times when the connection is closed and the updates stop. To compensate I pull the data every 10 minutes and compare to what we have. If we are out of date then I restart the streaming.

Nest has some weird rules about when you can update different fields. For example to set the target temp your structure must be set to 'Home' otherwise it will fail. And since we are using the REST API instead of one of the firebase client platforms (IOS or Android) there is no helpful error text as to why it failed. I've tried to provide warnings for when something your trying to do may not work. But you should consult this page (https://www.developer.nest.com/document ... rror-codes) if your getting errors to see if your violating one of their rules. I go ahead and try the update even after I give the warning just in case our data is out of date.
Attachments
Nest.osapp
Nest Plugin
(214.77 KiB) Downloaded 90 times

Automate
Posts: 1691
Joined: Sat Dec 11, 2010 1:44 pm
Location: US

Re: Nest announces smart home API

#14 Post by Automate » Thu Jan 29, 2015 3:10 pm

Great, started working right away. I am getting a few errors in the log though. I'll PM you the log

rojolondon
Posts: 11
Joined: Sun Jan 25, 2015 9:34 am

Re: Nest announces smart home API

#15 Post by rojolondon » Fri Jan 30, 2015 6:29 am

Great work fiveHellions! I gave it ago straight away and it started reading the info from my thermostat straight away. Can't seem to send anything back, executing the methods doesn't seem to do anything. Tried most things like setting to away or setting the target temp.

Do you want any logs from me? I'm in the UK so we don't have cooling or fan function, just heat. Never warm enough for cooling! :(

Don't seem to get any errors under the NEST log, just getting smoke alarm data but i don't have the protect so guessing that's that. The only other thing is data doesn't match. Our streaming updates may be stopped. Lets start them back. but I'm guessing that's it restarting the stream?

Good work never the less! Thanks!

rojolondon
Posts: 11
Joined: Sun Jan 25, 2015 9:34 am

Re: Nest announces smart home API

#16 Post by rojolondon » Fri Jan 30, 2015 6:47 am

rojolondon wrote:Can't seem to send anything back, executing the methods doesn't seem to do anything. Tried most things like setting to away or setting the target temp.
Maybe this has something to do with it...?

01/30/2015 02:41:53.123 PM - Starting Rest Interface
01/30/2015 02:41:55.666 PM - Error starting RESTful web service: HTTP could not register URL http://+:8732/api/. Another application has already registered this URL with HTTP.SYS.


I will work on that, strange as there is nothing else registered to 8732. I will work on this anyway and see what happens.

fiveHellions
Posts: 86
Joined: Wed Feb 06, 2013 12:12 pm

Re: Nest announces smart home API

#17 Post by fiveHellions » Mon Feb 02, 2015 11:44 am

Thanks for the feedback guys. I've posted a new version below.


Automate, I see a couple of problems in the logs.

1) the last connection time isn't matching causing the streaming to be restarted even though it is still running. This results in multiple change notifications every time data is updated. The problem is once I store the value in OSA as a date when I retrieve it it no longer matches the string I get from NEST. I didn't catch this one because on the virtual devices developers can set up, the last connection field is always blank. I now format both date values the same so they will match. I'm also now converting from the UTC time that they give back to the users local time. Hopefully I coded the date stuff right. Hard to test it without the real device.

2) for some reason it can't find an object with a matching address (using OSAEObjectManager.ObjectExists(id)) so it goes to add it but fails because it already exists. Can you check your objects and make sure they have an address that matches what is in the logs? Maybe just the name matches but the address is blank or something? I added more logging to try and figure this one out.


Rojolondon, I think your problem is that the objects aren't owned by the Nest pluggin. In the new version I've added code to update the object types and set their owner to NEST. I think this stems from the nest object not existing when the object types get created. So once you install the new version try it again.

Do you ever see "API - ObjectAdd failed. Object with same name or address already exists" in your logs? or is Automate the only one having that problem?
Attachments
Nest.osapp
(215.13 KiB) Downloaded 87 times

rojolondon
Posts: 11
Joined: Sun Jan 25, 2015 9:34 am

Re: Nest announces smart home API

#18 Post by rojolondon » Tue Feb 03, 2015 12:51 am

fiveHellions, it works perfectly for me now! THANKS! All controls and readings are working correctly.
I don't seem to be getting any errors, all i get is API - ObjectAdded successfully

I will keep playing with it and let you know if i find any bugs but so far so good!

Cheers

Automate
Posts: 1691
Joined: Sat Dec 11, 2010 1:44 pm
Location: US

Re: Nest announces smart home API

#19 Post by Automate » Tue Feb 03, 2015 5:52 am

Should there be methods for setting the Home / Away status?

Also, is there a property to indicate the thermostat is currently telling the heat or cooling to energize?

fiveHellions
Posts: 86
Joined: Wed Feb 06, 2013 12:12 pm

Re: Nest announces smart home API

#20 Post by fiveHellions » Tue Feb 03, 2015 7:19 am

The Nest Structure object should have methods to set the house to home or away. This is done on a per house basis and not a per thermostat.

Unfortunately Nest doesn't provide information on whether the system is currently running. With some programming I could probably guess at this based on the mode and the target temps and the ambient temp. But it would just be a guess and not 100% accurate. It still might be worth having for analytics even if it is just a guess. Let me know if you want me to include a property or event that guesses when it is actively heating/cooling.

How are your logs looking? Are you still getting API error trying to re-add objects that already exist?

Post Reply