Knowledge for the World

How to install Magic Mirror on your Raspberry Pi

  • by Zach (125)
  • 30 minutes

Magic Mirror is essentially a webpage that runs on a web server housed inside your Raspberry Pi. It displays tons of cool information and can even be used to create your very own smart mirror!

Note: I recommend using either the Raspberry Pi 3 to complete this project, but the Raspberry 2/Zero/Zero W will also work.

1

First, you'll need to install the latest version of Raspbian, the official Raspberry Pi operating system (based on Debian Linux). Howchooer tyler wrote a great guide on installing Raspbian Stretch that will walk you through the process step by step.

2

Unmount the SD card from your computer and insert it into your Pi. Connect your keyboard, mouse, HDMI cable and, lastly, the Pi's power cable. You will now see the Raspbian Pixel desktop (GUI).

3

Our Magic Mirror needs to be wifi-enabled so that it can connect to the internet and so that we can access it remotely to set things up.

In the top right of your screen, click on the network icon (two computers with an X). Select your network, enter your wifi password, and click OK.

The Raspberry Pi 3 and Raspberry Pi Zero W have built-in wifi, older Pis (and the normal Pi Zero) do not. If you're using a Pi without built-in wifi, you'll need to connect a wifi dongle to your Raspberry Pi.

4

We'll need our Pi's IP so that we can connect to it from our regular computer and complete the rest of the installation from there.

On your Pi, navigate to Menu > Accessories > Terminal. Type the following and press enter:

ifconfig

Your Pi's IP will be located next to inet addr.

Alternatively, you can also ping your Pi from your computer to obtain the IP address; I wrote a short guide on pinging the Pi in OS X.

5

On newer versions of Raspbian, SSH is disabled by default. You can either enable SSH using the SD card or, on your Pi, navigate to Preferences > Raspberry Pi Configuration > Interfaces and enable it there.

After enabling SSH, open Terminal (Mac) or Command Prompt (Windows). Type the following command and press enter:

ssh pi@your-pis-ip-address

When prompted for your password, use the default Raspberry Pi password: raspberry. If you see an authenticity of host warning, type yes and press enter.

6

Change the default password
For better security, I recommend you change you Pi's default password to something else. Type the following, press enter, and follow the prompts:

passwd

Expand your Pi's filesystem to utilize all available space, and also to boot into the GUI
Type the following and press enter:

sudo raspi-config

Select Expand Filesystem and press enter. Then, reboot your Pi:

sudo reboot

Update your Pi

sudo apt-get update
sudo apt-get upgrade --yes

7

There are a number of great Magic Mirror dashboards available -- I went with one created by Michael Teeuw since it's beautiful and he's a bit of a Magic Mirror pioneer. More information for the MagicMirror dashboard can be found on its Github repo.

We're going to use the automatic installer to save us some time. To do this, run the following command:

bash -c "$(curl -sL https://raw.githubusercontent.com/MichMich/MagicMirror/master/installers/raspberry.sh)"

Note: The automatic installer officially supports the Pi 2 and 3. If you want to run MagicMirror on a Pi 1 or Pi Zero, you'll need to use the server-only version and install a full-screen browser manually. Save yourself some time and just use a Pi 3. :)

When prompted whether you want to use pm2 for auto starting of your MagicMirror, select "yes" by typing y and pressing enter.

MagicMirror should start automatically! If it doesn't, run:

cd ~/MagicMirror && DISPLAY=:0 npm start
8

Now we'll tell MagicMirror to start on system boot. Run the following command:

pm2 startup

That command will output another command for you to run. Run that command. It may vary for your system, but for me it was:

sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi

Next, create a startup shell script:

cd ~
nano mm.sh

Add the following to that file, save, and exit:

cd ~/MagicMirror
DISPLAY=:0 npm start

Make sure the script is executable:

chmod +x mm.sh

Next, start MagicMirror and force it to start on boot:

pm2 start mm.sh

Finally, reboot your Pi:

sudo reboot

9

If your magic mirror needs to be in portrait mode (as mine is), you'll need to tell your Pi to rotate the display:

sudo nano /boot/config.txt

Add the following lines:

# rotate the screen
display_rotate=1 # use lcd_rotate=3 to rotate in the other direction
10

To keep your Pi from going into sleep mode (which defeats the purpose of the magic mirror), run the following:

sudo nano ~/.config/lxsession/LXDE-pi/autostart

Add the following, save, exit, and reboot:

@xset s 0 0
@xset s noblank
@xset s noexpose
@xset dpms 0 0 0

If you'd like to save electricity, you can also add a PIR sensor to your Raspberry Pi and install the MagicMirror PIR module to wake your mirror when it senses motion. :)

11

Customize the interface

Time to configure the interface for your location and needs!

cd ~/MagicMirror
nano config/config.js

Configure weather
Change both the "currentweather" and "weatherforecast" weather module settings to your location.

Change the JavaScript config object to add your city's name, location ID, and free OpenWeatherMap API key:

config: {
    location: "Tampa",
    locationID: "4174757",
    appid: "YOUR_OPENWEATHER_API_KEY",
    units: "imperial" // Use Fahrenheit instead of Celsius
}

Configure compliments
MagicMirror spins through an array of complements based on the time of day. If you'd like, you can change these compliments to something different -- famous quotes, perhaps?

Configure your calendar
By default, MagicMirror shows a calendar containing US holidays. You can change these by pasting a calendar's public URL here.

For now, I decided to remove both and instead subscribe to the Tampa Bay Rays schedule and a Google Calendar containing a list of national holidays. These calendar URLs normally end in .ics, and you can Google the one you're looking for.

Down the road, I'll add authentication so I can link up my Google Calendar. You can also change the icon that's loaded by changing the value of calendar.urls.symbol; this value should be from the list of FontAwesome icons found here, with the "fa-" portion removed. For example, 'fa-bullhorn' becomes just 'bullhorn'.

When you're finished configuring, save and exit.

12

There are tons of other fun and useful MagicMirror modules you can play around with. Find a really great one? Post in the comments section below and I'll include it here!

13

Now that your MagicMirror setup is working, I highly recommend you create a backup of your SD card image. This is totally optional, but if something gets messed up when installing Jasper it will be easy to revert. I wrote a guide on how to back up your SD card for Mac or, if you have Windows, Lifehacker wrote a great guide as well.

14

Make your magic mirror voice-enabled by installing Google Assistant. Be sure to check out my Google Home-enabled magic mirror guide to learn how to do this.

15

Jasper is an open-source text-to-speech and speech-to-text processing platform, allowing you to speak commands to your Raspberry Pi such as to play a Spotify playlist, add things to your Google Calendar, or integrate with openHAB to control your entire house. Jasper is definitely a cool feature to add to your mirror -- if you're up for the task!

I wrote an exhaustive guide on how to install Jasper on your Pi. You can also see my completed Magic Mirror build here, which is a great read if you're also into woodworking.

16

The Raspberry Pi can be a complicated beast. Post below and I'll do my best to help you out!