Debouncing

Hi all,

I am trying to debounce a sensor in nodered with limited success.

My project uses a reed switch (magnetic sensor) to establish when my robot lawnmower is in the docking station.
This is done over mqtt and captured in HA as a binary sensor and works great. I have “on” for when the lawnmower is active on the lawn and “off” for when it is docked.

Now unfortunately there is a slight wobble on the body of the mower when it docks causing it to announce “on” “off” “on” “off” “on” “off” when it arrives (and sometimes when it leaves).

I stopped the message notifying numerous times to my phone with a delay node that waits until the messages are a rate of 1 per 4 seconds and then drops the intermediate messages.

But now i need to prevent the “on” being announced at all when it comes back to the dock.
Is there a way to perhaps wait until it is in one state for a set amount of time before announcing? 3 seconds or so would do it.

any help gratefully received!

Yes

Adjust the interval accordingly.

hmm not sure that’s quite doing it. I need it to only announce if the state has been “on” or “off” for 5 seconds. not really looking to add a delay per se

This way when the lawnmower comes back and mechanically bounces onto the dock (announcing off,on,off.on,off) then it doesn’t send ANY of the “on”'s and only sends “off” after it has sat there in the dock for 5 seconds.

Yeh, I misunderstood. I’ve not done exactly what you’re trying but it’s likely you could achieve it with constraints on a trigger state node.

Throttle (by block size) may work. it lets the first “off” message pass and blocks further messages until receives a reset message. reset message can be send if the lawnmower has been on for let’s say 10 minutes continuously without changing to off.

[{"id":"5cfa5fc3.c965","type":"inject","z":"294e4f5f.46b07","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1760,"wires":[["3bb6638.22e359c"]]},{"id":"6a97a19a.c99ba","type":"debug","z":"294e4f5f.46b07","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":650,"y":1780,"wires":[]},{"id":"ee2ffaff.b6a628","type":"inject","z":"294e4f5f.46b07","name":"","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1800,"wires":[["3bb6638.22e359c"]]},{"id":"3bb6638.22e359c","type":"throttle","z":"294e4f5f.46b07","name":"","throttleType":"block","timeLimit":"10","timeLimitType":"seconds","countLimit":"1","blockSize":"1","locked":false,"x":490,"y":1780,"wires":[["6a97a19a.c99ba"]]},{"id":"3024e4e1.21dddc","type":"inject","z":"294e4f5f.46b07","name":"","topic":"","payload":"{}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":1860,"wires":[["42caea01.c737f4"]]},{"id":"42caea01.c737f4","type":"change","z":"294e4f5f.46b07","name":"built message","rules":[{"t":"set","p":"reset","pt":"msg","to":"True","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":1860,"wires":[["3bb6638.22e359c"]]}]

Use a wait-until node with the conditional set to state doesn’t equal on then a timeout set to 3 seconds and have the announce node connected to the timeout output

Thanks for the ideas all. I may have resolved this…

I think this way the on/off on the sensor as it docks or undocks will trigger the flow, it will wait 3 seconds for the bounce to calm down and then get the current state. if its “on” it will send the relevant notifications (“the lawnmower is heading out”) and if its “off” it will send a different one (“the lawnmower is docked and charging”).

will know in 30-40 minutes or so if it works in the real world… :slight_smile:

This is an old thread, but for the next person who stumbles across it when they’re wanting to debounce an input, I found this does the job BEAUTIFULLY:

node-red-debounce (node) - Node-RED