MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord

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

    Troubleshooting
    3
    5
    3244
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      beck0r last edited by beck0r

      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

      http://www.ofbrooklyn.com/2014/01/2/building-photo-frame-raspberry-pi-motion-detector/
      (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.
      Result:

      #!/usr/bin/env python
      
      import sys
      import time
      import RPi.GPIO as io
      import subprocess
      
      io.setmode(io.BCM)
      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 ".",
                  sys.stdout.flush()
                  if turned_off:
                      turned_off = False
                      turn_on()
              else:
                  if not turned_off and time.time() > (last_motion_time + 
                                                       SHUTOFF_DELAY):
                      turned_off = True
                      turn_off()
                  if not turned_off and time.time() > (last_motion_time + 1):
                      time.sleep(.1)
      
      def turn_on():
          subprocess.call("sh /home/pi/monitor_on.sh", shell=True)
      
      def turn_off():
          subprocess.call("sh /home/pi/monitor_off.sh", shell=True)
      
      if __name__ == '__main__':
          try:
              main()
          except KeyboardInterrupt:
              io.cleanup()
      

      monitor_on.sh

      sudo tvservice -p
      

      monitor_off.sh

      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…

      PS:

      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?

      https://pi-buch.info/tag/tvservice/

      vcgencmd display_power 1
      
      vcgencmd display_power 0
      
      1 Reply Last reply Reply Quote 0
      • B
        beck0r last edited by

        This works for me !

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

        instead of…

        tvservice -p
        

        Source:

        https://www.elektronik-kompendium.de/sites/raspberry-pi/2111101.htm

        1 Reply Last reply Reply Quote 0
        • E
          envedede last edited by

          @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: https://forum.magicmirror.builders/topic/2618/mmm-pir-sensor-black-screen/3

          1 Reply Last reply Reply Quote 0
          • Z
            ZtM last edited by yawns

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

            #!/bin/bash
            #end-motion.sh
            
            echo STOP MOTION
            
            vcgencmd display_power 0
            
            #!/bin/bash
            #start-motion.sh
            
            echo START MOTION
            
            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.

            1 Reply Last reply Reply Quote 0
            • B
              beck0r last edited by beck0r

              Thanks a lot. Working as described.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Enjoying MagicMirror? Please consider a donation!
              MagicMirror created by Michael Teeuw.
              Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
              This forum is using NodeBB as its core | Contributors
              Contact | Privacy Policy