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

heffneil

Active Member
I have to admit I am not very well versed in this but I've spent a couple hours and perhaps I am getting older and I am not further than when I started.  I would love to see some documentation on how to get this working.  I am still a bit unclear how to make the transition from this program to Haiku or how to even use it afterwards.  I think I got the bridge working.  I can't find a place to put this file but once I do, then what?
 

ihf

Active Member
To get to the Library Directory without much fuss, go to Finder, Go,Go to Folder.... Type  /Library/Webserver and see what you get.
 

heffneil

Active Member
Yeah ok I have the directory but im really lost.  Let me know if you can explain in dummy terms for me.  Do I need a file for each button or switch? Where are you specifying that in the file?  Very confused  :wacko:
 

ihf

Active Member
You need to replace the IP and port of the HH server, HH userid, HH password. Then where it says hh api calls, you need to insert the calls that do what you want on the HAI. You will have to refer to the HH Javascript API documentation but here is a full example that can turn a unit (number 3) on/off and  set level:
 
<?php
define('HHAPI_URL', 'http://IP address:port/api');
define('HHAPI_USER', ‘XXX’);
define('HHAPI_PASS', ‘YYY’);

// Grab the name and date properties from the controller object
if (isset($_GET["dim"])) {
    hhapi('controller.unitWithNumber(3).setLevel('.$_GET["dim"].')');
}
else{
   hhapi('controller.unitWithNumber(3).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);
}
 
Once this file is in the Webserver directory and the Webserver is started. You can add this device using the bridge's configurator and the URL should point to this file. In the configurator, try clicking the test button to see if the URL is correct and the file works (I.e. controls the device). You will then have to use the Alexa app on your phone and go to Settings, Smart Home, Discover Devices. If the bridge is working, it should say it found devices. At that point you can ask Alexa to turn on/off the device. 
 
Don't give up :)
 

ihf

Active Member
Oh, sorry, didn't answer your question...yes there is a file for each device defined in the configurator and possibly a separate file for on or off. The only real difference between these files is the HHAPI calls which are defined int he HH Javascript API doc. If you have a specific thing to do, I can try to construct the call.
 

heffneil

Active Member
Wow I am getting old :)  You're a smart dude.  Now that I have some directions I can actually try this.  Thanks!
 
Neil
 

heffneil

Active Member
The file just goes in the root of the Webserver directory right and named .php?  I get a file not found.  I must be missing something else.
 
I tried test.html test.php and still can't find them.  Im lost and I Know this shouldn't be so hard...
 

ihf

Active Member
I can't really comment about the full URL since I am using a different (probably older) bridge and the parms may be different. If you are getting a 404 then the webserver must be running at that address and it thinks you do not have a file in the /Library/Webserver/Documents directory that is called HaikuHelper.php. I assume the filename has the correct case and the .php suffix?
 

heffneil

Active Member
yeah I mean I put test.html in that directory and it isn't showing either.  This is why I am so confused.  How in the world is anyone figuring this out?  I need some docs for this thing and I can't find anything but dribs and drabs?
 
Top