Self Cancelling Switch On/Off Rule

I want to setup a simple rule to turn off my bathroom exhaust fan 45 minutes after it was turned on, using a smart 3-gang Nue switch I had installed recently. I've included a screenshot of my rule below, showing how I have setup the action to turn off the switch, which is cancellable. My intention is to cancel the action if the switch is turned off before the 45 minutes is up. I could setup another rule to detect the switch being turned off, but I would prefer to keep it self-contained in the one rule. Is that possible?

Thanks,
Simon

Thinking about it now, is to detect a changed state on the switch and conditional logic to react differently depending on being switched on or off?

Make it wait for the condition of the switch turning off with a 45 minute timeout and then turn the fan off.
If the switch turns in the 45 minutes its already off but otherwise it will turn off after 45 minutes.

1 Like

Thanks for the suggestion @at9. I think I may still go with a conditional logic approach, but am interested to understand the behaviour of what you have suggested.

Are you still suggesting to have the rule triggered by the switch turning on? If so, if during the 45 minute timeout window, if I turned the switch off and back on again, would the original 45 minute timeout still come into play? i.e. if I did this after 40 minutes, would the switch turn off 5 minutes later?

This is what I changed the rule to while you were responding to my post:

Sorry, re-reading your post I see you suggested waiting for the switch to turn off, I'm assuming that would in effect cancel the 45 minute timeout, ignore my previous question.

Thanks again @at9

1 Like

Based on the suggestions from Bruce in the latest Hublitat live it would be better to do something like this.

Trigger: Switch On

Actions:
Cancel delayed actions.
Off Switch -> Delay 45min (Cancelable)
Wait for event Switch off - Timeout 45 min 5 seconds
Cancel delayed actions.

2 Likes

Thanks @Hasty1. It's funny, I watched Bruce's KISS segment and didn't even twig that I could have used it for my fan. That said, I still lean towards the IF-THEN-ELSE structure, I just feel it reads better for some reason. I completely understand yours / Bruce's solution, but just feel mine is a bit more explicit somehow....

I just moved a bunch of IF-IFELSE-ELSE to the new method Bruce mentioned. I am still working on optimization of a lot of rules.

2 Likes

Just a comment re KISS

In your example I donā€™t think you need the last two lines in your rule at all.

Edit. Ah I guess it means that the delay timer doesnā€™t keep running if the switch is turned off before the timeout.

Yup!

possible revision:

Trigger: Switch On

Actions:
Cancel Wait
Wait for event: Switch turns off - Timeout: 45 min
Off: Switch

5 Likes

NIce! I Like it! Want to review all my rules!? :rofl:

1 Like

yeah, i have been reviewing a lot of mine as well.

You don't need the cancel wait because you can't retrigger the rule without canceling the wait not that it actually makes any difference.

2 Likes

I agree because I tried it.
I thought it would act like a button event and retriever the rule if on was pressed again.
Nope - doesnā€™t happen. You have to cycle off before the rule will trigger from another on event.

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.