So this was posted in the Tasmota (Sonoff) Google group but though I would share here as well…
This is a rule set I did for the bathroom fan. Kids had a tendency to keep the fan running so I programmed it to have different auto shutoff depending if you press the button once, twice or hold it.
rule1 on button1#state=2 do backlog power1 toggle; ruletimer1 600 endon on button1#state=3 do backlog power1 1; ruletimer1 0 endon on power2#state=1 do backlog power1 1; power2 0; ruletimer1 3600 endon
rule2 on Rules#Timer=1 do power1 off endon
backlog rule1 1;rule2 1; rule3 0; setoption1 1; setoption13 0; setoption32 60
A single press tuns the fan on for 10 minutes, a double press for an hour and a hold turns it on indefinitely. Since my switch only has one button, I configured Relay2 on an unused pin (GPIO14) to give it that double press ‘extra button’. Since on a one button switch, Power2 is toggled by a double press of the button. Hold time is set to a minute so it’s not hit ‘accidentally’ by the kids and allows me to keep it on for any reason.
Since it’s not Home Assistant related (since everything is done at the switch level, I posted it here. Hope that’s ok.