"Debouncing" an App

With automations, funky Z-Wave issues, People (kids?) pressing buttons--there are a number of uncontrollable situations that could trigger an app multiple times in a row.

Are there any good solutions?

In some cases, it would be helpful to simply ignore anything that re-triggers the app withing mm:ss amount of time.

In other case, it might be helpful to "queue up" the requests so they wouldn't run for mm:ss amount of time.

Bonus points for being able to include this app and related ones in those times. :slight_smile:

This may be good "feature request" for something in the future--but I was also wondering how people deal with this now?

It came up for me-because my door locks can generate multiple (often 2) trigger events at once, which created some unexpected behavior (thankfully, nothing crazy--when my rule ran again, it recognized it had little to do, but I'd like to avoid the "two threads of an app at once" scenario as several of my rules can take a few minutes to run.

I suspect I can think of some ways to do this with global variables, etc. I shy from the Private Boolean, only because it could be all to easy for "bad timing" to leave that in a bad state far past the time window I'd want.

Perhaps, a global time variable for each app group, with a time. Then, first thing, the app(s) could compare the current time to that--and either exit or wait if it was too soon (would the Rule Manager allow a second instance to start and exit/wait like that?). This would only work for a second instance tho--as instance 2, 3, 4, etc. would all fire at the same "expiration time" if I wanted them to queue up--not sure the RM is able to easily manage a "stack" (ugly, but one could code a fixed number of times--but it would be a hard coded limit).

Thoughts?

Did you actually see any issues yet requiring a debounce? In my 2 yrs or so of using Hubitat I've rarely actually found a situation like this in practice that I couldn't resolve with a PB or a simple bit of logic/conditional at the top of the rule. Really rules rarely take minutes to run through their sequence. They run quickly and set up queued events that then sit and wait to be executed, or the rule might sit and wait for a condition or event in order to then proceed to set up the remaining events. Having said that, you will find a few topics on debouncing in the forum.

Yeah, my locks seem to generate a couple events for every action (you have to process the first one in case it's one of the older ones--but the newer ones send an incorrect first one and the second one really matters. Except in some cases, where it really is the first one. Yeah, a mess like that.

Some of my events trigger large-scale changes ("leave and turn everything off"/"arrive home and turn everything on"). Those need to be broken up, they make some announcements, and I find I currently need to put "refresh()" calls in and re-perform events to ensure the actions actually happen (hopefully, I can get past this--but it is a crutch for now that helps). Thus, they can run 1-3 minutes, some a bit more maybe.

Thanks for those links!! :slight_smile:

The long one where they were working on debouncing contact sensors on the platform had a lot of good info.

I have to think that there's some REALLY cheap (lack of) engineering on a lot of this cheap Chinese crap that is being sold. I have to wonder if they truly aren't performing any hardware-based debouncing on the reed relay in those contact sensor that were generating numerous events only a few ms apart.

Still, very good info about how the apps, drivers, groovy, and the Rule Manager all work.

2 Likes

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