Magic Mirror – PIR Sensor – Update #3

The idea of installing the motion detector is that it either turns the HDMI signal on or off. IF the motion detector does not detect any movement for 9 seconds (value that can be changed as required), it switches of the HDMI Signal. As soon as movement is registered again, it switches the signal on again. If movement is also registered during 60 seconds, the timer is reset to zero..

The pir sensor connected to raspberry pi with female-female jumper cable.

  • VCC to Pin 2
  • GND to Pin 6
  • OUT to Pin 12

And now the motion detector should switch the HDMI signal on or off. Two shell scripts are created for this. The first is created with command:

sudo nano /home/pi/magicmirror/

with following content:

vcgencmd display_power 1 > /dev/null

the second script with the command:

sudo nano /home/pi/magicmirror/

with following content:

vcgencmd display_power 0 > /dev/null

Now a python script.. Create this script with the command:

sudo nano /home/pi/magicmirror/

with following content:

#!/usr/bin/env python

import sys
import time
import RPi.GPIO as io 
import subprocess


def main():
    io.setup(PIR_PIN, io.IN)
    turned_off = False
    last_motion_time = time.time()
    while True:
        if io.input(PIR_PIN):
            last_motion_time = time.time()
            if turned_off:
                turned_off = False
            if not turned_off and time.time() > (last_motion_time + SHUTOFF_DELAY):
                turned_off = True
            if not turned_off and time.time() > (last_motion_time + 1):
def turn_on():"sh /home/pi/magicmirror/", shell=True)

def turn_off():"sh /home/pi/magicmirror/", shell=True)

if __name__ == '__main__':
    except KeyboardInterrupt:

Now service file… a service file has to be added so that this script is always executed when it is started. The command:

cd /lib/systemd/system/
sudo nano pir_monitor_controller.service

with the following content:

Description=MagicMirror PIR Service       
ExecStart=/usr/bin/python /home/pi/magicmirror/ > /home/pi/magicmirror/pir_monitor_controller.log 2>&1       
sudo systemctl daemon-reload 
sudo systemctl enable pir_monitor_controller.service 
sudo systemctl start pir_monitor_controller.service

and Testing..

Magic Mirror – A another Smart Mirror Hobby Project



  • Unzip the image and install it to an SD card
    • Official image mirror is here or
  • Configure your WIFF in magicmirroros-wpa-supplicant.txt at the root of the flashed card.
  • Put SD-Card in to Raspberry PI and Boot up.

Raspberry PI Configuration:

Hostname is magicmirroros (not raspberrypi as default), username: pi and inital password is: raspberry

ssh pi@magicmirroros
  1. The partition created (section of the microSD card that can be used) does not yet correspond to the full storage capacity of the microSD card.
    1. sudo raspi-config
    2. Advanced Options => Expand Filesystem.
  2. Date, Time, Country, Keyboard etc. Configuration
    1. sudo raspi-config
    2. Localisation Options
      1. Change with your Local Settings
  3. Update the Software Packages
    1. sudo apt-get update
    2. sudo apt-get upgrade
    3. sudo rpi-update
    4. sudo reboot
  4. Deactivating the screen saver
    1. sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
    2. Add and the end of file
      1. @xset s noblank
      2. @xset s off
      3. @xset -dpms
    3. sudo nano /etc/lightdm/lightdm.conf
      1. Add under [SetDefaults] Section
      2. xserver-command=X -s 0 -dpm
  5. Active Hardware
    1. Raspbian automatically switches off hardware to save energy
      1. sudo nano /etc/network/interfaces
      2. Add under wlan0 section
        1. wireless-power off

Raspberry PI and Magic Mirror OS 2 Result:

Custom Frame : Work In Progress

Frame Update #2 – 21 – 22.02.2020

Last Update #3 – 22.03.2021

  • Frame
    • Frame ist completed, but not with spray painting, rather with wrapping folie, but looks also good.
  • Software
    • compliments Module with my sequenze changed.
    • Calendar Module with my Family Calendar integrated.
    • Maybe Blog Statictics or Log can be integrated in the future.



huge thanks to Allah for success and I. Peker for Frame Creating Support!