Read the statement by Michael Teeuw here.
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 7sleep.sh includes:
#!/bin/bash /opt/vc/bin/tvservice -oisMonitorOn.sh includes
#!/bin/bash isMonitorOn=$(/opt/vc/bin/tvservice --status | grep off | wc -l) if [ "$isMonitorOn" = "0" ]; then echo True fiisAudioOn.sh includes
#!/bin/bash if grep -q RUNNING /proc/asound/card*/pcm*/sub*/status; then echo "True"; fiPython and Bash scripts need to be in the same folder!
for now i’m running this via screen
screen -dmS smartMotion python smartMotion.pyconnect to screen session
screen -r smartMotiondetatch from session
CTRL + A + D -
remember to do chmod +x shellscriptname.sh
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