Skip to content
Control MagicMirror with Alexa
JavaScript
Branch: master
Clone or download
JoChef2 Merge pull request #8 from JoChef2/dev
README edit notifications
Latest commit c2e1f4c Dec 27, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
public commit message Nov 1, 2019
translations commit message Nov 1, 2019
.gitattributes commit message Nov 1, 2019
CODE_OF_CONDUCT.md Add code of conduct Nov 7, 2019
LICENSE commit message Nov 1, 2019
MMM-AlexaControl.js Page limit remove finished Nov 23, 2019
README.md Merge pull request #8 from JoChef2/dev Dec 27, 2019
node_helper.js Add monitorOff function 2 Nov 23, 2019
package.json commit message Nov 1, 2019

README.md

MMM-AlexaControl

The MMM-AlexaControl module allows you to control your MagicMirror² with Alexa. You can turn it on and off, change the page and send notifications to other modules. For that it uses node-fauxmo nodejs module. As a result of this only an Amazon Alexa is necessary to use the module. Not even an Alexa Skill is required. It emulates an Wemos device. So acutally every smart home automation device that supports Wemos devices should be able to control your Mirror. But I only test it with an Echo Dot Gen. 3 and a Raspberry Pi 3B+.
Note: If you have problems look at the end of the Readme

Installation

  1. Navigate to your modules folder in a terminal:
cd ~/MagicMirror/modules
  1. Clone this repository:
git clone https://github.com/JoChef2/MMM-AlexaControl.git
  1. Navigate into the module folder and install the node modules. This step could use a few minutes.
cd ~/MMM-AlexaControl
npm install
  1. Configure the module in your config file. For that use the steps below.

  2. Start your Mirror

  3. Search in the Alexa App for new devices or say: "Alexa, discover my devices".
    Note: For some of the devices e.g. restart restarts your mirror wether or not you say on or off happen the same thing. For the monitorToggle device it isn't indifferent.
    Note: If you have problems to discover your devices or other problems look at the end of the Readme.

  4. Say "Alexa turn [device name] on/off"

Using the module

To use this module, add it to the modules array in the config/config.js file:

modules:[
    {
        module: 'MMM-AlexaControl',
        position: 'middle_center',
        config:{
            image: true,
            pm2ProcessName: "mm",
            vcgencmd: true
        }
    }
]

Configuration options

The following properties can be configured:

Option Description
image Icon
Make this image visible.
Default Value: true
Possilbe Values: true or false
height Here you can change the image height.
Default Value: 265 Note: The unit is px.
wight Here you can change the image width.
Default Value: 265 Note: The unit is px.
pm2ProcessName If you want to restart your Mirror with PM2 change here your PM2 processname. Here you can configure PM2 for your Mirror.
Default value: mm
vcgencmd This option chose the command to toggle your monitor on and off. I found two commands. Test them before in the terminal.
Default value: true
Possible values:
true = vcgencmd display_power 0 and vcgencmd display_power 1
false = tvservice --off and tvservice --preferred
startPort First Port for the devices. The port identify the device. So delete old devices in the Alexa App to prevent issues. Normaly you don't have to change it.
Default value: 11000

Control devices

These are configured devices you can use. If you want to change their name you must edit the translation file inside /translations/en.json. You can also add languages.

Option Description
refresh This refreshs your Mirror.
Default value: true
Possible value: true and false
restart This restarts your Mirror with PM2. So make sure the pm2ProcessName is right.
Default value: true
Possible values: true and false
stop This stops your Mirror with PM2. So make sure the pm2ProcessName is right.
Default value: true
Possible values: true and false
reboot This reboots your Pi.
Default value: false
Possible values: true and false
shutdown This shutdowns your Pi. Note: When you shutdown the Pi your devices aren't available. So you must start your Pi manually.
Default value: false
Possible values: true and false
monitorToggle This can switch your monitor on and off. Make sure the used command work for you. Look at the option vcgencmd
Default value: true
Possible values: true and false

Page devices

If you are using the MMM-Pages module you can change the page with this module.
You only have to type your number of pages in th config file. Note: There are 100 pages available. I think that's enougth.

Option Description
pages The number of your pages you would like to control. Note: Chose 0 if you won't use this.
Default value: 0

Notification devices

Notification devices allows you to send notifications to other modules.
You can send the same notification when you turn the device on and off like this:
Note: You have to put the notifications array you chose inside the config part.

notifications: [
    {
        name: 'Notificaition 1',
        port: 11100,
        OnOff: false,
        notification: ["NOTIFICATION", "PAYLOAD"]
    }
]

You can send different notifications when you turn a device on or off like this:

notifications: [
    {
        name: 'Notification 2',
        port: 11101,
        OnOff: true,
        notification: [["NOTIFICATION ON", "PAYLOAD ON"],["NOTIFICATION OFF", "PAYLOAD OFF"]]
    }
]

Note: NOTIFICATION ON and NOTIFICATION OFF stay for the different notifications you can send when you turn on or off the device. The same thing applies to PAYLOAD ON and PAYLOAD OFF.

These are the configuration options for a notification device:
Note: They are all necessary.

Option Description
name Here you can name your device. Make sure you didn't used the name before. Delete first the old device.
port Here you can give the device a static Port. I suggest that to you because then there aren't overlaps. Preferably start with the port 11100.
OnOff If you want to send the same notification when you turn a device on and off chose true. Otherwise if you want to send different notifications chose false.
Possible values: true and false
notification If OnOff is true:
notification: [["NOTIFICATION ON","PAYLOAD"],["NOTIFICATION OFF", "PAYLOAD"]]
Replace the notifications and the payloads.
If OnOff is false:
notification: ["NOTIFICATION", "PAYLOAD"]
Replace the notification and payload.

Custom devices

You can also create custom devices. I'm not really sure if it's useful but probably somebody need it. For that you need the option devices. Here are two examples:
If you want to do the same thing when you turn on and off your devices use this:
Note: You have to put the devices array you chose inside the config part.

devices: {
    devices: [{
        name: 'Custom 1',  
        port: 11102,              
        handler: `_this.sendSocketNotification("PAGE_CHANGED", 1)`
    }  
]}

If you want to do different things when you turn on or off your device use this:

devices: {
    {
        name: 'Custom 2',    
        port: 11103,            
        handler: `if(action === 1){  // 1 means on
                _this.sendSocketNotification("PAGE_CHANGED", 0)
            }else{
                _this.sendSocketNotification("PAGE_CHANGED", 1)      
            }`
    }  
]}

These are the configuration options for a custom device:

Option Description
name Here you can name your device. Make sure you didn't used the name before. Delete first the old device.
port Here you can give the device a static Port. I suggest that to you because then there aren't overlaps. Preferably start with the port 11100.
handler Use the handler for every thing you want to do. If you need this in your code use _this. Inside the examples above you can see how to differentiate between on and off.

Problems

  1. Devices not found:

    • Make sure that your Alexa and Pi are in the same Wifi. I had also the problem that my Pi was in the 2.4GHz Wifi and my Alexa in the 5GHz Wifi. It's only a problem when you discover the devices. To solve the problem disable one of the Wifis for a moment or turn the Wifi on your Pi on and off till it works.

    • Have you used the port before? Try every devices from the mirror. Probably the name is wrong. If that happen delete the device and discover for new devices. Define yourself ports for notification and custom devices to prevent this problem.

  2. Wrong action happen:

    • You used the Port before. To solve the problem delete old devices and define a custom port for the device if it's a notification or custom device.
  3. If you have still problems create an issue.

You can’t perform that action at this time.