I’ve had some of the exact same issues. My wife woke up early on Saturday morning to the garage door going up and down. Funny how toggling - in a loop - means it will continue to loop and continue to toggle.
I’m pretty much a newbie too, so much of this is a guess (although our garage door going up and down all night was not a guess!). But, could the brackets in your first code example be causing part of the problem? From this page the setup and loop functions each need to be contained in open/close brackets:
// actions are performed in the functions "setup" and "loop"
// but no information is reported to the larger program
The brackets in your code don’t seem to be enclosing the functions. I don’t have the vaguest notion if that’s causing the issue, but I thought it might be worth a look.
In my garage door expedition Part B, I am using Tinker with the Photon Relay Board. I just push the respective Digital Write Button to go HIGH and then push it again to go low: the poor man’s version of a momentary. Someday, when I understand more, I’d like to improve that situation.
I wish you all the best.