├── .gitignore ├── CHANGELOG.md ├── package.json ├── .github ├── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── SUPPORT.md └── CODE_OF_CONDUCT.md ├── LICENSE.txt ├── MMM-AlexaOnOff.js ├── node_helper.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/* 2 | package-lock.json 3 | 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # MMM-AlexaOnOff Change Log 2 | All notable changes to this project will be documented in this file. 3 | This project adheres to [Semantic Versioning](http://semver.org/). 4 | 5 | 6 | ## [0.1.1] - Allow Multiple Notifications 7 | 8 | * New: Add ability to trigger multiple notifications on single device 9 | 10 | 11 | ## [0.1.0] - Initial Commit and Public Release 12 | 13 | First public release 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MMM-AlexaOnOff", 3 | "version": "0.1.1", 4 | "description": "Send MagicMirror simple On/Off commands from any home automation device supporting Belkin Wemos devices.", 5 | "main": "MMM-AlexaOnOff.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/shbatm/MMM-AlexaOnOff.git" 9 | }, 10 | "keywords": [ 11 | "MagicMirror", 12 | "AlexaOnOff", 13 | "wemos", 14 | "fauxmo" 15 | ], 16 | "author": "shbatm", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/shbatm/MMM-AlexaOnOff/issues" 20 | }, 21 | "homepage": "https://github.com/shbatm/MMM-AlexaOnOff#readme", 22 | "dependencies": { 23 | "fauxmojs": "^1.0.3" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[FEATURE REQUEST] Your feature request idea here" 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | For general information on how to use this module, getting started setting up, or other questions, please visit the MagicMirror² Forum at https://forum.magicmirror.builders. To make sure the module developer is aware of your issue, please tag '@shbatm' on your forum post. 11 | 12 | **Is your feature request related to a problem? Please describe.** 13 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 14 | 15 | **Describe the solution you'd like** 16 | A clear and concise description of what you want to happen. 17 | 18 | **Describe alternatives you've considered** 19 | A clear and concise description of any alternative solutions or features you've considered. 20 | 21 | **Additional context** 22 | Add any other context or screenshots about the feature request here. 23 | -------------------------------------------------------------------------------- /.github/SUPPORT.md: -------------------------------------------------------------------------------- 1 | ## Support for this MagicMirror² Module 2 | 3 | For general information on how to use this module, getting started setting up, or other questions, please visit the MagicMirror² Forum at https://forum.magicmirror.builders. 4 | 5 | To make sure the module developer is aware of your issue, please tag '@shbatm' on your forum post 6 | 7 | If you experience errors with this module, or have a suggestion for improvements, please raise an issue by clicking the ISSUE button here in the Repository. When raising an issue, please include: 8 | 9 | - The configuration section for this module 10 | - The configuration section for any affected modules 11 | - Relavent logs: 12 | + From the console or `~/.pm2/logs/` 13 | + From the web console using DevTools (Ctrl+Shift+I) 14 | 15 | This information should be posted directly in the Issue, or in a Gist (https://gist.github.com). If you are not comfortable posting this in a public place, you may send a private chat on the MagicMirror forum, or e-mail the relavent info to support@shbatm.com. -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 shbatm 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[Bug] Describe your issue here" 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | For general information on how to use this module, getting started setting up, or other questions, please visit the MagicMirror² Forum at https://forum.magicmirror.builders. To make sure the module developer is aware of your issue, please tag '@shbatm' on your forum post. 12 | 13 | If you are having an actual issue, please include a clear and concise description of what the bug is. 14 | 15 | **To Reproduce** 16 | Steps to reproduce the behavior: 17 | 1. Go to '...' 18 | 2. Click on '....' 19 | 3. Scroll down to '....' 20 | 4. See error 21 | 22 | **Expected behavior** 23 | A clear and concise description of what you expected to happen. 24 | 25 | **Configuration** 26 | Please include: 27 | - The configuration section for this module 28 | - The configuration section for any affected modules 29 | 30 | * It may be easier to post these in a [Gist](https://gist.github.com) and post the link here. 31 | 32 | **Logs** 33 | If applicable, please include the relevant logs to help explain your problem. 34 | + From the console or `~/.pm2/logs/` 35 | + From the web console using DevTools (Ctrl+Shift+I) 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | 40 | If you are not comfortable posting the logs or configuration on a public place, you may also send @shbatm a private chat on the [MagicMirror² Forum](https://forum.magicmirror.builders) or send an e-mail to support@shbatm.com. E-mails asking general questions or without an accompanying Issue will not be answered. 41 | -------------------------------------------------------------------------------- /MMM-AlexaOnOff.js: -------------------------------------------------------------------------------- 1 | /* global Module */ 2 | 3 | /* Magic Mirror 4 | * Module: MMM-AlexaOnOff 5 | * 6 | * By shbatm 7 | * MIT Licensed. 8 | */ 9 | /* jshint esversion:6 */ 10 | 11 | Module.register("MMM-AlexaOnOff", { 12 | defaults: { 13 | netInterface: "wlan0", 14 | netProtocol: "IPv4", 15 | startPort: 21900, 16 | devices: [ 17 | "Magic Mirror", 18 | ] 19 | }, 20 | 21 | requiresVersion: "2.5.0", // Required version of MagicMirror 22 | 23 | start: function() { 24 | this.sendSocketNotification("INITIALIZE", this.config); 25 | }, 26 | 27 | getScripts: function() { 28 | return []; 29 | }, 30 | 31 | getStyles: function() { 32 | return []; 33 | }, 34 | 35 | socketNotificationReceived: function(notification, payload) { 36 | if (notification === "ACTION_RECEIVED") { 37 | this.config.devices.forEach(d => { 38 | if (typeof d === "object" && payload.device === d.name) { 39 | if (payload.action in d) { 40 | if (Object.prototype.toString.call(d[payload.action]) === '[object Array]') { 41 | // Array of notifications present 42 | d[payload.action].forEach(n => { 43 | this.sendNotification(n.notification, n.payload); 44 | }); 45 | } else { 46 | // Single notification present 47 | this.sendNotification(d[payload.action].notification, d[payload.action].payload); 48 | } 49 | } else { 50 | this.sendNotification("MMM-AlexaOnOff_ACTION_RECEIVED", payload); 51 | } 52 | } else if (typeof d === "string" && payload.device === d) { 53 | this.sendNotification("MMM-AlexaOnOff_ACTION_RECEIVED", payload); 54 | } 55 | }); 56 | } 57 | }, 58 | 59 | notificationReceived: function(notification, payload, sender) { 60 | // Do nothing. 61 | }, 62 | }); -------------------------------------------------------------------------------- /node_helper.js: -------------------------------------------------------------------------------- 1 | /* Magic Mirror 2 | * Node Helper: MMM-AlexaOnOff 3 | * 4 | * By shbatm 5 | * MIT Licensed. 6 | */ 7 | 8 | /* jshint node:true, esversion:6 */ 9 | 10 | var NodeHelper = require("node_helper"); 11 | const os = require('os'); 12 | const FauxMo = require('fauxmojs'); 13 | 14 | module.exports = NodeHelper.create({ 15 | start: function() { 16 | this.initialized = false; 17 | console.log("Module helper started for " + this.name); 18 | }, 19 | 20 | initialize: function() { 21 | if (!this.config) { console.error("MMM-AlexaOnOff Config Error."); return; } 22 | 23 | // Find the IP Address to use 24 | let netIfaces = os.networkInterfaces(); 25 | this.ip = "127.0.0.1"; 26 | 27 | if (!(this.config.netInterface in netIfaces)) { 28 | console.warn(`Requested network interface ${this.config.netInterface} not found!`); 29 | } else { 30 | let netDetail = netIfaces[this.config.netInterface].find(x => x.family === this.config.netProtocol); 31 | this.ip = netDetail.address; 32 | } 33 | 34 | let dev = []; 35 | 36 | this.config.devices.forEach((d, i) => { 37 | let dName = (typeof d === "string") ? d : d.name; 38 | console.log( this.config.startPort + i); 39 | dev.push({ 40 | name: dName, 41 | port: this.config.startPort + i, 42 | handler: (action) => { 43 | console.log(`Fauxmo Action for ${dName}: ${action}`); 44 | this.sendSocketNotification("ACTION_RECEIVED", { device: dName, action: action }); 45 | } 46 | }); 47 | }); 48 | 49 | this.fauxMo = new FauxMo({ 50 | ipAddress: this.ip, 51 | devices: dev 52 | }); 53 | 54 | console.info(`FauxMo service started. Listening on ${this.ip}:${this.config.startPort}${(this.config.devices.length > 1) ? "-" + 55 | (this.config.startPort + (this.config.devices.length - 1)) : ""}`); 56 | this.initialized = true; 57 | }, 58 | 59 | socketNotificationReceived: function(notification, payload) { 60 | if (notification === "INITIALIZE" && !this.initialized) { 61 | this.config = payload; 62 | this.initialize(); 63 | } 64 | } 65 | }); -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [INSERT EMAIL ADDRESS]. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MMM-AlexaOnOff 2 | 3 | This is a module for the [MagicMirror²](https://github.com/MichMich/MagicMirror/). 4 | 5 | Send MagicMirror simple On/Off commands from any home automation device supporting Wemos devices through the [`fauxmojs`](https://github.com/dsandor/fauxmojs) Node.js module. No AWS, microphones, buttons, or 3rd-Party hubs required. 6 | 7 | ### DISCLAIMER: Project Not in Active Development 8 | 9 | I am not actively working on this project at the moment since I don't use it on my MagicMirrors. I am currently using NodeRED and the API provided by [MMM-Remote-Control](https://github.com/Jopyth/MMM-Remote-Control) to control my mirrors. I'm not going to be able to perform any direct troubleshooting, but I will accept any PRs to correct identified issues. 10 | 11 | ## Installation 12 | 13 | *Assumptions:* This module assumes that you have a stand-alone home automation device, such as an Amazon Echo, Echo Dot, Google Home Hub, etc. This module receives commands from these devices over your WiFi and, using [dsandor's](https://github.com/dsandor) fauxmojs Fake Wemos module, translates them into commands for the MagicMirror. 14 | 15 | This module also does not control anything on it's own by design. There are plenty of Modules out there to turn on/off the monitor, switch profiles, show/hide modules etc. This module simply rebroadcasts commands when received as notifications to other modules. 16 | 17 | #### To Install: 18 | 19 | 1. Install the module in your Mirror: 20 | 21 | ```shell 22 | cd ~/MagicMirror/modules 23 | git clone https://github.com/shbatm/MMM-AlexaOnOff.git 24 | cd MMM-AlexaOnOff/ 25 | npm install 26 | ``` 27 | 2. Setup the configuration using the details below. 28 | 3. Discover devices on your home automation system of choice. 29 | - For Amazon Alexa devices, simply say "Alexa, discover my devices" 30 | 4. For each device you have configured, you can say "Alexa, turn [device name] on", or "off". 31 | - These `on` and `off` commands will send the notifications you have configured to the different modules. 32 | 33 | ## Using the module 34 | 35 | To use this module, add the following configuration block to the modules array in the `config/config.js` file: 36 | ```js 37 | var config = { 38 | modules: [ 39 | { 40 | module: 'MMM-AlexaOnOff', 41 | config: { 42 | // See below for configurable options 43 | } 44 | } 45 | ] 46 | } 47 | ``` 48 | 49 | ## Configuration options 50 | 51 | | Option | Description 52 | |----------------- |----------- 53 | | `devices` | *Required* devices accepts a mixed array of strings with device names (e.g. `"Magic Mirror"`) or objects of the form:
`{`
` name: "Device Name",`
` on: {`
` notification: "NOTIFICATION_TITLE",`
` payload: "NOTIFICATION PAYLOAD"`
` },`
` off: { `
` notification: "NOTIFICATION_TITLE",`
` payload: "NOTIFICATION PAYLOAD"`
` },`
`}`

In addition to a single notification, `on:` or `off:` can also accept an array of notifications to send. See example below.
*Note:* If you provide only string names, or don't provide details on the `on` or `off` notification you want to send, a generic "MMM-AlexaOnOff_ACTION_RECEIVED" notification will be sent with the device name and action in the payload. While not useful by itself, you could have a module that watched for this and did something. 54 | | `netInterface` | *Optional* Network interface you are using
Default: `wlan0` for WiFi. If your mirror uses wired ethernet, use `eth0`. 55 | | `netProtocol` | *Optional* Network protocol you are using
Default: `IPv4`, change only if you use `IPv6` exclusively. 56 | | `startPort` | *Optional* Starting network port to use. Each device you create will be given its own port in a series starting with this one. 57 | 58 | ## Example - Turn On/Off Monitor using an Amazon Echo and MMM-OnScreenMenu module 59 | 60 | The [MMM-OnScreenMenu](https://github.com/shbatm/MMM-OnScreenMenu) module allows for controlling your mirror from notifications [sent by other modules](https://github.com/shbatm/MMM-OnScreenMenu#controlling-the-menu-from-another-module). 61 | 62 | To use: 63 | 64 | 1. Start MagicMirror with configuration included below. 65 | 2. Say "Alexa, discover my devices." 66 | - Alexa should find a new device called "Magic Mirror" 67 | 3. Say "Alexa, turn off magic mirror." 68 | - This module will receive the command, find an "off" notification to send. 69 | - The MMM-OnScreenMenu module will recieve a "ONSCREENMENU_PROCESS_ACTION" notification telling it to turn off the monitor. 70 | 71 | #### Example Configuration 72 | 73 | **Turn on or off the monitor using MMM-OnScreenMenu module:** 74 | ```js 75 | { 76 | module: 'MMM-OnScreenMenu', 77 | position: 'bottom_right', 78 | }, 79 | { 80 | module: 'MMM-AlexaOnOff', 81 | config: { 82 | devices: [{ 83 | name: "Magic Mirror", 84 | on: { 85 | notification: "ONSCREENMENU_PROCESS_ACTION", 86 | payload: { actionName:'monitorOn' } 87 | }, 88 | off: { 89 | notification: "ONSCREENMENU_PROCESS_ACTION", 90 | payload: { actionName:'monitorOff' } 91 | }, 92 | }] 93 | } 94 | } 95 | ``` 96 | 97 | **Show or hide a module using the MMM-RemoteControl module:** 98 | (see [here](https://github.com/Jopyth/MMM-Remote-Control#list-of-actions) for specifics on the module identifier needed) 99 | ```js 100 | { 101 | module: 'MMM-AlexaOnOff', 102 | config: { 103 | devices: [{ 104 | name: "Clock Module", 105 | on: { 106 | notification: "REMOTE_ACTION", 107 | payload: { action: "SHOW", module: "module_3_clock" } 108 | }, 109 | off: { 110 | notification: "REMOTE_ACTION", 111 | payload: { action: "HIDE", module: "module_3_clock" } 112 | }, 113 | }] 114 | } 115 | } 116 | ``` 117 | 118 | **Sending multiple notifications with one device:** 119 | Config section to do this with MMM-Remote-Control (see [here](https://github.com/Jopyth/MMM-Remote-Control#list-of-actions) for specifics on the module identifier needed): 120 | ```js 121 | { 122 | module: 'MMM-AlexaOnOff', 123 | config: { 124 | devices: [{ 125 | name: "Calendar", 126 | on: [ 127 | { 128 | notification: "REMOTE_ACTION", 129 | payload: { action: "SHOW", module: "module_4_calendar" } 130 | }, 131 | { 132 | notification: "REMOTE_ACTION", 133 | payload: { action: "HIDE", module: "module_3_clock" } 134 | } 135 | ], 136 | off: [ 137 | { 138 | notification: "REMOTE_ACTION", 139 | payload: { action: "HIDE", module: "module_4_calendar" } 140 | }, 141 | { 142 | notification: "REMOTE_ACTION", 143 | payload: { action: "SHOW", module: "module_3_clock" } 144 | } 145 | ], 146 | }] 147 | } 148 | } 149 | ``` 150 | --------------------------------------------------------------------------------