getEnergyLatest() public method

public getEnergyLatest ( $serial_number = null )
Ejemplo n.º 1
0
            // Target humidity has changed
            $nest->setHumidity(intval($target));
        }
    }
    //-------------------------------------------circulation mode-------------------------------------------------------------------------
    // If circulate air mode is allowed, check to see if inside temp is over setpoint by 1.4 (circbuffer) degrees and that all other criteria are met. Enable fan until criteria are not met.
    if ($circmode == true and $low_target_temp + $circbuffer - $infos->current_state->temperature <= 0 and round($low_target_temp) >= $circtemp and $infos->current_state->fan == 0 and $infos->current_state->temperature - $circobuffer > $locations[0]->outside_temperature) {
        $nest->setFanModeOnWithTimer(FAN_TIMER_15M);
        //run fan for 15 minutes
    } else {
        $nest->setFanMode(FAN_MODE_AUTO);
        //set fan back to auto.
    }
} elseif ($datatype === 'daily') {
    //Used to get Nest energy reports. Includes 10 days of data.
    $energy = $nest->getEnergyLatest();
    //Loop through the array of days and get the data for eac day
    $yesterday_date = date("Y-m-d", time() - 60 * 60 * 24);
    //calculate yesterday's date. We can't get degree days for today.
    $days = $energy->objects[0]->value->days;
    //print_r($weather);//Print array of days to browser for debug purposes
    foreach ($days as $day) {
        //We can only get degree days for yesterday or older.
        $active_date = date("Ymd", strtotime($day->day));
        //Change date format for weather underground api
        //print_r($active_date);//Print active date for debug purposes
        //Check to see if there is already a record for this day.
        $result = $con->query("SELECT date FROM energy_reports WHERE date = '" . $day->day . "'");
        //if there is no entry and the day is older than yesterday, get the data from weather underground
        if ($result->num_rows == 0 and strtotime($active_date) < strtotime($yesterday_date)) {
            //if there is no record for this date, get degree days from weather underground.
Ejemplo n.º 2
0
echo "Device information:\n";
$infos = $nest->getDeviceInfo();
jlog($infos);
echo "----------\n\n";
echo "Device schedule:\n";
// Returns as array, one element for each day of the week for which there has at least one scheduled event.
// Array keys are a textual representation of a day, three letters, as returned by `date('D')`. Array values are arrays of scheduled temperatures, including a time (in minutes after midnight), and a mode (one of the TARGET_TEMP_MODE_* defines).
$schedule = $nest->getDeviceSchedule();
jlog($schedule);
echo "----------\n\n";
echo "Device next scheduled event:\n";
$next_event = $nest->getNextScheduledEvent();
jlog($next_event);
echo "----------\n\n";
echo "Last 10 days energy report:\n";
$energy_report = $nest->getEnergyLatest();
jlog($energy_report);
echo "----------\n\n";
/* Helper functions */
function json_format($json)
{
    $tab = "  ";
    $new_json = "";
    $indent_level = 0;
    $in_string = false;
    $json_obj = json_decode($json);
    if ($json_obj === false) {
        return false;
    }
    $json = json_encode($json_obj);
    $len = strlen($json);
 
 	// Google maps api URL
 	// This is required to get the timezone offset from the current user's location
 	$google_json = "https://maps.googleapis.com/maps/api/timezone/json?location=" . $user_lat . "," . $user_long . "&timestamp=" . $timestamp;
 	$google_time = json_decode(file_get_contents($google_json));
 	$dst_offset = $google_time->dstOffset;
 	$raw_offset = $google_time->rawOffset;
 	$timestamp_offset = ( $dst_offset + $raw_offset ) / 60 / 60;
 	//$local_time = $timestamp + $dst_offset + $raw_offset;
 */
 $nest = new Nest($nest_username, $nest_password_decrypt);
 $nest_devices = $nest->getDevices();
 foreach ($nest_devices as $device) {
     // Gather information from the Nest class object for storage
     $infos = $nest->getDeviceInfo($device);
     $energy = $nest->getEnergyLatest($device);
     $weather_nest = $nest->getWeather($user_location);
     // Gather the device information for storage
     $device_serial_number = $infos->serial_number;
     $nest_location = $infos->where;
     $device_name = $infos->name;
     $battery_level = $infos->current_state->battery_level;
     // Outside weather pulled from the nest class
     $outside_humidity = $weather_nest->outside_humidity;
     $outside_temperature = $weather_nest->outside_temperature;
     // Inside weather pulled from the nest class
     $temperature = $infos->current_state->temperature;
     $humidity = $infos->current_state->humidity;
     // Current running statistics for the graph
     $ac = $infos->current_state->ac == "" ? 0 : $infos->current_state->ac;
     $heat = $infos->current_state->heat == "" ? 0 : $infos->current_state->heat;