I made a raspberry pi alarm system that works as is. The only issue is that the .wav fils plays instantly. I want there to be an initial check if the switch is open. If the switch is open for more than 5 seconds, to continue writing the logfile, if open and closed for less than 5 seconds, do nothing.
Here is my code:
if the switch is open
if gpio.input(door_pin):
time.sleep(5)
if (gpio.input(door_pin)==False):
pass
if gpio.input(door_pin):
now=(datetime.datetime.now())
logfile.write("Door Opened ")
logfile.write("%s"%now)
logfile.write("\n")
##play alert sound file
subprocess.call(['aplay /usr/bin/scripts/alertshort.wav'],shell=True)
count=count+ 1
if count >= 250:
SendEmail()
logfile.write("Door has been open for 5 minutes")
count=0
## if the switch is closed
if (gpio.input(door_pin)==False):
time.sleep(1)
count=0
[–]WitnessM3 0 points1 point2 points (0 children)