A HUGE thank you to Gene in the forums here for pointing me straight. First off, I know just enough to do up these working examples. I’m very familiar with Google Sheets and Apps Scripts, but know very little about APIs and how to make these API calls to Rachio. After tons of Googling, I was able to get a response back from my Rachio and things went quick after that. I work best with examples and figured I’d post mine here so maybe someone else can benefit.
If you have a better way to do this or some more examples I haven’t done up yet, PLEASE add a comment.
This assumes you have a working knowledge of Google Apps Scripts. Simply paste these into a blank script and work your way down the list. You’ll need the info you get in the first few to run the ones at the bottom. To get the info that’s returned, go to View / Logs. Some of the info is kind of buried, but easy to pick it out.
function GetPersonID() {
var APIKey = “INSERT_YOUR_API_KEY”;
var url = “https://api.rach.io/1/public/person/info”;
var headers = {
“contentType”: “application/json”,
“headers”:{“Authorization”: "Bearer " + APIKey}
};
var response = UrlFetchApp.fetch(url, headers);
var data = JSON.parse(response.getContentText());
Logger.log(data);
}
function GetDeviceID() {
var APIKey = “INSERT_YOUR_API_KEY”;
var PersonID = “INSERT_YOUR_PERSON_ID”
var url = “https://api.rach.io/1/public/person/” + PersonID;
var headers = {
“contentType”: “application/json”,
“headers”:{“Authorization”: "Bearer " + APIKey}
};
var response = UrlFetchApp.fetch(url, headers);
var data = JSON.parse(response.getContentText());
Logger.log(data);
}
function GetZones() {
//HERE YOU’RE LOOKING FOR THE ZONE ID’S. IT SEEMED LIKE I ONLY GOT ZONES IN MY MAIN SCHEDULE?
var APIKey = “INSERT_YOUR_API_KEY”;
var DeviceID = “INSERT_YOUR_DEVICE_ID”
var url = “https://api.rach.io/1/public/device/”+DeviceID;
var headers = {
“contentType”: “application/json”,
“headers”:{“Authorization”: "Bearer " + APIKey}
};
var response = UrlFetchApp.fetch(url, headers);
var data = JSON.parse(response.getContentText());
Logger.log(data);
}
function ZoneInfo() {
//THIS WILL GIVE YOU MORE DETAILED INFO ABOUT THE ZONE AND CONFIRM WHAT ZONE EACH ID IS POINTED TO
var APIKey = “INSERT_YOUR_API_KEY”;
var ZoneID = “INSERT_A_ZONE_ID”
var url = “https://api.rach.io/1/public/zone/”+ZoneID;
var headers = {
“contentType”: “application/json”,
“headers”:{“Authorization”: "Bearer " + APIKey}
};
var response = UrlFetchApp.fetch(url, headers);
var data = JSON.parse(response.getContentText());
Logger.log(data);
}
function ZoneStart() {
var APIKey = “INSERT_YOUR_API_KEY”;
var ZoneID = “INSERT_A_ZONE_ID”
// Make a POST request with a JSON payload.
var data = {
‘id’: ZoneID,
‘duration’: 60 // value in seconds; required
};
var options = {
‘method’ : ‘put’,
‘contentType’: ‘application/json’,
‘headers’:{‘Authorization’: 'Bearer ’ + APIKey},
// Convert the JavaScript object to a JSON string.
‘payload’ : JSON.stringify(data)
};
var response = UrlFetchApp.fetch(‘https://api.rach.io/1/public/zone/start’, options);
var data = JSON.parse(response.getContentText());
Logger.log(data);
}
function ZoneStartMultiple() {
//I WANTED THE ABILITY TO CYCLE SO I NEEDED TO CALL EXTRA ZONES THAT AREN’T ACTUALLY USED. I JUST SEND A DURATION OF 0 AND IT SEEMS TO WORK
var APIKey = “INSERT_YOUR_API_KEY”;
var ZoneID1 = “INSERT_A_ZONE_ID”
var ZoneID2 = “INSERT_A_ZONE_ID”
var ZoneID3 = “INSERT_A_ZONE_ID”
var ZoneID4 = “INSERT_A_ZONE_ID”
var ZoneID5 = “INSERT_A_ZONE_ID”
var ZoneID6 = “INSERT_A_ZONE_ID”
var ZoneID7 = “INSERT_A_ZONE_ID”
var ZoneID8 = “INSERT_A_ZONE_ID”
// Make a POST request with a JSON payload.
var data = { “zones” : [
{
‘id’: ZoneID1,
‘duration’: 30,
‘sortOrder’ : 0
},
{
‘id’: ZoneID2,
‘duration’: 0,
‘sortOrder’ : 1
},
{
‘id’: ZoneID3,
‘duration’: 0,
‘sortOrder’ : 2
},
{
‘id’: ZoneID4,
‘duration’: 0,
‘sortOrder’ : 3
},
{
‘id’: ZoneID5,
‘duration’: 0,
‘sortOrder’ : 4
},
{
‘id’: ZoneID6,
‘duration’: 0,
‘sortOrder’ : 5
},
{
‘id’: ZoneID7,
‘duration’: 0,
‘sortOrder’ : 6
},
{
‘id’: ZoneID8,
‘duration’: 0,
‘sortOrder’ : 7
},
{
‘id’: ZoneID1,
‘duration’: 0,
‘sortOrder’ : 9
},
{
‘id’: ZoneID2,
‘duration’: 0,
‘sortOrder’ : 10
},
{
‘id’: ZoneID3,
‘duration’: 0,
‘sortOrder’ : 11
},
{
‘id’: ZoneID4,
‘duration’: 0,
‘sortOrder’ : 12
},
{
‘id’: ZoneID5,
‘duration’: 0,
‘sortOrder’ : 13
},
{
‘id’: ZoneID6,
‘duration’: 0,
‘sortOrder’ : 14
},
{
‘id’: ZoneID7,
‘duration’: 0,
‘sortOrder’ : 15
},
{
‘id’: ZoneID8,
‘duration’: 0,
‘sortOrder’ : 16
}
]};
var options = {
‘method’ : ‘put’,
‘contentType’: ‘application/json’,
‘headers’:{‘Authorization’: 'Bearer ’ + APIKey},
// Convert the JavaScript object to a JSON string.
‘payload’ : JSON.stringify(data)
};
var response = UrlFetchApp.fetch(‘https://api.rach.io/1/public/zone/start_multiple’, options);
var data = JSON.parse(response.getContentText());
Logger.log(data);
}