Last active
July 1, 2016 04:11
-
-
Save juanqui/f0daa2739f7d4a90059cd288b8309bd4 to your computer and use it in GitHub Desktop.
Get Temperatures From Nest Thermostats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var request = require('request'); | |
// request login | |
request({ | |
url: 'https://home.nest.com/user/login', | |
method: 'POST', | |
headers: { | |
'user-agent': 'Nest/2.1.3 CFNetwork/548.0.4', | |
'X-nl-protocol-version': '1', | |
'Content-Type': 'application/json' | |
}, | |
json: { | |
"email": "<email>", // CHANGE THIS! | |
"password": "<password>" // CHANGE THIS! | |
} | |
}, (e, r, body) => { | |
let user = body.user; | |
let accessToken = body.access_token; | |
// compute url | |
let statusURL = body.urls.transport_url + '/v2/mobile/' + user; | |
// request status | |
request({ | |
url: statusURL, | |
method: 'GET', | |
headers: { | |
'X-nl-user-id': user, | |
'Authorization': 'Basic ' + accessToken, | |
'user-agent': 'Nest/2.1.3 CFNetwork/548.0.4', | |
'X-nl-protocol-version': '1' | |
} | |
}, (e, r, body) => { | |
body = JSON.parse(body); | |
// loop through devices, collect temperature | |
for (let deviceKey in body.shared) { | |
let data = body.shared[deviceKey]; | |
console.log(deviceKey, data.target_temperature * 9 / 5 + 32, data.current_temperature * 9 / 5 + 32) | |
} | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment