<?php require_once 'nest.class.php'; // Your Nest username and password. $username = '******'; $password = '******'; // The timezone you're in. // See http://php.net/manual/en/timezones.php for the possible values. date_default_timezone_set('America/Montreal'); // Here's how to use this class: $nest = new Nest($username, $password); echo "Location information:\n"; $locations = $nest->getUserLocations(); jlog($locations); echo "----------\n\n"; echo "Devices list (thermostats):\n"; $devices_serials = $nest->getDevices(); jlog($devices_serials); echo "----------\n\n"; echo "Devices list (Nest Protect):\n"; $protects_serials = $nest->getDevices(DEVICE_TYPE_PROTECT); jlog($protects_serials); echo "----------\n\n"; echo "Device information:\n"; $infos = $nest->getDeviceInfo($devices_serials[0]); jlog($infos); echo "----------\n\n"; echo "Current temperature:\n"; printf("%.02f degrees %s\n", $infos->current_state->temperature, $infos->scale); echo "----------\n\n"; echo "Setting target temperature...\n";
{ $target = intval($humidity); if ($target > $GLOBALS['safelimit']) { echo "Error: Requested target exceeds safety limit.\n"; return 1; } elseif ($target < 0) { $target = 0; } echo "Setting humidity target to " . $target . "%\n"; $success = $nest->setHumidity($target); return $success; } if (count($argv) == 1) { $infos = $nest->getDeviceInfo(); echo "Current humidity level: " . $infos->current_state->humidity . "%\n"; } elseif ($argv[1] == "auto") { $locationinfo = $nest->getUserLocations(); $exttemp = round($locationinfo[0]->outside_temperature, 0); if ($exttemp >= 0) { $autotarget = $maxhumidity; } else { // Drop target humidity 5% for every 5degree C drop below 0 $autotarget = $maxhumidity - 5 * abs($exttemp / 5); } $success = setHumidity($nest, $autotarget); } elseif (is_numeric($argv[1])) { $success = setHumidity($nest, intval($argv[1])); } else { echo "Invalid humidity value entered. Must be either 'auto' or a value between 0 and " . $safelimit . ".\n"; } exit(0);