Haiku Using Amazon Alexa devices (Echo, Dot, Tap, etc.) with HAI

I've double checked user name and password. It's what I use to log into the HH Web Interface, correct?
 
I did not add echo code. Not sure how to.
 
Add something like this in line one
echo "line 1";

Then copy that line and add it other places and go to the URL in your browser and see if you get at least line 1 displayed
 
Here's my older code I found on Dropbox

<?php
define('HHAPI_URL', '192.168.1.203:9399 port/api');
define('HHAPI_USER', 'Xxxx');
define('HHAPI_PASS', 'yyyy');

// hhapi calls

// Grab the name and date properties from the controller object
if (isset($_GET["dim"])) {
hhapi('controller.unitWithNumber('.$_GET["DeviceNum"].').setLevel('.$_GET["dim"].')');
}
else{
hhapi('controller.unitWithNumber('.$_GET["DeviceNum"].').toggle()');
}

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);
}
>
 
Thank you. Dumb question.  Where your code has ["DeviceNum"] I enter the device number, correct? So in keeping with my device I'd enter ["3"]
 
Also, I'm getting the number off the HH Web Interface under Control. This is the same spot I can toggle the lights on and off.
 
Just use my code directly as it is don't change anything but the ip username and password

And I was wrong use 003 in the call to the page
So I called the file haikuhelper.php

So you run your server ip/haikuhelper.php?DeviceNum=003

You only change the 003 in the call to the page you can try any id
 
I am home.  Are you getting it working now?  Let me know.  The code I posted is old.  The new stuff I will post below:  
 
First here is the URL I use to run it: 
 
http://192.168.1.203/HaikuHelper.php?newTargetValue=1&DeviceNum=147  
 
this is to turn ON Device 147
 
http://192.168.1.203/HaikuHelper.php?newTargetValue=0&DeviceNum=147
 
this is to turn OFF Device 147.
 
Get this working and I will try to get dimming working for you.  Code is:
 
Here is the "good" code.  This does buttons and sets Cooling Temperature:
 
<?php
define('HHAPI_URL', 'IP_OF_HAIKUHELPER:pORT_OF_HAIKUHELPER port/api');
define('HHAPI_USER', 'USERNAME');
define('HHAPI_PASS', 'PASSWORD');
 
//  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["Temp"])) { //Passing a button name to exectute that button    
   hhapi('controller.thermostatWithNumber('.$_GET["Thermostat"].').setCoolSetpoint('.$_GET["Temp"].')');
 echo("Yay for Me!");
}
    
    
 
 
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);
}
?>
 
You should forget the bridge until you can successfully use the URL in a browser. If it still asks you for userid/password then there is still something wrong with the php authentication.
 
<?php
define('HHAPI_URL', 'IP_OF_HAIKUHELPER:pORT_OF_HAIKUHELPER port/api');
define('HHAPI_USER', ‘xxxx’);
define('HHAPI_PASS', ‘xxxx');
 
//  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["Temp"])) { //Passing a button name to exectute that button    
   hhapi('controller.thermostatWithNumber('.$_GET["Thermostat"].').setCoolSetpoint('.$_GET["Temp"].')');
 echo("Yay for Me!");
}
    
    
 
 
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);
}
 
?>
 
Back
Top