Preventing trigger repeat

The downfall of this rule is that when someone re-opens the front door within the 14 second “red snitch light” is that the red light is selected as the capture and restore. So it stays red forever if that happens.

How do I lock out the contact sensor during that 15 seconds so it doesn’t retrigger the rule?

Use a PB - set it to false as the first action, and back to true as the last action. Require the PB to be true for the trigger to work.

1 Like

Set the Boolean as the first action. And reset it after. Then make a required expression that the Boolean for the rule needs to be false to trigger.

1 Like

Ya beat me!

Thanks, but…in English. What’s a PB and What’s a Boolean?

I may appear more advanced than I actually am. lol.

Would making a required expression stating that it must be true that all the contact sensors are closed, work the same without the private boolean? Then if one of the sensors are open the required expression would be false and the rule should never trigger again until the sensors are all closed again and the required expression becomes true again? Or am I thinking of this wrong?

Look up "Private Boolean" in the documentation.

Maybe, maybe not. Depends on the intention. We don't know exactly what the OP is actually trying to achieve. Should the required expression cancel pending actions when turning false? Should there be a 15-second delay (not cancellable in this rule) or a Wait for Event(contacts closed + timeout, elapsed time, etc.) ?

1 Like

Sorry I didn't notice the delay. My bad. If the intention is to stop the triggering completely if one of the sensors are open then the required expression should work, correct? This is for my knowledge as well.

Yes. Using a PB is more universal in its approach. The danger with your approach is what happens if a sensor battery dies when it’s in the open position?

1 Like

That makes sense and I see what you are saying. However, even with the PB if the battery dies in the sensor open position then the PB won't reset when it is closed so the rule still won't reset allowing it to trigger next time. Either way when you notice it isn't working you gotta track it down. That is if the rule is written to reset on close and not automatically do so after some set delay.

I actually use both methods along with conditional triggers depending on the application.

That is one reason I like Hubitat is there is so many different ways to get the same results.

I don't know what you're referring to.

In @JayInPtown's rule (posted above - and this is the thread they started), the contact sensor doesn't need to close. The PB would be reset at the end of the rule. So even if the battery in one triggering sensor dies, the other sensor could still trigger the rule.

In your suggested setup, where all sensors have to be closed in a required expression, a single battery fault disables the rule.

I know how the original rule is written by the original post. If you will see above I stated that it is if the rule is written to reset when all sensors are closed and not reset on a delay like their rule.

Also, I personally would like to know as soon as one battery dies and I have to track it down instead of it dying and finding out when that sensor doesn't work. Just my way of working things but in no way does it make your approach wrong.

That's good, because the suggestions here (at least mine) were for the @JayInPtown's rule.

:+1:

Another option might be to set the trigger as a conditional trigger.

Only trigger if bulb color not red?

2 Likes

My apologies I was simply trying to point out to them there was other ways of doing it and thinking about it.

You got it covered i will step aside and let you handle it.

I tried to learn about the Private Boolean.

I think it would be a ‘condition’ but when I select that it defaults to true. I’m lost.

Could you write a sample rule with a contact sensor, capture-restore bulb command, 15secomd reset.

You’ll see I added a a delay in my rule to give the capture command time to work (based on a post here)

In the Actions you have make the first action to set the PB to TRUE. At the end of the everything put another to set it to FALSE. When you have the actions pulled up to edit at the bottom you'll see:

Screenshot 2025-02-08 at 6.20.23 AM

Click on 'true' and it will toggle to 'false' for the initial setting.

Then be sure to set a Required Expression where that is that the PB for this rule is FALSE.

So what all does that then do? With the Required Expression defined the PB must be FALSE or the rule will not run at all. So assuming it's false it will then trigger when the contacts you specified open and immediately set the PB to TRUE so for the next several seconds while everything runs it will not be able to restart. At the end when you set it back to FALSE that will set so it can fire again next time.

Hope that helps.

1 Like

In your rule build, it doesn't matter at all whether the PB starts at True or False. Since the system defaults them to True when you're building them, that's what I (and most folks, I suspect) roll with.

Here's a short rule I have using PB... For this scenario of preventing re-triggers, the PB needs to be a Req'd Expression. Per above, I always start with PB = True

Then the first Action your rule should set PB the other way (False in my case). Then build your desired rule actions, and as the very last Action, reset your PB back to original state (True for me). That way, it's ready to rock for the next trigger event.

In my example here, my very first Action line about exiting the rule if PB=False isn't necessary in most cases -- that's just an add'l safeguard I added in an abundance of caution.

ETA -- Don't get wrapped up about what True/False means -- they're simply state identifiers. They could just as well be Red/Blue, Lions/Tigers, Michelin/Firestone, etc.

4 Likes

Here you go:

I've also exported the rule and attached it below. You can import it and change the devices to the ones that you use.

Rule to import
{"deviceReplacements":{"300":{"deviceName":"Virtual Contact Sensor","deviceLabel":"Contact: Front Door","deviceTypeName":"Virtual Contact Sensor","deviceTypeNamespace":"hubitat"},"297":{"deviceName":"Virtual Contact Sensor","deviceLabel":"Contact: Back Door","deviceTypeName":"Virtual Contact Sensor","deviceTypeNamespace":"hubitat"},"14":{"deviceName":"Livingroom Light","deviceLabel":"Livingroom Light","deviceTypeName":"Group Bulb Dimmer-2.1","deviceTypeNamespace":"hubitat"}},"appReplacements":{"282":{"appTypeName":"Rule-5.1","appTypeNamespace":"hubitat","appType":"sys","appName":"Rule-5.1","appLabel":"PB example","parentAppInstalledAppId":"35","parentAppTypeName":"Rule Machine","parentAppTypeNamespace":"hubitat","parentAppName":"Rule Machine","parentAppLabel":"Rule Machine","childApps":{},"singleInstance":false}},"appData":{"282":{"state":{"parens":{"0":0},"actionDone":true,"p.PB":"true","ndx":4,"dateFormat":"yyyy-MM-dd","installedRules":[{"201":"Announcements: Dryer done"},{"123":"Announcements: Empty Litter Box"},{"119":"Announcements: Mail"},{"120":"Announcements: Washer done"},{"36":"Geofence: Arrive Home"},{"38":"Geofence: Leave Home"},{"127":"Hubitat: Periodic Platform Check"},{"126":"Hubitat: Periodic Zigbee Radio Check"},{"138":"LGTV: On - JoinTV"},{"116":"Lighting: 2AM landscape lighting off"},{"146":"Lighting: Christmas Evening Lights"},{"111":"Lighting: Driveway Motion"},{"50":"Lighting: Evening lights"},{"112":"Lighting: Front Porch Motion"},{"183":"Lighting: HVAC Closet"},{"130":"Lighting: Laundry"},{"186":"Lighting: Main Bathroom"},{"46":"Lighting: Morning Lights Off"},{"85":"Lighting: Outdoor Closet"},{"99":"Lighting: Shed"},{"215":"Lighting: Shed kludge"},{"192":"Lighting: Upstairs Hallway"},{"135":"Manual Control: Driveway"},{"136":"Manual Control: Laundry"},{"190":"Manual Control: Main Bathroom"},{"134":"Manual Control: Shed"},{"194":"Manual Control: Upstairs Hallway"},{"230":"Mode Away/Sleep: Lock doors"},{"185":"Mode Away/Sleep: Lock doors (old)"},{"219":"Notifications: Lock - Back Door"},{"221":"Notifications: Lock - Front Door"},{"223":"Notifications: Lock - Kitchen Patio"},{"227":"Notifications: Lock - Outdoor Closet"},{"256":"Pond: Heater"},{"48":"Reset Private Booleans"},{"209":"Reset Private Booleans 2"},{"213":"Rule-Test: Temperature + PB"},{"44":"Sleep: Goodnight"},{"40":"Sleep: Wake Up"},{"55":"SleepNumber Ashok: Set Firmness to 100 in the AM"},{"75":"SleepNumber Ashok: Unoccupied"},{"79":"SleepNumber Bed Left: Set Firmness to 100 in the AM"},{"77":"SleepNumber Bed Left: Unoccupied"},{"131":"SleepNumber Guest Bed: deflate/inflate"},{"47":"Timed Switch: Bug Zappers sunset to sunrise"},{"90":"Timed Switch: Holiday off at 9:00"},{"43":"Timed Switch: Paper Shredder 5 minutes max"},{"41":"Timed Switch: Water Heater 30 minutes max"},{"212":"Water Main: Heat Tape"}],"clonedName":"PB example","selectActionsParams":{"label":"PB example"},"editCondIf":null,"stopOnST":false,"usesTime":false,"trigCustoms":[],"inUseTrigConds":[],"setDisabledActs":true,"capabDone":true,"predCapabs":[2],"locationBlocked":[],"pbFixed":true,"ruleNdx":1,"notEqual":true,"firstR":{"0":false},"actionList":["1","2","3","4","5","6","7"],"capture":"capture.2","timeHandlersUpdated":true,"actLabelIndent":"","unUsed":[],"prevStateUpdated":true,"varSettingsUpdated":true,"certainTimes":[],"disabledActions":[],"hasWhileRule":false,"paramsDone":true,"eval":{"0":[2]},"capabstrue":{"1":"Contact: Front Door, Contact: Back Door any contact reports open"},"lastEvtDate":"2025-02-08","unusedConds":["2"],"nestedInIf":[],"actions":{"1":{"quick":true,"method":"getSetPrivateBoolean","indent":""},"2":{"quick":true,"method":"getCapture","indent":""},"3":{"quick":false,"delay":"0:00:01","method":"getDelay","indent":""},"4":{"quick":true,"method":"getSetColor","indent":""},"5":{"quick":false,"delay":"0:00:15","method":"getDelay","indent":""},"6":{"quick":true,"method":"getRestore","indent":""},"7":{"quick":true,"method":"getSetPrivateBoolean","indent":""}},"usesDate":false,"actNdx":8,"lastEvtValue":0,"installed":true,"waitEvents":[],"private":"true","predPB":true,"running":false,"copyL":[],"simpleCond":false,"changedValues":true,"nestedRepIf":[],"lastEvtTime":"08:35","condOper":"cond","hasPredicate":true,"nestedElse":[],"varTriggersFixed":true,"setCopyActs":true,"cutAction":[],"broken":false,"fixedMarkIfs":true,"stopped":false,"rulesList":[],"hasPrev":[],"nestedLabel":[],"oldInputAct":true,"inputAct":true,"stateVarsUpdated":true,"token":1,"waitCondNdx":1,"capabsfalse":{"2":"Private Boolean<span style='color:black'>(true)</span> is true"},"stPrimed":true,"allLocalVars":{},"varSettingsOld":{},"timeFormat":"HH:mm","doActN":"N","olddValues":true,"inUseConds":["2"]},"appSettings":[{"deviceList":null,"multiple":false,"name":"tCapab1","type":"enum","value":"Contact"},{"deviceList":null,"multiple":false,"name":"not2","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"useST","type":"bool","value":"true"},{"deviceList":{"300":"Contact: Front Door","297":"Contact: Back Door"},"multiple":true,"name":"tDev1","type":"capability.contactSensor","value":null},{"deviceList":null,"multiple":false,"name":"tstate1","type":"enum","value":"open"},{"deviceList":null,"multiple":false,"name":"isCondTrig.1","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"dValues","type":"bool","value":"true"},{"deviceList":null,"multiple":false,"name":"pointless","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"comments","type":"textarea","value":""},{"deviceList":null,"multiple":false,"name":"hasAll","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"isFunction","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"cancelCapab","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"editToken","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"lvTable","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"state_2","type":"enum","value":"true"},{"deviceList":null,"multiple":false,"name":"1","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"rCapab_2","type":"enum","value":"Private Boolean"},{"deviceList":null,"multiple":false,"name":"origLabel","type":"text","value":"PB example"},{"deviceList":null,"multiple":false,"name":"AlltDev1","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"eraseRule","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"true","type":"button","value":""},{"deviceList":null,"multiple":true,"name":"logging","type":"enum","value":null},{"deviceList":null,"multiple":false,"name":"stays1","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"updateRule","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"hasRule","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"stopOnST","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"cancelST","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"editST","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"doneST","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"evalOnBoot","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"copyL","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"trashAll","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"disableL","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"moreVar","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"cutX","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"editPV","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"N","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"cancelBtn","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"actType.1","type":"enum","value":"rulesActs"},{"deviceList":null,"multiple":false,"name":"actSubType.1","type":"enum","value":"getSetPrivateBoolean"},{"deviceList":null,"multiple":false,"name":"actionCancel","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"pvRuleType.1","type":"enum","value":"Rule Machine"},{"deviceList":null,"multiple":true,"name":"privateT.1","type":"enum","value":"[\\"*\\"]"},{"deviceList":null,"multiple":false,"name":"pvTF.1","type":"bool","value":"true"},{"deviceList":null,"multiple":false,"name":"actionDone","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"delayAct.1","type":"enum","value":"none"},{"deviceList":null,"multiple":false,"name":"cut1","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"chkBox1","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"I1","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"1.0.false","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"disable1","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"actType.2","type":"enum","value":"deviceActs"},{"deviceList":null,"multiple":false,"name":"actSubType.2","type":"enum","value":"getCapture"},{"deviceList":{"14":"Livingroom Light"},"multiple":true,"name":"capture.2","type":"capability.switch","value":null},{"deviceList":null,"multiple":false,"name":"delayAct.2","type":"enum","value":"none"},{"deviceList":null,"multiple":false,"name":"2.0.false","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"chkBox2","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"I2","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"disable2","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"2","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"cut2","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"actType.3","type":"enum","value":"delayActs"},{"deviceList":null,"multiple":false,"name":"actSubType.3","type":"enum","value":"getDelay"},{"deviceList":null,"multiple":false,"name":"uVar.3","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"cancelAct.3","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"randomAct.3","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"delayMinute.3","type":"number","value":""},{"deviceList":null,"multiple":false,"name":"delaySecond.3","type":"decimal","value":"1"},{"deviceList":null,"multiple":false,"name":"delayHour.3","type":"number","value":""},{"deviceList":null,"multiple":false,"name":"chkBox3","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"I3","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"cut3","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"3.0.false","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"disable3","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"3","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"actType.4","type":"enum","value":"dimmerActs"},{"deviceList":null,"multiple":false,"name":"actSubType.4","type":"enum","value":"getSetColor"},{"deviceList":null,"multiple":false,"name":"color.4","type":"enum","value":"Red"},{"deviceList":null,"multiple":false,"name":"uVar.4","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"colorLevel.4","type":"number","value":"96"},{"deviceList":null,"multiple":false,"name":"delayAct.4","type":"enum","value":"none"},{"deviceList":{"14":"Livingroom Light"},"multiple":true,"name":"bulbs.4","type":"capability.colorControl","value":null},{"deviceList":null,"multiple":false,"name":"chkBox4","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"I4","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"cut4","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"disable4","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"4","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"4.0.false","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"actType.5","type":"enum","value":"delayActs"},{"deviceList":null,"multiple":false,"name":"actSubType.5","type":"enum","value":"getDelay"},{"deviceList":null,"multiple":false,"name":"uVar.5","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"randomAct.5","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"cancelAct.5","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"delaySecond.5","type":"decimal","value":"15"},{"deviceList":null,"multiple":false,"name":"delayHour.5","type":"number","value":""},{"deviceList":null,"multiple":false,"name":"delayMinute.5","type":"number","value":""},{"deviceList":null,"multiple":false,"name":"I5","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"chkBox5","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"cut5","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"disable5","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"5","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"5.0.false","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"actType.6","type":"enum","value":"deviceActs"},{"deviceList":null,"multiple":false,"name":"actSubType.6","type":"enum","value":"getRestore"},{"deviceList":null,"multiple":false,"name":"delayAct.6","type":"enum","value":"none"},{"deviceList":null,"multiple":false,"name":"I6","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"chkBox6","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"cut6","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"disable6","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"6","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"6.0.false","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"actType.7","type":"enum","value":"rulesActs"},{"deviceList":null,"multiple":false,"name":"actSubType.7","type":"enum","value":"getSetPrivateBoolean"},{"deviceList":null,"multiple":false,"name":"pvTF.7","type":"bool","value":""},{"deviceList":null,"multiple":true,"name":"privateT.7","type":"enum","value":"[\\"*\\"]"},{"deviceList":null,"multiple":false,"name":"pvRuleType.7","type":"enum","value":"Rule Machine"},{"deviceList":null,"multiple":false,"name":"delayAct.7","type":"enum","value":"none"},{"deviceList":null,"multiple":false,"name":"I7","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"chkBox7","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"cut7","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"7.0.false","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"7","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"disable7","type":"button","value":""}],"subscriptions":[{"handler":"allHandlerX","name":"contact.open","type":"DEVICE","typeId":300,"typeName":"Contact: Front Door","filter":"true"},{"handler":"allHandlerX","name":"contact.open","type":"DEVICE","typeId":297,"typeName":"Contact: Back Door","filter":"true"}]}}}
3 Likes

Instead of Required Expression, just use Conditional Trigger. Simpler, and more reliable.

3 Likes