Thanks! There is an update that I begged for to stop crashes from occuring or as the author calls it graceful exiting if the UPNP requestor is unreachable! It is 3.2.1
Here is my updated file. It does thermostat cool points and handles if it is on HOLD or not. Puts hold back on if it was on and turn if off so it can change the setpoint. Also added Scenes. Scenes are 0-6 or something like that. Unintuitive given our switches are A - D.
<?php
define('HHAPI_URL', 'XXX,XXX,XXX,XXX:YYYY port/api');
define('HHAPI_USER', 'ZZZZZ');
define('HHAPI_PASS', 'PPPPPP');
// hhapi calls
// Grab the name and date properties from the controller object
if (isset($_GET["dim"])) { // Check to see if DIM is defined so run the DIM command
hhapi('controller.unitWithNumber('.$_GET["DeviceNum"].').setLevel('.$_GET["dim"].')');
}
elseif(isset($_GET["newTargetValue"])) { //See If we are passing a unit number to turn on or off
if ($_GET["newTargetValue"] == 1){ //Value is 1 so turn switch ON
hhapi('controller.unitWithNumber('.$_GET["DeviceNum"].').on()');
}
elseif($_GET["newTargetValue"] == 0){ //Value is 0 so turn switch OFF
hhapi('controller.unitWithNumber('.$_GET["DeviceNum"].').off()');
}
}
elseif (isset($_GET["Button"])) { //Passing a button name to exectute that button
hhapi('controller.buttonWithName("'.$_GET["Button"].'").activate()');
}
elseif (isset($_GET["ButtonID"])) { //Passing a button number to exectute that button
hhapi('controller.buttonWithNumber('.$_GET["ButtonID"].').activate()');
echo("Yay for Me!2");
}
elseif (isset($_GET["Temp"])) { //Temp to change the temp
if (hhapi('controller.thermostatWithNumber('.$_GET["Thermostat"].').holdDescription') == 'On'){
hhapi('controller.thermostatWithNumber('.$_GET["Thermostat"].').setHold(0)');
hhapi('controller.thermostatWithNumber('.$_GET["Thermostat"].').setCoolSetpoint('.$_GET["Temp"].')');
hhapi('controller.thermostatWithNumber('.$_GET["Thermostat"].').setHold(1)');
} else {
hhapi('controller.thermostatWithNumber('.$_GET["Thermostat"].').setCoolSetpoint('.$_GET["Temp"].')');
}
echo("Yay for Me!");
}
elseif (isset($_GET["Test"])) { //Passing a button name to exectute that button
echo(hhapi('controller.thermostatWithNumber(5).holdDescription'));
}
elseif(isset($_GET["Scene"])) { //See If we are passing a unit number to turn on or off
hhapi('controller.unitWithNumber('.$_GET["DeviceNum"].').setScene('.$_GET["Scene"].')');
// hhapi('controller.unitWithNumber(145).setScene(2)');
echo("Set Scene!");
}
function hhapi($cmd) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, HHAPI_URL);
curl_setopt($ch, CURLOPT_USERPWD, HHAPI_USER . ':' . HHAPI_PASS);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $cmd);
$result = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if($error) echo $error;
return json_decode($result);
}
?>