Collaboration between obniz and Alexa (IFTTTT)
Contents
Make things
With obniz, you can easily light LEDs and move things from your smart speaker.
We tried to link it with Alexa, which is built into Amazon Echo and other devices.
There is a way to extend Alexa’s functionality by developing a Skill, but this time we’ll use IFTTT so that you can extend the functionality more easily than creating a Skill.
IFTTT is a web service that makes it easy to connect various web services and devices.
Talk to Alexa and blink the LED
Let’s make a system that makes the LED blink when you talk to Alexa. The summary is as follows.
- Say to Alexa, “Alexa, trigger blink the LED.”
- The Webhook URL of the obniz Event is called through IFTTT.
- The program registered in the obniz Event is run and the LED blinks.
Materials
- obniz Board
- Alexa-powered smart speaker(eg. Amazon Echo)
- power supply for obniz
- LED
- (In case of LED without resistor, resistor, breadboard and jumper are also prepared.)
How to make
Hardware connection
Connect LED (and resistor) to an obniz Board like the table and the image below by referring to LED Library. (It’s no need to connect resistor if you use LED with a resistor. If you’re unsure, please check the datasheet.)
Also, pay attention to the direction of the LED. The longer leg (anode) is closer to the 0 pin of obniz.
obniz | LED |
---|---|
0 | Anode (the longer one) |
1 | Cathode (the short one) |
Software
If the obniz Event calls IFTTT Webhook URL, LED will blink.
Please refer to the “Program.”
In the following part of the program, the number 0 of the obniz Board is assigned to the anode side of the LED and the number 1 to the cathode side.
let led = obniz.wired("LED", {anode:0, cathode:1});
Also, the LED blinks depending on posted JSON contents on Webhook in the statement of if(typeof req === "object")...
. In this program, the LED will blink every 300 milliseconds and it’s continued for 3 seconds if the value of “led” key is “true” in JSON contents.
LED is registered in the JS parts library of obniz, so you can easily control them.
→ LED (JS parts library) | obniz
Setting up an obniz Event
Set up the obniz Event so that the IFTTT recipe can call Webhook URL and run the Program. Learn more about obniz Events here.
First, go to the official obniz website and enter the “Developer Console”.
Next, click on New in the “Event” field to create an event. Please refer to the following for details of the settings.
Name | (arbitrary) |
---|---|
Webapp to run | Select the name of the program saved in the repository. |
Trigger | Webhook |
Click “Create”.
In the end, please note the URL in the “Endpoint” field. This URL will be used in the next chapter, “Make a recipe with IFTTT”.
Connect Alexa to IFTTT
To run a program triggered by the phrase “Alexa, trigger blink the LED”, use a service called IFTTT, which is a service that allows any web service(app) to run triggered by another web service(app).
Click “Create” in the top right corner of the main page and let’s start to make one. Then, click on “This” and select Amazon Alexa from the Service.
Choose “Say a specific phrase.” (You need to log in with your Amazon account if you use Alexa for the first time with IFTTT.)
Type “blink the led” in the field as the phrase you talk to Alexa (only lower case letters.)
Click on “Create trigger” to save the settings.
Next, edit the “That” part. Click on “That” and select “Webhook” in the Service.
Choose “Make a web request.”
Enter the Webhook URL you made a note in the “Install an App on your device” section in the URL field and fill in the remaining field like the image below.
Click on “Create action” and finish the settings.
Program
How to use
Let’s say to Alexa, “Alexa, trigger blink the LED.” LED probably blinks for 3 seconds like the video below.
(It might delay up to 15 minutes).
Application example
In the previous chapter, we blinked the LED, you can also apply this to many things.
Turn the switch on and off.
For example, if you change the LED part to a servomotor, you can turn on and off the lights and outlets just by talking to Alexa.
Even if it’s not a smart home appliance, you can easily (physically) turn a switch on or off just by talking to Alexa, so it’s convenient when you’re not free or want to operate a switch in another room.
We tried it with the ON/OFF switch of the outlet. (See video below).
As you can see, you can easily operate the physical switch just by talking to Alexa.
Turn Alexa’s timer like a party↑↑↑
Since IFTTT’s Alexa’s trigger has “Your Timer goes off”, I changed IFTTT’s trigger and program a little and made the timer party-like by making the ring LED light-up colorful when Alexa’s timer goes off!
in the end
Thus, you can easily connect the obniz Board and Alexa through IFTTT.
However, IFTTT does not have Alexa on the action side, so it is impossible to make Alexa talk depending on the sensor value from obniz.
Creating an Alexa Skill gives you more flexibility to extend your functionality. Please see this article.