My Raspberry Pi mirror has shut off a few times by accident (overheated, lost power, etc). Every time I turned it back on it was kind of a pain - I had to take the mirror off the wall, hook up my keyboard and mouse, start up the mirror, etc. This happened enough that I wanted to automate a solution. I finally found this article and followed “method 2”. I thought I’d summarize here in case this can help anyone else.
What this will do
Start up your mirror whenever your raspberry pi gets turned on.
We’ll utilize Raspian’s
autostart mechanism to run a shell script whenever your Raspberry Pi starts up. The shell script will turn off sleep mode on your Pi and start your mirror.
1) Write a shell script
Create a shell script in the home directory. From the terminal, type:
$ vi /home/pi/start-mirror.sh
Copy this code into the
start-mirror.sh file that was just opened, then save and close the file:
#!/bin/bash sudo xset -dpms sudo xset s off cd /home/pi/MagicMirror && npm start
3) Create a .desktop file
This will utilize the
autostart system on the pi. Your script will run after the desktop system starts up.
$ mkdir /home/pi/.config/autostart $ vi /home/pi/.config/autostart/mirror.desktop
Note: you might not need to run the first command to create the autostart directory - I already had this directory on my computer.
Copy this code into the mirror.desktop file and save it:
[Desktop Entry] Type=Application Name=MirrorStart Exec=sh /home/pi/start-mirror.sh
After this saves, you’re all set. Reboot the pi and test it out:
After the reboot you should see the Desktop pop up for 10-20 seconds, then your mirror should automatically start up.