This article extends the integration of turning on a relay and activating devices using GPIO pins by adding Alexa support. This document will guide you through required software installations, as well as linking your account to Alexa to be able to properly activate the skill.
1. Requirements
2. Project Setup
For this article, we will be using the repository
linked here. This repository has two different approaches to activation, automatic and manual. For this article, we will only be focusing on manual device activation using Alexa.
In this article, the smart home device we will be using is a fan, light bulb, humidifier, and door lock.
Clone the repository either by downloading the zip files directly, or use a unix-like command line operation with Git support.
git clone
https://github.com/STM-Capstone-2022/stm-capstone-aws.gitWe will also need some other external development tools to be able to get the project running on Alexa. The software we need is AWS CLI, Node.js npm, AWS CDK, and Maven.
For AWS CLI, it should already be installed on your development environment from the first requirement.
For Node.js npm, there are different ways to install depending on your OS.
- For Windows, install Node.js
- For Mac, in the command line type in brew install npm
- For Debian Linux, in the command line type in sudo apt-get install npm
For AWS CDK, type in the command line npm install -g aws-cdk.
If there is a permission error, it means that npm was installed onto your entire system, rather than the user. To fix this, find the Node.js installation and place it into your user root directory
For Maven, there are different ways to install depending on your OS
- For Windows, use this link to navigate to the Apache Maven website. It gives instructions on how to download and install to your Windows device
- For Mac, in the command line run brew install maven
- For Debian Linux, in the command line run sudo apt-get install maven
Two things are needed to finish the project setup.
-
Using your IAM account, run aws configure
on the command line. Keep the same IAM user access and secret access keys, but change the region to us-east-1. The reason for this is that the Alexa skill can only communicate with the US market in this region.
-
Run on the command line cdk bootstrap aws://$ACCOUNT_NUMBER/us-east-1
to set up a CDK. For $ACCOUNT_NUMBER, make sure that you use the ROOT account number, not the IAM account.
3. Configuration
Within the application.properties files, there are softcoded constants. A sibling file application-override.properties is gitignore'd to hold sensitive information and may supersede application.properties when they both contain the same key.
These keys should be modified to fit your project:
- iot.thing.relay.name - The ID of an IoT Core Thing, the relay to the multiple smart devices.
- iot.thing.region - The AWS-deployed region of the IoT Core Thing.
4. Deploying the Project
Within the project directory, run the following lines in command line
- mvn package -pl '!alexa-iot-application' to build all worker submodules (building the cloud application itself is not necessary).
- cdk synth stm-alexa-endpoint to generate the application templates for the Alexa stack and upload assets to the CDK bucket
- cdk deploy stm-alexa-endpoint to launch the stack to your account
5. Attaching the Alexa Skill
When creating an Alexa skill, you need to only create it once, and it needs to be reattached to the lambda function whenever it is deleted and recreated. Redeploying through CDK does not require this unless the original stack is deleted.
To attach the Alexa skill, follow this set of instructions.
- Create an Alexa Skill on https://developer.amazon.com/alexa/console/ask, creating an Amazon Developer account if needed. Select Smart Home skill.
- Be navigated to the Smart Home tab of the new skill. In the Smart Home service endpoint section, copy your Skill ID. Keep this page open
- On a new tab, visit your AWS Console on your root account that deployed the project -> Visit CloudFormation -> Stacks -> Select N. Virginia region (us-east-1) -> the stack named stm-alexa-endpoint.
- Navigate through the Resources tab -> AlexaSkillFunction -> Configuration tab below the Function overview -> Triggers
- Press New Trigger -> select Alexa Smart Home -> paste Your Skill ID.
- Go back to the Function overview, copy the Function ARN, go back to your Alexa Skill management page and paste it in Smart Home -> Smart Home service endpoint -> Default endpoint. Repeat steps 5 and 6 whenever the Function is deleted in-between redeployment.
Finally, set up Account Linking in the AWS documentation:
https://developer.amazon.com/en-US/docs/alexa/smarthome/set-up-account-linking-tutorial.htmlAt this point, Alexa is ready to use with your devices.