-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnest-humidity.php
executable file
·55 lines (46 loc) · 1.42 KB
/
nest-humidity.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/php
<?php
////////////////////////////
// Max automatic target humidity levels
$maxhumidity=40;
// Your NEST credentials
define('USERNAME', '');
define('PASSWORD', '');
// Don't change this unless you're very very sure, or you may cause damage to your home!
$safelimit=60;
/////////////////////////////////////////
//// Nothing to change below here //////
require_once('nest.class.php');
$nest = new Nest();
function setHumidity($nest, $humidity) {
$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);
?>