Amazon Alexa and IFTTT

There have been discussions here already about this topic. I just wanted to elaborate some more. A brief example for Imp newbies …

This is the original post from @merlin13:

I got my Dot a couple days ago and while I didn't write any custom skill yet like Aron did, last night it took me about 10 minutes to get Alexa to trigger LEDs on my imp via IFTTT. Not as cool as using a custom skill but pretty easy to do.

If anyone is interested in details, I can provide them but in a nutshell, I used IFTTT with Alexa “Say a specific phrase” trigger to make a web request to the Maker channel which calls an endpoint in my agent code. Very simple integration that unfortunately doesn’t send back any content that Alexa can say but it works.

He is correct, you can command the imp to do things, but there is no feedback to Alexa. Also, Alexa says the command was sent to “ifttt”. Nobody would know what that means unless they know what IFTTT was. So the word “trigger” and Alexa saying “ifttt” is a bit awkward, but it works great. I created many applets for the same imp. Light on, light off, misc.

On IFTTT, when you select to make a new applet, the “+ if”, type the word ‘Alexa’ in the search to find all of the Alexa apps easily, then pick the “Say a specific phrase” trigger. In the “then” part, search the word ‘Maker’ to find the Maker app. Using the search makes it easy to find the apps among the many in the list.

In the Maker app, the phrase will be “light on”. Then you’ll give it your Imp URL. Select POST (instead of GET), and “text/plain” for content type. The body to send would be like this: data=on

I used plain text in my example, but you can also use JSON if you modify the agent. In my example, I look for the POST variable named “data”. Use any name you wish, or multiple names, but again, modify the agent.

Here is the agent code:

`// Agent Code

http.onrequest(function(req, resp){
if (req.method == "POST"){
local body = http.urldecode(req.body);
device.send("data", body.data);
}
resp.send(200, "OK");
});`

Here is the device code:

`// Device Code

function process(value) {
    server.log("Command: " + value);
    if(value == "on"){
    hardware.pin9.write(1);
    }
    if(value == "off"){
    hardware.pin9.write(0);
    }
}

// pin9 is an LED that would be an output to turn on/off a light
hardware.pin9.configure(DIGITAL_OUT);

agent.on("data", function(value) {
process(value);
});
`

When you say to Alexa: “Alexa, trigger light on” …
She will send trigger to IFFT and you can watch it happen on your Imp IDE server log.

Again, this would be a very simple project for an Imp newbie and you can do this without actually wiring anything. You can use the Imp IDE to watch the action in the server log. Later on, you can wire-up solid state relays (optic isolators, etc). If you have any questions or need clarification, please ask.