function performLogin(email, password) { | |
var payload = { | |
"username" : email, | |
"password" : password | |
}; | |
var options = { | |
"method" : "post", | |
"payload" : payload | |
}; | |
var response = JSON.parse(UrlFetchApp.fetch('https://home.nest.com/user/login', options).getContentText()); | |
if ('error' in response) { | |
throw "Invalid login credentials"; | |
} | |
return response | |
} | |
function getData() { | |
var login_auth = performLogin('<YOUR NEST USERNAME>','<YOUR NEST PASSWORD>'); | |
var headers = { | |
"Authorization" : 'Basic '+login_auth['access_token'], | |
"X-nl-user-id" : login_auth['userid'], | |
"X-nl-protocol-version" : '1', | |
'Accept-Language': 'en-us', | |
'Connection' : 'keep-alive', | |
'Accept' : '*/*', | |
}; | |
var options = { | |
'headers' : headers | |
}; | |
var request=UrlFetchApp.fetch(login_auth['urls']['transport_url']+'/v2/mobile/user.'+login_auth['userid'], options); | |
var result=JSON.parse(request.getContentText()); | |
var structure_id = result['user'][login_auth['userid']]['structures'][0].split('.')[1] | |
var device_id = result['structure'][structure_id]['devices'][0].split('.')[1] | |
var current_temp = result["shared"][device_id]["current_temperature"]; | |
var target_temp = result["shared"][device_id]["target_temperature"]; | |
var humidity = result["device"][device_id]["current_humidity"]/100; | |
var auto_away = result["shared"][device_id]["auto_away"]; | |
var heater_state = result["shared"][device_id]["hvac_heater_state"]; | |
Logger.log("Current Temp: "+current_temp+", Target Temp: "+ target_temp +", Humidity: "+ humidity*100 + "%" ); | |
var time = new Date(); | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = ss.getSheets()[0]; | |
// Appends a new row with 3 columns to the bottom of the | |
// spreadsheet containing the values in the array | |
sheet.appendRow( [ time, current_temp, target_temp, humidity, heater_state, auto_away ] ); | |
} |
This comment has been minimized.
This comment has been minimized.
Any idea why im getting this error? |
This comment has been minimized.
This comment has been minimized.
Possibly the entire site got changed and this no longer works |
This comment has been minimized.
This comment has been minimized.
I just got this code setup and I have 2 nest in two homes under one login. I wondering if you know how I would tell it what device ID to look at. It is just picking one and its not the one I want. I don't understand what part of the code I would update to pick the device. Any help would be awesome. Thanks |
This comment has been minimized.
This comment has been minimized.
Like @taylorbrinton, I have two Nests and all variants of this code I've found so far seem to ignore that potential. Not sure which one it's keying off yet, or if that would potentially change in the future at random. |
This comment has been minimized.
This comment has been minimized.
Getting an error now. Anyone else seeing this? |
This comment has been minimized.
This comment has been minimized.
@brywhi You are over your hourly rate limit however I cannot find what are the imposed limits. |
This comment has been minimized.
This comment has been minimized.
Does this still work? I assume the var payload section below is for my google username and password?? Then the var login auth is for my nest auth as follows: Thanks |
This comment has been minimized.
This comment has been minimized.
I'm having the same issue @plinley. I don't think this script will work if you migrated your account to Google. |
This comment has been minimized.
This comment has been minimized.
I've never tried with a Google migrated account. It might need changing to get it working. |
This comment has been minimized.
This comment has been minimized.
I'm having the same issue with a "migrated to Google" account. Thanks |
This comment has been minimized.
Very cool! Thanks for this... I added an outside temperature fetch from OpenWeatherMap.org here: https://gist.github.com/davidrea/17ba3aebfa65c933daca (don't think Gists support PRs though...)