Prevent multiple triggering of app

I have a sensor that alerts me when triggered. However, a person could accidentally trigger it several times in a few seconds. I want to prevent them from triggering again within one minute. Other threads on this topic have not been helpful. So... whenever an app is started, it first evidently cancels any other instances of itself. Here's an example of running an app, then starting it again after 5 seconds:

2024-01-03 11 41 33
2024-01-03 11 41 10

The second execution canceled the first then started its 10 second countdown. So I tried the Required Expression with Private Boolean approach again running twice within 5 seconds:

2024-01-03 15 54 35
2024-01-03 16 14 30

Both yield identical results!!!
I guess I just don't understand what's supposed to happen here. Can anyone explain what I'm doing wrong (and if there's a better way to do it)?

That should more or less work, but that can't be your actual rule since there are no triggers and it would never run. There is a chance it could still retrigger if the sensor (should you have a similar rule triggered by one) sends a matching event milliseconds after another and the state of the PB hadn't finished being written yet. A boolean hub variable might be faster. A better approach would be to limit milliseconds-apart readings from the sensor--are they really meaningful events?

Along those lines, what is the actual rule?

I assume you are just using the run rule. If so that will not work, you need a trigger. If you click run, twice it will run it twice.

Use a virtual Motion sensor and activate twice in 5 seconds you should only see one run.

There's no trigger defined here. As a test, I've just been running it from the Rules editor.

I just tried it with a trigger button, here's the results showing the 2nd press doing nothing. It looks like @terminal3 is correct, it behaves differently when run from a trigger (go figure). THANKS!
2024-01-03 16 40 10

BTW: How do I limit milliseconds-apart readings from the sensor?

They act differently, because they are different. A trigger waits for an event. When you click run rule you are telling it to run the actions. A required expression prevents a trigger from occurring. if not true. You can still run the rule actions. however. Either by running them from within the RM editor, as you did here, or you can have another rule run them. That is not prevented by a required expression.

2 Likes

Search the forums for 'debounce contact sensor'. There's a custom app you can add that handles rapid retriggering by setting a virtual contact closed some time (I think 1 second is the default) after the real contact closes.

I use it to debounce a rule that would otherwise often get hit with 4 triggers almost simultaneously.

Edit: found it - HubitatPublic/example-apps/debounceContact.groovy at master · hubitat/HubitatPublic · GitHub