-1

I've followed a youtube tutorial on configuring a rPi with a magnetic reed switch and relay switch to allow for my garage door to be opened and closed via Homekit on my iPhone. It works great.

The only thing now that I'd like to figure out is how to start a countdown timer each time the door is open, and if the timer reaches zero, close the garage door. And if the garage door happens to be closed before the timer reaches zero, the timer should be terminated.

What's the best approach for something like this?

I'm pretty sure that the tutorial scripts included the install of rpi.gpio. I can run "gpio readall" from a terminal prompt, and I can see that pin 12 is "1" when the door is closed, and "0" when the door is open.

3
  • 2
    This is a standard programming task for which the Raspberry Pi is pretty irrelevant.
    – joan
    Feb 7, 2017 at 20:51
  • 1
    What if something is in the way of the door?
    – Jacobm001
    Feb 8, 2017 at 1:11
  • There's still the usual eye beam safety feature, and the door will reverse direction if it comes into contact with something before it reaches the ground. I think I've figured out how to accomplish the original problem... I'm going to modify the existing script that already runs, because it's already checking the open/close state of the door every second. All I need to do is store the time whenever the door opens, and then each time the script checks the state, if the door is still open and the elapsed time is >10 minutes (or whatever time), I can call the function that closes the door. Feb 9, 2017 at 1:41

1 Answer 1

1

If the program checks every second, just create a variable and add 1 to it every time it checks.

Then, add an if statement that checks if the time is over your threshold. (In the same place you check the status of the door)

Remember to update the time variable each time the status of the door is changed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.