MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. andr1
    3. Best
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    A
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 5
    • Groups 0

    Posts

    Recent Best Controversial
    • PIR sensor / wakes screen up when audio is detected

      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
      
      posted in System
      A
      andr1
    • RE: Where are you from?

      Westman Islands, Iceland (Living in Reykjavik, Iceland)

      posted in General Discussion
      A
      andr1
    • 1 / 1