Alexa, is my food ready?

Kevin Kazmierczak
Mar 8, 2016 · 14 min read
Image for post
Image for post
Photo credit: Stratageme.com via Visual hunt / CC BY-NC-SA

Introduction

A few months ago, I wrote up how I built an internet connected grill thermometer so I could check on my low and slow cooking from any of my devices and then get push notifications when it was ready. I recently aquired an Amazon Echo and was curious if I could somehow get this device to tell me the status of my grill with just my voice. For those that aren’t familiar with the device, it’s a product from Amazon that’s a standalone digital assistant similar to Siri, but it’s always on and ready for commands. It looks just like a small speaker that can sit in your house and any time you have a question for it, you can just say something like, ‘Alexa, what’s the weather’ and it’ll tell you the weather. It does much more than that, but that’s the general idea.

Skills

The question for me, was whether or not I could add some custom functionality to the device. It has a bunch of built in commands, but I wanted to make my own. Thankfully Amazon thought of this and added the concept of ‘Skills’ that your echo can use. A ‘Skill’ is a custom action that developers can create to do whatever they want and they can either use them on their own device or they could publish them publicly for others to use. There is a whole listing of skills on the Alexa app that you can add to your Echo.

  • “ask…for…” is the phrase to request a specific skill to do something. There are multiple variations of words supported here, you can see them all here
  • “Grill Log” is the invocation name I’ve registered my custom skill to use, it must be two words
  • “the temperature” is the intent of the user ( not related to Android intents ) and will get passed to your service for processing

Processing User Requests

As stated above, you have two options to process the user’s request, either in your own web service or using AWS Lambda. If you already have a web service infrastructure setup, it might make more sense for you to use the web service option, but I won’t go into the detail of what’s required to do this. You can read more about the details of that on the Amazon dev site. It’s much easier to use the Lambda functionality as it’s already within the Amazon suite of tools. If you aren’t familiar with Lambda, it’s a service that Amazon Web Services (AWS) provides that can run code in response to events. You can read more about Lambda here and read through a tutorial here. That code can be written in a number of different languages, Javascript (Node.js), Java, or Python, so you can pick the one you are most familiar with. You pay for how many requests and processing time you use, but you get one million requests free per month using the free tier.

Image for post
Image for post

Interaction Model

Now that you have some code that you can call hosted up in the AWS cloud, we can define our skill on the developer site. If you go to developer.amazon.com, and then go to the Alexa section, you can register your custom skill here. It’s worth noting that in order to test your custom skill, you must have your device registered with the account you have registered on the developer site. If you’d like to make that skill publicly available, you can complete the registration process and then Amazon will need to certify it for use. The certification process takes anywhere from a few days to a week. Once certified, it will be in the list of available skills that anyone could add to their device. In my experience, the review team is very particular about skills it certifies, which I think is a good thing, but I’d highly recommend you review the submission guidelines before you send it for certification.

Image for post
Image for post
{
"intents": [
{
"intent": "AMAZON.HelpIntent"
},
{
"intent": "StatusIntent"
},
{
"intent": "TemperatureIntent",
"slots": [
{
"name": "temptype",
"type": "LIST_OF_TYPES"
}
]
}
]
}

Processing Code

Now that we’ve registered our skill and have a basic Lambda function setup, we need to fill out the detail of what the skill is going to actually do. Since our code is just a Node.js script, we can connect to whatever we need to assuming there is the ability to connect to it. For my skill, I need to connect to the database of BBQ temperatures and get the last reading.

  1. card — The information to put on the card object the user sees in the Alexa app
  2. reprompt — The text string to speak if the user doesn’t respond within a small time period
  3. shouldEndSession — A flag to either close the session or keep it open for the user to respond

Testing Your Skill

There are a few different ways you can test our your skill. The first way I’d test the skill is by directly testing the Lamdba function using the web tools. If you are logged into the AWS console, you can load up the Lambda function and configure it’s test data and test it there. The nice part to doing the testing here is that you immediately see the response and any console logging for that request. Hopefully when you test the function, you’ll see your response object with all the speech you’ve generated. It gets a little tricky if you have work with session data, but works well for simple tests.

Image for post
Image for post

Conclusion

Here we’ve walked through the steps of creating an Alexa skill that can read the temperatures out of my Grill Log database. Amazon has made it pretty simple to create these skills as all you need to worry about is figuring out how you will connect to your data. In my case I was just simply calling into another AWS product, but you could be calling into anything that’s available on the internet. The format of invoking the skills on the device still feels a bit awkward at times, but I bet that gets improved over time. I’m amazed at how many things the Echo has already integrated with and it’ll be interesting to see if Apple ever creates something similar with Siri and HomeKit to compete in this space.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store