MagicMirror² Documentation
website·Indexed 36 days ago
https://docs.magicmirror.buildersOfficial documentation for MagicMirror², an open-source smart mirror platform. Includes guides on installation, configuration, and core development, as well as detailed instructions for creating custom modules using the core module file, Node helpers, and the rendering component. Covers default modules such as Clock, Calendar, Weather, News Feed, and Compliments.
What's inside MagicMirror
- MagicMirror² is an open-source modular smart mirror platform designed to convert a standard mirror into a personal assistant display. It utilizes a modular plugin system and uses Electron as an application wrapper, eliminating the need for separate web server or browser installations. The software is designed to be run on a display placed behind a two-way mirror.
Alternative installation methods for MagicMirror²
While manual installation is the only officially supported method, several community-maintained alternatives exist:
- Automatic Scripts: MagicMirror Scripts or The MagicMirror Package Manager (mmpm).
- Containerization: Docker images (available via khassel/magicmirror) or Kubernetes Helm Charts (khassel/magicmirror-helm).
- OS Image: MagicMirrorOS, a full Raspberry Pi OS image with Docker-based MagicMirror pre-installed.
- NPM: Available via the npm-registry.
Understand the MagicMirror notification system
MagicMirror uses a notification system that allows the core to send messages to modules, and allows modules to send notifications to other modules. To implement this in a custom module, use thenotificationReceivedhandler to listen for incoming messages and thesendNotificationmethod to broadcast messages.MagicMirror² Project Philosophy and Core Principles
MagicMirror² is designed as an open-source platform for Raspberry Pi enthusiasts and developers, prioritizing simplicity and accessibility to encourage community contribution and learning. The project adheres to several core principles:
- Simplicity as a Foundation: The project avoids overly complex frameworks (like Vue or SASS) to ensure that users can modify a single file and see immediate results without needing a complex build pipeline.
- Modular and Open: The architecture is modular, allowing users and contributors to easily add or remove features.
- Accessibility: It serves as an entry point for beginners to learn software development and open-source collaboration.
- Collaborative Growth: The project is driven by community feedback, code contributions, and shared ideas.
Trigger notifications and alerts from other modules
Developers can trigger the alert module by sending a
SHOW_ALERTnotification.- To trigger a notification: Send
SHOW_ALERTwith an object containingtype: "notification". - To trigger an alert: Send
SHOW_ALERTwith an empty object or alert-specific parameters.
// Trigger a notification self.sendNotification("SHOW_ALERT", { type: "notification", title: "Hello", message: "World" }); // Trigger an alert self.sendNotification("SHOW_ALERT", { title: "Alert", message: "Warning!" });- To trigger a notification: Send
Render a MagicMirror component using getDom
ThegetDommethod is used to procedurally generate the module's UI. MagicMirror calls this method whenever the screen needs to be updated. It must return an HTMLElementcontaining the content to be displayed. To trigger a re-render when data changes, callthis.updateDom().getDom: function() { const wrapper = document.createElement("div"); wrapper.innerHTML = 'Hello world!'; return wrapper; }Recompile native Node modules for Electron
If yournode_helper.jsuses native Node modules, they must be recompiled for Electron using@electron/rebuildto function correctly.npm install --save-dev @electron/rebuildAdd to package.json:
"scripts": { "postinstall": "./node_modules/.bin/electron-rebuild" }Sync Office 365 calendars with MagicMirror
Office 365 calendars use date formats incompatible with MagicMirror 2. To use an Office 365 calendar, you must route it through Google Calendar:
- Import your existing Office 365 calendar into Google Calendar to capture past events.
- Use Microsoft Flow to create a trigger that automatically adds new Office 365 events to your Google Calendar (runs every 5 minutes).
- Use the private address generated by Google Calendar as the source URL in the MagicMirror calendar module configuration.
Apply animations to MagicMirror modules
Since version 2.25.0, MagicMirror supports animations based on the animate.css library. Animations can be applied in the following locations:
- Global module configuration (via the
animatedproperty). - Within the
this.hide()function in the core module file. - Within the
this.show()function in the core module file. - Within the
this.updateDom()function in the core module file.
Animation names are case-sensitive. If an invalid name is provided, the system defaults to the 'fade' animation. You must use
animateInnames for appearing elements andanimateOutnames for hiding elements; they are not interchangeable.- Global module configuration (via the
Use the MagicMirror Logger for application logging
MagicMirror provides aLogconvenience wrapper that acts as a proxy to standardconsole.logmethods. It is used to output information, general logs, and errors to the console. Because MagicMirror runs in an Electron front-end/browser environment, logs may appear in both the terminal and the browser's developer console.Log.info("info"); Log.log("log"); Log.error("error");Target specific modules in custom CSS
Every module (including 3rd-party modules) is wrapped in a div with a CSS class named after the module. To apply styles to a specific module, use its corresponding class name. For example, the Clock module can be targeted using the.clockclass..clock { /* Your custom styles for the clock module */ }Render a MagicMirror component using Nunjucks templates
IfgetDomis not overridden, MagicMirror uses the Nunjucks templating engine. To implement this, definegetTemplateto return the filename of the template andgetTemplateDatato return an object containing the data to be injected into the template.// In MMM-MyModule.js getTemplate: function() { return "MMM-MyModule.njk"; }, getTemplateData: function() { return { list: ["item 1", "item 2", "item 3"], }; }// In MMM-MyModule.njk
<ul> {% for item in list %} <li>{{ item }}</li> {% endfor %} </ul>