Build your own voice-controlled Magic Mirror Instructions
*Windows users: You must have a Linux Bash Shell to do this Workshop. When you are installing Git, please follow these instructions to use the Unix tools from the Windows Command Prompt.
repo: MichMich/MagicMirror
We are using an open source MagicMirror² software platform that will allow you to convert your hallway or bathroom mirror into your personal assistant.
To toggle the (web) Developer Tools from mirror mode, use CTRL-SHIFT-I
or ALT
and select View
.
Open your command line
Download the repository to your laptop
git clone https://github.com/MichMich/MagicMirror.git
Enter the repository
cd MagicMirror/
Install node libraries
npm install
Navigate to the config folder and rename config.js.sample to config.js
cd config/
mv config.js.sample config.js
Run the app
npm start
We need to setup an AWS IoT Device Gateway. It works as a hub that will allow an Alexa Skill to send messages to it and a Magic Mirror to subscribe to new messages from it. This will let us control our Magic Mirror with our voice.
Login to AWS Management Console
Choose US East (N. Virginia) region
Find IoT Core service
Click on Onboard at the left menu bar, under Configuring a device, click on Get Started
Click on Get Started
Choose Linux/OSX platform, and Node.js
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
Go back to the AWS web page, click on Done
Open the MagicMirror Thing you just created
Click on Interact on the left menu bar, see the HTTPS Rest API Endpoint in the format of xxxxxxxxxxxxxxx.iot.us-east-1.amazonaws.com
? You will need to copy this endpoint for Lambda function deployment later
In this section, we build the language model for our Alexa Skill by defining the commands that Alexa can recognize.
Go to the Alexa Developer Console
Click on the Create Skill button.
Name your Skill (any name is fine), select Custom model, and click the Create a skill button.
Choose Start from scratch template
Click on Invocation on the left menu bar. Set “magic mirror” as the invocation name (or any unique phrase). This is the phrase used to activate your skill. Save Model.
Click on JSON Editor on the left menu bar. Delete everything in there.
Go to InteractionModel.json in the speechAssets folder, and copy everything in the file, and paste it in JSON Editor. Save Model. Build Model
Click on Endpoint on the left menu bar. Select AWS Lambda ARN. Copy your Skill ID to be used later in Lambda function deployment
repo: joanaz/MirrorMirrorOnTheWallSkill
In this section, we deploy our AWS Lambda function for our Alexa skill. Our Lambda function processes our voice commands and tells Alexa how to respond, and sends our commands to the AWS IoT Device Gateway.
Download the GitHub repository to your laptop
git clone https://github.com/joanaz/MirrorMirrorOnTheWallSkill.git
Install node libraries
cd MirrorMirrorOnTheWallSkill/src/
npm install
Navigate to the certs folder and rename keys_sample.json to keys.json
cd certs/
mv keys_sample.json keys.json
Copy the credential files generated in Section AWS IoT Core. Then open the local MirrorMirrorOnTheWallSkill folder you downloaded, go to src, then certs, paste your credential files here
Open MirrorMirror.js in src folder with a text editor. Copy and paste your HTTPS Rest API Endpoint to line 17, replacing YOURID.iot.us-east-1.amazonaws.com
Open index.js in src folder with a text editor. Copy and paste your Alexa Skill ID to line 18 for the variable APP_ID, replacing amzn1.ask.skill.YOURALEXASKILLID
, and save the change
Here’s the list of node libraries you installed in the above step. If you are interested in learning more about them, you can go and check out their links.
OPTIONAL: It is for showing images on the Magic Mirror. 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.json below).
OPTIONAL: It is for showing a video on the Magic Mirror. Watch this instruction video to create your own Youtube API key, and save it in certs/keys.json (see keys.json below).
The keys.json file is where you put your Google Images Search and YouTube API keys.
// keys.json
{
"cse": {
"ID": "YOUR GOOGLE CUSTOM SEARCH ENGINE ID",
"API_key": "YOUR GOOGLE PROJECT API KEY"
},
"youtube": {
"API_key": "YOUR YOUTUBE API KEY"
}
}
Go to the AWS Management Console
Click on the Create a Function button.
Choose Author from scratch. Name the function (any name is fine).
Keep “Create new role from template(s)” and enter a role name (any name is fine)
Click on the Create function button.
Under Add triggers menu on the left, click on Alexa Skills Kit
Disable Skill ID Verification. Click Add button. Then scroll up and click the orange Save button
Click on the box with your function name in the Designer section. Select Code entry type as “Upload a .ZIP file”
Click on Upload button, then upload the zip file created in Step 1. Then Save
Copy the ARN from the top right.
Go back to the Alexa Developer Console, click on Endpoint on the left menu bar, and paste the ARN to Default Region. Click Save Endpoints
You can now test your Alexa skill by going to the Test tab on the Alexa Developer Console and enabling testing. Type “start magic mirror” in the textbox and see what happens!
You can also test your Alexa skill on EchoSim, by saying “Alexa, ask magic mirror to say hello”.
Another testing tool is the Amazon Alexa website, where you can see each of your Alexa voice command and Alexa’s response. If you get the image command to work, you will see the image on the card too.
repo: joanaz/MMM-MirrorMirrorOnTheWall
We’re Finally up to the last step! We add the Magic Mirror Module to MagicMirror² which subscribes to incoming messages from the AWS IoT Device Gateway and displays text/images/video on the MagicMirror², and turns on/off other Magic Mirror Modules according to our commands.
Navigate to the MagicMirror repo we downloaded in Section 1
cd MagicMirror/modules/
Download our Magic Mirror Module code inside the modules folder
git clone https://github.com/joanaz/MMM-MirrorMirrorOnTheWall.git
Install Node libraries
cd MMM-MirrorMirrorOnTheWall/
npm install
Copy the certs folder in your Lambda function code (under MirrorMirrorOnTheWallSkill/src) to the MMM-MirrorMirrorOnTheWall folder
Open MirrorMirror.js in MMM-MirrorMirrorOnTheWall folder with a text editor. Copy and paste your IoT Device HTTPS Rest API Endpoint to line 18, replacing YOURID.iot.us-east-1.amazonaws.com
Copy below code and add it to MagicMirror/config/config.js
// modules: [
// ...
{
module: 'MMM-MirrorMirrorOnTheWall',
position: "middle_center",
config: {}
},
// ]
You can invoke your Alexa skill by saying Alexa, start Magic Mirror
. Next, you can say any of the following commands to trigger different actions on your Magic Mirror.
The text in {} will be displayed on Magic Mirror in bold.
To turn on/off a Magic Mirror Module, it has to already be installed and configured in MagicMirror². You also have to map its official module name to a transcribable spoken name in ModuleNames.json. For example, we can map “MMM-Globe” to “globe”, or “currentweather” to “current weather”.
To turn on a Magic Mirror Module, say:
To turn off a Magic Mirror Module, say:
Note: To clear the text/images/video displayed by this module, you can simply turn this module off.
To turn on all Magic Mirror Module, say:
To turn off all Magic Mirror Module, say:
The text in {} will be searched by Google Image Search API, and the returned images will be displayed on your Magic Mirror with the text.
The text in {} will be searched by Youtube Data API, and the returned video will be displayed on your Magic Mirror, with the text. The YouTube video autoplays on a loop.