This Rule Machine child app causes the bathroom fan switch (Leviton ZW15S) to turn off after N (20) minutes. If I want a longer time the wall switch is turned off for less than 2 seconds then back on to reset the wait to N+ (10) more minutes. There is a max delay of one step past 50 minutes. Should the wall switch remain off for longer than the 2 seconds or the set time expires, the delay is reset back to 0.
I had a challenge with debouncing the wall switch until I tried configuring a physical switch trigger selecting on and stays that way for 0.
For the off trigger just use the switch device so it sets the delay variable to zero when physically turning the switch off and for when it gets turned off electronically.