This is an AWS Lambda deployed Alexa skill that communicates with the MagicMirror module MMM-Alexa via the AWS IOT Gateway.
This work is inspired by joanaz Mirror Mirror On The Wall Alexa Skill. Major difference is that this implementation use the alexa-app SDK instead of the alexa-skills-kit-sdk-for-nodejs for creating the skill and of course there are other features of the skill.
The main features that I developed this skill for was:
- to control my Sonos speakers using Alexa
- to control my lights based on a Vera solution
- to control various features of the Magic Mirror
- Install the MMM-Alexa module in your Magic Mirror installation
- Clone this repository with
git clone https://github.com/boghammar/MMM-AlexaSkill.git
- Install dependencies by
cd MMM-AlexaSkill
and thennpm install
- Setup an AWS IOT device according to the instructions below
- Configure your skill with the credentials from the AWS IOT device creation
- Deploy your code to AWS Lambda (see below)
Since this skill relies on AWS IOT to communicate with the Magic Mirror you need to deploy your certificates along with the code when deploying to AWS Lambda. For that purpose use the utility prepareDeploy.js
to pack the correct files for deployment. What this utility does is
- Find out the secret directory by reading the Alexa.configPath in the package.js file.
- Reads the
Alexa.configPath+/deployConfig.js
file that contains the following parameters
// This is the deploy configuration for MMM-AlexaSkill
var cfg = {
IOTEndpoint: 'apt******.iot.us-east-1.amazonaws.com',
certPath: 'C:/_data/dev/certs', // Where are the certificates
certID: '16cc68c66f' // Whats the prefix of the certificate files
}
module.exports = cfg;
- Copies the certificates files to the directory
./certs
within your source tree - Copies the deployConfig file to the directory
./certs
within your source tree - Zips all necessary source files (including the
node_modules
directory) along with the./certs
directory.
The resulting zip file can then be uploaded using the AWS Lambda Console.
The utility createUtterances.js
is used to create the files alexa/schema.txt
and alexa/utterances.txt
. The contents of these files can be pasted into the appropriate windows in the Amazon Alexa Skill configuration.
The messages sent from the skill to the IOT device have the following format:
{
"module": "nameofmodule",
"body": {
// Module specific module data
}
}
for instance the SonosPlay module takes this message
{
"module": "SonosPlay",
"body": {
"action": "play",
"what": "beatles",
"from": "spotify",
"where": "kitchen"
}
}
the MMM-Video module takes this message
{
"module": "MMM-Video",
"body": {
"action": "play",
"video": {
"ix": 0
}
}
}