RASPBERRY PI 4
Hello there, I have this script that should shut off a power outlet when it detects a movement.
The rpi-rf_send
code is from this repo.
The question is: if the current goes away, how do I restart the script?
I tried to insert the script in rc.local
(probably in the wrong way) but it doesn't work.
import time
from gpiozero import MotionSensor
import subprocess
pir = MotionSensor(pin=14,pull_up=False)
def restart_plug():
print("Starting plug...")
subprocess.run(["rpi-rf_send","8652300","-g", "3", "-p", "172"])
def stop_plug():
print("Stop plug...")
subprocess.run(["rpi-rf_send","8652292","-g", "3", "-p", "172"])
time.sleep(5)
restart_plug()
while True:
pir.wait_for_motion()
print("Waiting for motion...")
if pir.is_active:
print("Motion detected!")
stop_plug()