Voici un fichier python qui fait exactement ce que tu souhaites
#!/usr/bin/env python
import sys
import time
import RPi.GPIO as io
import subprocess
import os
io.setmode(io.BCM)
SHUTOFF_DELAY = 120 # in seconds, how long the monitor will be on until next PIR detection
PIR_PIN = 4
def main():
io.setup(PIR_PIN, io.IN)
turned_off = False
subprocess.call("sh /home/pi/monitor_off.sh", shell=True)
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
subprocess.call("sh /home/pi/monitor_on.sh", shell=True)
else:
if not turned_off and time.time() > (last_motion_time + SHUTOFF_DELAY):
turned_off = True
subprocess.call("sh /home/pi/monitor_off.sh", shell=True)
time.sleep(.1)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
io.cleanup()
et dans monitor_off.sh
vcgencmd display_power 0
et dans monitor_on.sh
vcgencmd display_power 1