De-Bouncer in Rules? Stop repeat notifications?

I have a reed switch on my front gate that notifies me when the gate is opened. The problem is that it whenever it is opened there is actually a very quick OPEN…CLOSED…OPEN state change of the sensor which means I get multiple notifications.

Is there any way in my notification rule to do the first notification and then ignore any state changes for the next 1 second or something like that? I’m thinking I need a timer or something?

Check out the Expire binding. You can “debounce” your input by adding it to the item definition, i.e.:

Switch FrontGate "Front Gate" {expire="1s,OFF"}

Any multiple state changes (from OFF to ON) within that 1 second will just extend the expire time, but the state of the item will only change once.

Note that you won’t be able to tell the state of the actual gate using this item (since the expire will set its state to “OFF” regardless of the actual switch state. You may want to have another item, bound to the same reed switch, that you use for the actual gate state.

Look at Generic Presence Detection, for a concrete example for using Expire to do this.

I also wrote a DP for this but it’s old and have been updated in forever. I can’t say if it shows the best approach any more. Design Pattern: Event Limit

There must be a better way than using the expire binding?
I’m already using that to figure out when devices haven’t been updated in a while and could be malfunctioning…

Garbage in => garbage out :wink: - The proper way to fix this is to debounce the switch on the hardware side, e.g. using a monostable multivibrator or a Schmitt trigger.

Yeah totally agree :slight_smile:
It’s an esp8266 running ESPEasy so been trying to also figure out how I can do it in there.

How about the “Interval” setting on Switch input? I think that acts the same way as the expire binding (keeping the input active for a set period regardless of toggling), but it might actually keep the steady state, as well…

Thanks @sihui I have just updated the firmware in the sensor and noticed that new setting. I am testing it out now :slight_smile:

If you are trying to debounce in OH rules then no, there is no better way. You must set a timer of some sort and you must ignore changes that occur while the timer is active. It doesn’t have to be Expire binding, though Expire Binding will be the easiest.

But as bartus says, it is best to solve problems like this as close to the device as possible.