setHumidity() public method

public setHumidity ( $humidity, $serial_number = null )
Ejemplo n.º 1
0
    }
    //-------------------------------------------------------------------------------------------------------------------
    //Insert Current Values into Nest Database Table
    //if you add addional values to the NEST API, you need to also add them here so that they will be logged in the database.
    // you also need to add the correctly named column to the database structure FIRST, or the php script will return an error.
    $sql = 'INSERT INTO nest (log_datetime, location, outside_temp, outside_humidity, away_status, leaf_status, current_temp, current_humidity, temp_mode, low_target_temp, high_target_temp, time_to_target, target_humidity, heat_on, humidifier_on, ac_on, fan_on, battery_level, is_online, alt_heat, aux_threshold, hvac_wires) VALUES (NOW(), "' . $postal_code . '", "' . $locations[0]->outside_temperature . '", "' . $locations[0]->outside_humidity . '", "' . $locations[0]->away . '", "' . $infos->current_state->leaf . '", "' . $infos->current_state->temperature . '", "' . $infos->current_state->humidity . '", "' . $infos->current_state->mode . '", "' . $low_target_temp . '", "' . $high_target_temp . '", "' . $infos->target->time_to_target . '","' . $infos->target->humidity . '","' . $infos->current_state->heat . '","' . $infos->current_state->humidifier . '","' . $infos->current_state->ac . '","' . $infos->current_state->fan . '","' . $infos->current_state->battery_level . '","' . $infos->network->online . '", "' . $infos->current_state->alt_heat . '","' . $aux_converted . '","' . $infos->current_state->hvac_wires . '")';
    $result = $con->query($sql) or trigger_error('SQL: ' . $sql . ' Error: ' . $con->error, E_USER_ERROR);
    //Set the humidity level if enabled.
    if ($set_humidity) {
        $exttemp = $nest->temperatureInCelsius($locations[0]->outside_temperature);
        // Drop target humidity 5% for every 5degree C drop below 0
        $target = max(0, $maxhumidity + $exttemp);
        $target = round(min($target, $maxhumidity, 60));
        if (abs($target - $infos->target->humidity) >= 1) {
            // 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
Ejemplo n.º 2
0
    }
    // $outsideTemp = -10;
    // Calculate inside dewpoint
    $currentDewpoint = calculateDewpoint($insideTemp, $insideHumidity);
    // Determine target inside humidity level
    $targetHumidityAdjusted = adjustedHumidity($insideTemp, $outsideTemp, $insideHumidity);
    // Sanity check in case the humidifier (e.g. steam) has caused the temperature to rise too much
    if (is_numeric($heat) && $insideTemp - $heat >= MAX_HEATING_DELTA) {
        $targetHumidityAdjusted = MIN_HUMIDITY;
    }
    echo "mode={$mode}\n";
    echo "temp(inside)={$insideTemp}\n";
    echo "temp(outside)={$outsideTemp}\n";
    echo "humidity(inside)={$insideHumidity}\n";
    echo "dewpoint(inside)={$currentDewpoint}\n";
    echo "target(max_humidity)={$targetHumidityCurrent}\n";
    echo "new_target(max_humidity)={$targetHumidityAdjusted}\n";
    // Adjust max humidity level if necessary
    if ($targetHumidityAdjusted != $targetHumidityCurrent) {
        $nest->setHumidity($targetHumidityAdjusted, THERMOSTAT_SERIAL);
        echo "humidity changed from {$targetHumidityCurrent} to {$targetHumidityAdjusted}\n";
        // Send email when Humidity changes
        $to = '*****@*****.**';
        $subject = 'Nest Humidity';
        $message = "Humidity changed from {$targetHumidityCurrent} to {$targetHumidityAdjusted}\n\nmode={$mode}\ntemp(inside)={$insideTemp}\ntemp(outside)={$outsideTemp}\nhumidity(inside)={$insideHumidity}\ndewpoint(inside)={$currentDewpoint}\nhumidity(current)={$targetHumidityCurrent}\nhumidity(target)={$targetHumidityAdjusted}\n";
        $headers = 'From: your@email.com' . "\r\n" . 'Reply-To: your@email.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
        mail($to, $subject, $message, $headers);
    }
} catch (Exception $e) {
    echo "Exception: " . $e->getMessage() . "\n";
}