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

Alright! Just for grins I tried your simple hello.php
 
<?php
          echo "Hello World";
       ?>
 
And it worked!
 
But that's the only one that's working.
 
That and the phpinfo of course.
 
Well Ok we have progress.  Now Can you try the file I emailed you?  It will need your updated password and username since you changed them?
 
It's all working now! Alexa will turn on my Study Fan and Lights! Thanks again for everyones help. Heffneil, you'll have to explain to IHF what you did to get the code to work. Ha.
 
I guess my next question is what I can do for this to automatically start up after I reboot my Mac mini?
 
Thank you!
 
Ok so we were banging our heads against the table and I finally got suck of using textedit.  I didn't trust it.  We installed Brackets to modify the file and the color coding was all wrong.  As it turns out text edit was putting a different quote ' than what is typical.  I don't know how to describe it other than to say it was royally screwing up the code and the PHP parser couldn't figure it out - hell we couldn't either! Fortunately Brackets color doing made it pretty obvious something was awry.  Changed the quotes around the username and password (When dwpaddack changed these with textedit it replaced them).
 
Neil
 
so if anyone wants to run ha-bridge with launchctl so it stays running all the time, this is my plist for launchctl

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.ha-bridge</string>
<key>ProgramArguments</key>
<array>
<string>java</string>
<string>-jar</string>
<string>/PATH/TO/ha-bridge/ha-bridge-3.2.0.jar</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/PATH/TO/ha-bridge/stderr</string>
<key>StandardOutPath</key>
<string>/PATH/TO/ha-bridge/stdout</string>
<key>WorkingDirectory</key>
<string>/PATH/TO/ha-bridge/</string>
</dict>
</plist>

 
Just create the file as text, update the paths, and name it "com.ha-bridge.plist" and put the file in /Library/LaunchDaemons.  then 'sudo chown root:wheel /Library/LaunchDaemons/com.ha-bridge.plist'  then 'sudo launchctl load /Library/LaunchDaemons/com.ha-bridge.plist' and it should start up the jar and keep it running at all times.
 
You may possibly have to do a 'sudo launchctl start com.ha-bridge' but I do not believe that's a requirement after the load since it's set to KeepAlive
 
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);
}
?>
 
I got this warning after I run the launchctl
 

/Library/LaunchDaemons/com.ha-bridge.plist: Path had bad ownership/permissions
 
Any thoughts on the permissions issue?
 
Thanks!
 
Neil
 
I did that and it started up but its not really running.  I had to re-execute it on the command line and it works again.  When I ran the plist again it said it was running so something is screwed up :)  How do I kill the plist?
 
Neils-Mac-mini:LaunchDaemons neilheuer$ launchctl unload com.ha-bridge.plist 
/Library/LaunchDaemons/com.ha-bridge.plist: Could not find specified service
Neils-Mac-mini:LaunchDaemons neilheuer$ sudo launchctl load /Library/LaunchDaemons/com.ha-bridge.plist
Password:
/Library/LaunchDaemons/com.ha-bridge.plist: service already loaded
Neils-Mac-mini:LaunchDaemons neilheuer$ 
Neils-Mac-mini:LaunchDaemons neilheuer$ launchctl unload com.ha-bridge.plist 

/Library/LaunchDaemons/com.ha-bridge.plist: Could not find specified service
 
Back
Top