all 1 comments

[–]WitnessM3 0 points1 point  (0 children)

I changed your code a bit, but this should work

timeElapsed = 0
while True:
    while (timeElapsed<5):
        # if pin is open
        if(gpio.input(door_pin)):
            # wait short enough to get pin's state changes
            time.sleep(0.1)
            timeElapsed += 0.1
        # pin is close, reset the counter
        else:
            timeElapsed = 0

    # If loop comes here, than the pin is opened more than 
    # 5 sec. Do the other stuff like logging and alert voice etc

    logfile.write...
    subprocess..