How to set up Magic Mirror on a Raspberry Pi

Set up a home dashboard solution on your Raspberry Pi

Sara Raap-van Bussel

3 minute read

As my entry to the challenge (see my earlier post) I am going to create a home dashboard. I want a screen in our living room that displays relevant information for our family. Things like our calendar’s, the weather, trash days, commute information etc. I looked at several solutions, but due to its extensibility I chose Magic Mirror.

Before we start, let’s make sure our Raspberry Pi is up to date:

sudo apt update
sudo apt upgrade -y

Installation

Let’s first download and install Node.js:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt install -y nodejs

Then we need to get Magic Mirror. We will clone the repository and check out the master branch:

git clone https://github.com/MichMich/MagicMirror

This will download the Magic Mirror code into a folder called MagicMirror. Make sure that you are cloning from the location where you want this folder to be.

Let’s finish the install:

cd MagicMirror
npm install

Copy the config sample file:

cp config/config.js.sample config/config.js

And start the application (with its visual components):

npm run start

Modules

The power of Magic Mirror is in the modules you can use. There are so many, and it is relatively easy (if you know how to code) to create your own. To manage these modules, you can use MMPM, the MagicMirror Package Manager. I personally don’t use this, because I already have Apache running, and MMPM wants to install NGINX which is a hassle next to Apache.

You can find a list of available modules on the Magic Mirror Wiki. Installing them is usually as easy as going to the modules folder (MagicMirror/modules) and cloning the module repository into that folder. However, do check the installation and configuration instructions for each module.

Automatically start Magic Mirror when the Raspberry Pi (re-)starts

It is pretty useful if Magic Mirror starts anytime the Raspberry Pi (re-)starts, without user intervention. We can use PM2, a production process manager, to accomplish this. We can install this easily with:

sudo npm install -g pm2

And make sure it always starts on boot:

pm2 startup

Next we need to make a script that can start Magic Mirror. We don’t want to risk overwriting this script when updating Magic Mirror, so place it outside your Magic Mirror folder. I put mine in my home folder:

cd ~
touch mm.sh

Open the script in Nano: nano mm.sh

And paste in these lines:

cd ./MagicMirror
DISPLAY=:0 npm start

Save and close the file with CTRL+Q, Y and enter.

Make the script executable using: chmod +x mm.sh

Now start Magic Mirror using PM2 and your script:

pm2 start mm.sh

And save these settings using

pm2 save

Your Magic Mirror will now start when the Raspberry Pi starts. If you want to manually restart Magic Mirror (to reload updated settings for example), you can use pm2 restart mm. Stop Magic Mirror with pm2 stop mm.

Delete cache to force reload of the settings

One of the problems I ran into when I was starting to set up my Magic Mirror, was that the settings were cached, and changes would not show up. This can be resolved by deleting your cache. On the Raspberry Pi execute:

cd ~
rm -rf .config/Electron