MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    PIR Sensor

    Scheduled Pinned Locked Moved General Discussion
    7 Posts 3 Posters 2.5k Views 2 Watching
    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.
    • T Offline
      tinsebayacc
      last edited by

      Hi, i have recently started building a smart mirror. Its taken me a while (software side) but i am getting there. My only issue is the PIR sensor. I have followed a tutorial and have it working great. It switches off my tv and turns it back on again. The problem is the no signal back ground i have when it switches off. I have a lg tv and its got an annoying cube that bounces around the screen. My question is how do i turn my screen black and not off. I have read some articles but i have not found any that work for me. I am using a PIR.py script and two on/off shell scripts. The shell scripts are as follows

      monitor_on.sh
      vcgencmd display_power 1

      monitor_off.sh
      vcgencmd display_power 0

      This works perfectly for turning my tv/hdmi off and back on again.
      I have read that the following shell scripts should turn the screen black but ive had no luck so far

      export DISPLAY=:0
      xset dpms force on

      export DISPLAY=:0
      xset dpms force off

      Any help would be appreciated as im a beginner and have run out of ideas. Thanks

      1 Reply Last reply Reply Quote 0
      • brobergB Offline
        broberg Project Sponsor
        last edited by

        Do you have xscreensaver installed? that should do exactly what you are asking
        https://www.jwz.org/xscreensaver/man3.html

        Or maybe a wifi- wall plug could work better? (i.e cut the power to the tv completly)

        T 1 Reply Last reply Reply Quote 0
        • T Offline
          tinsebayacc @broberg
          last edited by

          @broberg

          Thanks for your response. No I haven’t got that installed. My question is how would I add that into my pir script so that the screen saver came on after a set time and to go off when the pir is activated? Many thanks

          brobergB 1 Reply Last reply Reply Quote 0
          • brobergB Offline
            broberg Project Sponsor @tinsebayacc
            last edited by

            @tinsebayacc

            Just replace your screen on and off commands with the xscreensaver commands. Should work.

            like

            for black screen :
            xscreensaver-command -activate

            and to deactivate black screen :
            xscreensaver-command -deactivate

            1 Reply Last reply Reply Quote 0
            • T Offline
              tinsebayacc
              last edited by tinsebayacc

              Thanks again, i have just tried the following but nothing happens. If i run “xscreensaver-command -activate” from the terminal i get

              “xscreensaver-command: warning: $DISPLAY is not set: defaulting to “:0.0”.
              xscreensaver-command: activating”

              It then works and goes into a black screen, same thing for when i deactivate it. But nothing happens when i add it to my sh monitor on/off commands for my pir.py script.

              S 1 Reply Last reply Reply Quote 0
              • S Offline
                sdetweil @tinsebayacc
                last edited by

                @tinsebayacc U need to add

                DISPLAY=:0

                in front of your command

                See the installers/mm.sh for an example

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 0
                • T Offline
                  tinsebayacc
                  last edited by

                  Thank you, that got rid of that error. Still no joy with the PIR sensor though unfortunately.
                  The strange thing is if i change my monitor_on and monitor_off sh files to

                  vcgencmd display_power 0
                  vcgencmd display_power 1

                  the pir works fine and shuts off / turns on my monitor.

                  these are my scrips

                  #!/usr/bin/env python

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

                  io.setmode(io.BCM)
                  SHUTOFF_DELAY = 30 # in seconds, how long the monitor will be on until next button press or PIR detection
                  PIR_PIN = 22 # 15 on the board (this needn’t to be a PIR. Can be a button also)
                  LED_PIN = 16 # optional, don’t use as Relay-PIN. It just shows detection time of the PIR without delay time

                  def main():
                  io.setup(PIR_PIN, io.IN)
                  io.setup(LED_PIN, io.OUT)
                  turned_off = False
                  last_motion_time = time.time()

                  while True:
                      if io.input(PIR_PIN):
                          last_motion_time = time.time()
                          io.output(LED_PIN, io.LOW)
                          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):
                              io.output(LED_PIN, io.HIGH)
                      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 script

                  DISPLAY=:0 xscreensaver-command -deactivate

                  monitor off script

                  DISPLAY=:0 xscreensaver-command -activate

                  1 Reply Last reply Reply Quote 0

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • 1 / 1
                  • First post
                    Last post
                  Enjoying MagicMirror? Please consider a donation!
                  MagicMirror created by Michael Teeuw.
                  Forum managed by Sam, technical setup by Karsten.
                  This forum is using NodeBB as its core | Contributors
                  Contact | Privacy Policy