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 / wakes screen up when audio is detected

    Scheduled Pinned Locked Moved System
    2 Posts 1 Posters 2.3k 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.
    • A Offline
      andr1
      last edited by

      I needed a “module” that wakes my mirror up when i started playing audio from it… here’s the python code and shell scripts needed…

      import RPi.GPIO as GPIO
      import time
      import subprocess
      isMonitorOn = False
      isPlaying = False
      sleepyTimer = 180                       #seconds until mirror goes to sleep
      i = 0
      counter = 0
      GPIO.setwarnings(False)
      GPIO.setmode(GPIO.BCM)
      GPIO.setup(4, GPIO.IN)
      print "Starting up!"
      print isPlaying
      while True:
             i=GPIO.input(4)
             print counter
             proc = subprocess.Popen('./isMonitorOn.sh', stdout=subprocess.PIPE)
             isMonitorOn = bool(proc.stdout.read())
             proc1 = subprocess.Popen('./isAudioOn.sh', stdout=subprocess.PIPE)
             isPlaying = bool(proc1.stdout.read())
             if i==0:
                counter += 1
                if not isMonitorOn:
                  if isPlaying:
                    subprocess.call("./wakeUp.sh")
                    isMonitorOn = True
                if isMonitorOn:
                  if isPlaying:
                    counter = 0
                  if counter >= sleepyTimer:
                    subprocess.call("./sleep.sh")
                    isMonitorOn = False
                    counter = 0
                time.sleep(1)
             elif i==1:
                counter = 0
                if isMonitorOn:
                  time.sleep(1)
                else:
                  subprocess.call("./wakeUp.sh")
                  time.sleep(1)
      
      

      wakeUp.sh includes:

      #!/bin/bash
      /opt/vc/bin/tvservice --preferred && sudo chvt 6 && sudo chvt 7
      
      

      sleep.sh includes:

      #!/bin/bash
      /opt/vc/bin/tvservice -o
      

      isMonitorOn.sh includes

      #!/bin/bash
      isMonitorOn=$(/opt/vc/bin/tvservice --status | grep off | wc -l)
      if [ "$isMonitorOn" = "0" ]; then
        echo True
      fi
      

      isAudioOn.sh includes

      #!/bin/bash
      if grep -q RUNNING /proc/asound/card*/pcm*/sub*/status; then echo "True"; fi
      

      Python and Bash scripts need to be in the same folder!

      for now i’m running this via screen

      screen -dmS smartMotion python smartMotion.py
      

      connect to screen session

      screen -r smartMotion
      

      detatch from session

      CTRL + A + D
      
      1 Reply Last reply Reply Quote 2
      • A Offline
        andr1
        last edited by

        remember to do chmod +x shellscriptname.sh

        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