23 Comments Already

commenter
Matthew Said,
November 30th, 2012 @5:34 pm  

Great resource, thanks so much for posting this! I’ve now purchased 6 of these for a small commercial office building I manage, because of your Node API. I’m hoping to runs some basic scheduled tasks to start the fans in the morning to equalize the temps across shared rooms and give us some white noise and then switch them back to auto at the end of the day…

When I run your sample, it works great on the first call for the Temp and Target but after the setTimeout though, the subsequent calls return a the key-value pairs rather than the formatted temperature lines for each. I haven’t dug in yet but found it curious. Thanks again.

commenter
watou Said,
December 8th, 2012 @1:36 pm  

I’m beyond impressed with your sleuthing in figuring out nest.com communication, and your slick API. But I am wondering if you discovered how to change the mode of the thermostat between heat, cool, range and off? I see the target_temperature_type set to those values, but I don’t know how the clients change it. Or, do you have pointers for how you did your sleuthing, so I could dig in myself and find the answer? Many thanks for the work and sharing it with us.

commenter
Aaron Said,
December 11th, 2012 @6:56 am  

My steps were a bit more than I’d like to put in a comment …. I should probably do a blog post about that … sometime. :)

Some of the API is shared between the web browser version and the mobile applications. Have you tried looking at the traffic at all during a switch when using the web interface (which is far easier to do with modern browsers from IE9 to Chrome to Firefox.

commenter
watou Said,
December 12th, 2012 @5:03 pm  

I would appreciate a post some day about your techniques for watching this kind of traffic. Your explanations are very clear and easy to follow.

Turns out it was a simple /v2/put/shared… with {“target_temperature_type”:”heat”} etc. Much simpler than I thought it was going to be.

I’ve written a plugin for the Vera home automation system so it can monitor and control the thermostats and home/away, along with all of Vera’s support for controlling lights, cameras, other HVAC equipment and everything else.

Thanks again, Aaron.

commenter
Yair Said,
December 20th, 2012 @9:46 am  

This is great.

I am seeing a weird thing. When I play with the API the thermostat disconnects from the network. I am using a nest V1 and when I looked at the traffic from web sites things look a bit different. Do you work with the V1 thermostat or the V2? If not I will create the V1 version of you library for those owning the V1 thermostat

commenter
Aaron Said,
December 20th, 2012 @9:48 am  

V1 (although I thought the firmware was the same on V1 & V2?)

commenter
watou Said,
December 20th, 2012 @9:51 am  

I have an original Nest and it appears to work properly with this code. However, what is the battery level after lots of poking at the thermostat? If it gets close to 3.6 volts, it may stop the proximity function, turn off wi-fi, and then turn itself off, too.

commenter
Aaron Said,
December 20th, 2012 @10:00 am  

It accesses Nest’s servers for the data. I may be wrong, but I didn’t believe accessing this data caused any additional load on the thermostat in any way. The thermostats are always poking/polling the servers to update status and check for modifications to settings.

commenter
watou Said,
December 20th, 2012 @10:20 am  

My thinking was that lots of changing the temperature setpoints, mode, etc. could cause an accelerated drain on battery power, especially if it has to flip its relays. But that’s only a guess. When I was first writing the home automation gateway plugin, I noticed its proximity function briefly stopped working, as it would do if the battery were depleted. But this is all just a guess. Since then, I’ve not seen the issue again nor heard any complaints from people using the plugin (http://cocu.la/vera/nest/README.md) with their v1 and v2 thermostats.

commenter
Charlie Said,
December 30th, 2012 @2:54 am  

Any way to set the nest to away and home using this API?

commenter
watou Said,
December 30th, 2012 @10:56 am  

Charlie, this code fragment (written in Lua) could be ported to Javascript in the Node API to set your thermostat(s) to home or away. The ‘away’ variable should be true or false.

local res = {}
local data = ‘{“away_timestamp”:’ .. tostring(os.time()) .. ‘,”away”:’ .. tostring(away) .. ‘,”away_setter”:0}’
local headers = {["user-agent"] = NEST_UA,
["Authorization"] = “Basic ” .. session.access_token,
["X-nl-protocol-version"] = “1″,
["content-length"] = string.len(data),
["content-type"] = “application/json”}
local url = { url = session.transport_url .. “/v2/put/structure.” .. structure_id,
protocol = “sslv3″,
method = “POST”,
source = ltn12.source.string(data),
sink = ltn12.sink.table(res),
headers = headers }
local one, code, headers, status = https.request(url)

commenter
Aaron Said,
December 30th, 2012 @2:41 pm  

@Charlie, I just added setHome/setAway to the API on Github (and via npm).

commenter
Charlie Said,
December 30th, 2012 @3:37 pm  

Thanks. I tried to implement something similar, but your solution is more robust. Do you know what away_setter is for?

commenter
Charlie Said,
December 30th, 2012 @3:51 pm  

I’m getting an error. You should remove the parens in this line and the next line:
https://github.com/wiredprairie/unofficial_nodejs_nest/blob/master/index.js#L474

commenter
Aaron Said,
December 30th, 2012 @4:11 pm  

D’oh! Parens added by WebStorm’s auto function-needs-parens feature. I guess I must have done that after the last test. Fixed on GitHub and npm.

commenter
Aaron Said,
December 30th, 2012 @4:14 pm  

I’ve never seen it set to anything other than 0.

commenter
Charlie Said,
December 30th, 2012 @4:28 pm  

Cool. I just set up my home automation to put my nest to away mode whenever I put my alarm to away. I found the auto-away a bit too slow to figure it out. So this should work much better. Thanks!

commenter
Aaron Said,
December 30th, 2012 @7:41 pm  

That’s very cool Charlie!

commenter
Tim Nicholson Said,
April 21st, 2013 @10:00 am  

Thanks so much for posting this. It has been instrumental to me in writing a simpler PHP/Curl based program to read the thermostat’s temperatures.

I’m finding very strange timestamp values in the json response, though. Do you have any idea which key has the actual timestamp that the thermostat last reported its temperature? I would have assumed the “shared” key which is the only place where the current temp is stored. However, the timestamps have way too high of numbers in them reporting the year as 44971 instead of 2013. The timestamps in the “track” and other keys are similarly large.

commenter
Aaron Said,
April 21st, 2013 @10:07 am  

The time stamps I’ve looked at are all JavaScript friendly time stamps: new Date(1349697004000).toString() => ‘Mon Oct 08 2012 06:50:04 GMT-0500 (Central Daylight Time)’ This post on stackoverflow might help: http://stackoverflow.com/questions/11897331/javascript-gettime-to-php-date (JavaScript includes milliseconds)

commenter
April 26th, 2013 @1:05 pm  

Thanks, Aaron. Javascript must include 3 decimal points on the time or something as compared to PHP. What I ended up doing was just dividing the timestamp by 1000 and then it works fine with the PHP date function.

I’ve now got my PHP program working pretty nicely in that it outputs either RSS format or HTML format for displaying in a browser. I’ve got it so I can pass in warning temperatures for low and high and it will include a warning message in the output.

My goal is to get IfThisThenThat (ifttt.com) to monitor the RSS for warning and text me if one is triggered. It should check periodically for a new item in the RSS feed and check for the keyword “Warning” without me having to run my PHP recursively.

Thanks again for turning me on to the Nest API and providing the details needed to be able to make sense of the data! I didn’t want to have to mess with node.js and this has been a fun little PHP project.

Pingback & Trackback
mygif
October 12th, 2012 @7:10 am  
mygif
November 9th, 2012 @7:14 am  

Related Post

Please Leave Your Comments Below

Please Note: All comments are moderated, so it may take some time before your comment appears.