MagicMirror² v2.14.0 is available! For more information about this release, check out this topic.

Motion Detect/PIR-Sensor tvservice -p does not turn on TV

  • Hi there,

    i’m currently trying to implement my PIR-Sensor HCSR501. My goal is, like those of many others, to turn off my HDMI output when there is no motion in front of the mirror. The sensor itself works and is able to detect movements. I’ve been trying to use the MMM-PIR-Sensor module but without success…
    I was looking for another solution, without a module and found this explanation
    (jump to Detecting movement)

    Since I wasn’t quite sure about the LED PIN and the io.output stuff I removed those parts from the script.

    #!/usr/bin/env python
    import sys
    import time
    import RPi.GPIO as io
    import subprocess
    SHUTOFF_DELAY = 10 # seconds
    PIR_PIN = 4       # 22 on the board
    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()
                print ".",
                if turned_off:
                    turned_off = False
                if not turned_off and time.time() > (last_motion_time + 
                    turned_off = True
                if not turned_off and time.time() > (last_motion_time + 1):
    def turn_on():"sh /home/pi/", shell=True)
    def turn_off():"sh /home/pi/", shell=True)
    if __name__ == '__main__':
        except KeyboardInterrupt:

    sudo tvservice -p

    sudo tvservice -o

    The sensor recognizes movement and turns off the screen as soon as moving ends. But unfortunately the turn on process does not work. Even when I try to use the command manually

    sudo tvservice -p

    nothing happens…

    I’ve asked myself if this could be related to my (older) Toshiba 42XV635D TV but then I remembered that every time I rebooted the pi (which is connected to the TV via HDMI) the TV automatically was turned on (of course it was turned off before the reboot)

    Can somebody help me with that? I (think) i’m nearly there…


    I have found two different commands here… It says that, in relation to the tvservice command this commands would bring back the TV signal immediately. Actually I have no idea what i’m saying right now 😉 So do they commands make any sense?

    vcgencmd display_power 1
    vcgencmd display_power 0

  • This works for me !

    /opt/vc/bin/tvservice -p; sudo /bin/chvt 6; sudo /bin/chvt 7

    instead of…

    tvservice -p


  • @beck0r said in Motion Detect/PIR-Sensor tvservice -p does not turn on TV:

    vcgencmd display_power 0

    Using vcgencmd fixed all my PIR sensor issues, where not every display was turning on/off corectly. See my reply in this thread:

  • I did the same thing with a webcam and motion. I could not get tvservice to work but no matter, vcgencmd works well:

    echo STOP MOTION
    vcgencmd display_power 0
    vcgencmd display_power 1

    It took a while to get these commands working because of the permissions so double check all your commands run as the user you want and change perms, groups accordingly if not.

  • Thanks a lot. Working as described.

Log in to reply