An AWS Lambda function of an Alexa skill for communicating and controlling a MagicMirror using AWS IoT Device Gateway.
It is complementary to the Magic Mirror Module Mirror Mirror On The Wall.
Please follow the steps below to setup and install this Alexa skill correctly.
You need to setup an AWS IoT Device, which is used for the communication between this Alexa skill and the Magic Mirror node app. The credentials you obtained through this process will also be used by the complementary Magic Mirror Module.
- login to AWS Management Console
- choose US East region
- find AWS IoT service
- click on Connect at the left menu bar, under Configuring a device, click on Get Started
- choose Linux/OSX platform, and Node.js
- click on Get Started
- name your device MagicMirror
- download credentials, aka connection kit
- click on Next step
- follow the instructions to run the start.sh script, which will generate a root-CA.crt
- copy all your credential files, then go to your local copy of this repo, and paste them inside the certs folder (which is inside the src folder)
Dependencies are installed by navigating to your src directory on command line, and enter npm install
.
- alexa-sdk (installed via
npm install
) - aws-iot-device-sdk (installed via
npm install
) - Google Images Search (installed via
npm install
). Follow the instructions in the link to create your own Google Custom Search Engine, and save the CSE ID and API key in certs/keys.json (see keys_sample.json below). - Youtube API(installed via
npm install
). Watch this instruction video to create your own Youtube API key, and save it in certs/keys.json (see keys_sample.json below).
On your command line, navigate to the certs folder, then enter cp keys_sample.json keys.json
, which will create a copy of keys_sample.json called keys.json. Copy and paste your API keys obtained above in keys.json.
// keys_sample.json
{
"cse": {
"ID": "YOUR GOOGLE CUSTOM SEARCH ENGINE ID",
"API_key": "YOUR GOOGLE PROJECT API KEY"
},
"youtube": {
"API_key": "YOUR YOUTUBE API KEY"
}
}
- Go inside your local src directory, select all files and folders and then create a zip file, make sure the zip file does not contain the src directory itself, otherwise Lambda function will not work.
- Go to the AWS Management Console and click on the Lambda link. Note: ensure you are in us-east region or you won't be able to use Alexa with Lambda.
- Click on the Create a Lambda Function or Get Started Now button.
- Choose Blank Blueprint
- Choose trigger Alexa Skills Kit, click "Next"
- Name the Lambda Function, (any name is fine), select the runtime as Node.js, select Code entry type as "Upload a .ZIP file"
- Click on Upload button, then upload the zip file created in Step 1 to Lambda
- Keep the Handler as index.handler (this refers to the index.js file in the zip). Create new role from template and name it anything.
- Leave the Advanced settings as the defaults and click on "Next"
- Review the settings then click "Create Function"
- Copy the ARN from the top right to be used later in the Alexa Skill Setup
- Go to the Alexa Console and Get Started with Alexa Skills Kit
- Click on the Add a New Skill button on the right
- Set "Mirror Mirror On The Wall" as the skill name, and "on the wall" as the invocation name, this is what is used to activate your skill
- Copy the Intent Schema from the included IntentSchema.json in the speechAssets folder.
- Copy the Sample Utterances from the included SampleUtterances.txt. Click Next.
- Select the AWS Lambda ARN for the skill Endpoint, pick North America, and paste the ARN copied from Section 3 Step 11. Click Next.
- You can test your Alexa skill by entering "hello" in the Service Simulator, click on the "Ask Mirror Mirror On The Wall" button, you should get a response as below
- Go back to the Skill Information tab and copy the Application Id.
- Paste the Application Id into the index.js file for the variable APP_ID, and save the change
- Delete the zip file generated in Section 3 Step 1, and generate a new zip file using the same method. Upload the new zip file to Lambda. This step makes sure the Lambda function only serves request from an authorized source
You are now able to start testing your Alexa skill! You should be able to go to the Amazon Alexa website and see your skill enabled.
When you use your skill, you will see the relevant cards show up on the home page.
See the Examples section and the [List of Commands] (#list-of-commands) section below for commands you can say.
*Note: You don't need to publish your Alexa skill, and you better not to publish your skill! Because otherwise your AWS IoT Device Gateway would be shared to other people, and their commands would show up on your mirror.
User: "Alexa, On The Wall, hello"
Alexa: "Hello my Queen, what can I do for you? "
If you are running AlexaPi on Raspberry Pi, or using a wake word engine like Snowboy, you can change the wake word from "Alexa" to "Mirror Mirror", then you can say:
User: "Mirror Mirror On The Wall, say Hello"
Alexa: "Yes, my Queen. Hello."
If you enabled the complementary Magic Mirror Module, the word "hello" will also be displayed on your Magic Mirror.
After you invoked this Alexa skill, you can say any of the following commands to trigger different actions on the Magic Mirror.
The text in {} will be displayed on Magic Mirror in bold.
"say {hello}"
"say {good morning}"
"say {you are the fairest of them all}"
"display text of {hello}"
"display text of {good morning}"
"show text of {hello}"
"show text of {good morning}"
The text in {} will be searched by Google Image Search API, and the returned images will be displayed on Magic Mirror, with the text.
"find {snow white}"
"find images of {hunter}"
"find pictures of {dwarfs}"
"show me {snow white}"
"show me pictures of {hunter}"
"show me images of {dwarfs}"
"show pictures of {hunter}"
"show images of {snow white}"
"display pictures of {dwarfs}"
"display images of {dwarfs}"
The text in {} will be searched by Youtube Data API, and the returned video will be played on Magic Mirror, with the text.
"show me how to {make slime}"
"show me video of {movie trailer}"
"show me a video of {cats}"
"show video of {volcanoes}"
"show a video of {birds}"
"display video of {animals}"
"display a video of {rattle snakes}"
"find video of {cat}"
"find video of {cat and dog}"
"find a video of {snow white}"
To turn on/off a Magic Mirror Module, it has to be installed and configured in the main project already. You also have to map its official module name to a transcribable spoken name in ModuleNames.json. For example, "MMM-Globe" maps to "globe", "currentweather" maps to "current weather".
Note: To clear the text/images/video displayed by this module, you can simply turn this module off. The spoken name for this module is tentatively "magic mirror"
To turn on a Magic Mirror Module, say:
"start {newsfeed}"
"start {current weather}"
"turn on {compliments}"
"open {smile test}"
To turn off a Magic Mirror Module, say:
"close {newsfeed}"
"close {current weather}"
"turn off {compliments}"
"finish {smile test}"
To turn on all Magic Mirror Module, say:
"open all"
"open all modules"
"open every module"
"open each module"
"show all modules"
"show me all modules"
"show every module"
"show each module"
"turn on all"
"turn on all modules"
"turn on every module"
"turn on each module"
"start all"
"start all modules"
"start every module"
"start each module"
To turn off all Magic Mirror Module, say:
"close all"
"close all modules"
"close every module"
"close each module"
"hide all"
"hide all modules"
"hide every module"
"hide each module"
"turn off all"
"turn off all modules"
"turn off every module"
"turn off each module"
"hide all"
"hide all modules"
"hide every module"
"hide each module"
"turn off all"
"turn off all modules"
"turn off every module"
"turn off each module"