Lab 3 - Alexa
Wouldn’t it be great if you could control your Air Conditioning unit with your voice? No need to search for the remote anymore!
Alexa solves all of this for us. So lets create our first Alexa Skill!
We’ll be able to ask Alexa:
- Alexa turn on the aircon
- Alexa turn off the aircon
Preliminary
This Lab requires you to have completed Lab 2
Step 1. - Develop your first Alexa Skill
Setting up Your Alexa Skill in the Developer Console
Go to the Alexa Developer Console. In the top-right corner of the screen, click the “Sign In” button. (If you don’t already have an account, you will be able to create a new one for free.)
Once you have signed in, select the Developer Console link and then Alexa Skills Kit. From the Alexa Developer Console select the Create Skill button near the top-right of the list of your Alexa Skills.
Give your new skill a Name, for example, ‘workshop’. This is the name that will be shown in the Alexa Skills Store, and the name your users will refer to.
Select the Default Language. This tutorial will presume you have selected ‘English (US)’. Select the Custom model under the ‘Choose a model to add to your skill’ section. Click the Create Skill button at the top right. Choose Start from scratch from the Choose a template section and click the Choose button on the top right.
Build the Interaction Model for your skill
- On the left hand navigation panel, select the JSON Editor tab under Interaction Model. In the textfield provided, replace any existing code with the code provided in the below sample. Click Save Model.
- Click “Build Model”
Skill Sample
{
"interactionModel": {
"languageModel": {
"invocationName": "workshop skill",
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples": []
},
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": []
},
{
"name": "AirConOnIntent",
"slots": [],
"samples": [
"turn on"
]
},
{
"name": "AirConOffIntent",
"slots": [],
"samples": [
"turn off"
]
}
],
"types": []
}
}
}
We will take a pause of setting up the Alexa skills here to create the lambda function.
Step2 Build your Alexa Skills lambda function
In the management console, find lambda service
navigate to lambda function service and select “Create”
input the params for lambda function:
- function name: “alexa_workshop”
- Runtime: “python 3.7”
- Execution role: “Create a new role with basic Lambda function”
then “Create”
Next, configure the lambda function:
First upload the lambda function zip package, you can download the code from HERE, keep the hander as “lambda_function.lambda_handler”, then slick “Save”
Set your device shadow update topic as an environment variable. In Environment Variables section, create an environment variable named shadow_update_topic and set it’s value to your thing’s shadow update topic. Which should be something like: $aws/things/[YOUR THING NAME]/shadow/update
Configure the lambda function service role, and the trigger events for this lambda
Configure the service role by navigate to the execution role
configure the role policies
select “AWSIoTFullAccess”, then attach,
Next, we set Alexa skills as the lambda function trigger,
select Alexa Skills Kit
Then input your skill ID
to check the skill ID of your Alexa skills, go back to the Alexa develop console and navigate to your skill, to check skill ID
After the configuration of IoT access, and the trigger events, your lambda configuration should look like this
Now, since the lambda function is ready, you can set your “Endpoint” of your lambda skill
Step3 Configure your Alexa Skills endpoint
next we configure the Alexa skills endpoint
configure your endpoint by input the ARN of your Alexa lambda function (check the next step to copy your lambda function’s ARN), and save the Endpoints
You can find your ARN of the lambda function in your lambda function configure page
Step4 Test Your Alexa Skills
now we can start to test your Alexa skills and check the interaction with your device!
First, make sure your device is running and reporting sensor data like the following in Lab2
Secondly, navigate to the test console to test your skills, change the mode to Development
then you can input the speeches as following, this will simulate as you are talking to an Echodot or your phone
If the skills response “ok! I’ve turned on the aircon”, you can now check if your board reports the on / off state accordingly
Additionally, you can check your logs on the IoT Core console or looking at the shadow document for your thing
Done
You are done with Lab 3.
Challenge:
- Can you modify your Alexa Skill to support changing the device temperature?