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..

PHPStorm – Symfony log highlighting

To do, go into Settings -> Editor -> Log Highlighting (Ideolog)

Add new Log Format with the following config:

Name: Symfony
Message Pattern: ^\[(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})\]\s+(\w+).(\w+):\s+(.*)$
Message start pattern: ^\[
Time format: yyyy-MM-dd HH:mm:ss
Time capture group: 1
Severity capture group: 3
Category capture group: 2

special thanks to :