# Function: Debounce Function to Output Only the Final Stable Value

**URL:** <https://discourse.nodered.org/t/function-debounce-function-to-output-only-the-final-stable-value/100724>\
**Category:** Share Your Nodes\
**Created:** [6 April 2026 08:18 UTC](https://discourse.nodered.org/t/function-debounce-function-to-output-only-the-final-stable-value/100724 "2026-04-06T08:18:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dougle03](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dougle03/32/32979_2.png) [@dougle03](https://discourse.nodered.org/u/dougle03)\
**Post date:** [6 April 2026 08:18 UTC](https://discourse.nodered.org/t/function-debounce-function-to-output-only-the-final-stable-value/100724/1 "2026-04-06T08:18:32Z")

</div>

So I wanted a node to settle down chatty inputs.  
My example: I have a dashboard number input using up and down buttons. It cycles through .5 steps to set HVAC temperature. After this input is a function that directly controls my hvac unit.  
The problem was if I wanted up the set temperature by 3 I'd need to click the up button 6 times in rapid succession. This was causing the control function to fire 6 times swamping the HVAC controller. The delay or rate limit nodes were no good as they pass the first message then delay drop later messages, but I wanted the last stable number... So I built the below simple function to store the number stream, hold the last number then send it after the time delay.  
A little like a debounce filter, but only the last value, not the first.

Let me know any thoughts or improvements:

```auto
// This function holds the unput until it settles down.
// It forwards the last number recieved after the cool down.

// Set the hold time
let delaySeconds = 1.5; // change this to whatever you want
let delayMs = delaySeconds * 1000;

// Clear previous timer
let timer = context.get("timer");
if (timer) {
    clearTimeout(timer);
}

// store latest number input
context.set("lastMsg", msg);

// The timer
timer = setTimeout(() => {
    node.send(context.get("lastMsg")); //output then settled
}, delayMs);

context.set("timer", timer);
return null;

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 April 2026 08:47 UTC](https://discourse.nodered.org/t/function-debounce-function-to-output-only-the-final-stable-value/100724/2 "2026-04-06T08:47:44Z")

</div>

You can use a Trigger node configured like this

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/31eaba9715705a6b316d027fa6e92042037bbc4a.png)

That will wait for a gap of 1.5 seconds between inputs and then send the latest message received.

---

<div class="post-metadata">

**Author:** ![dougle03](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dougle03/32/32979_2.png) [@dougle03](https://discourse.nodered.org/u/dougle03)\
**Post date:** [6 April 2026 08:50 UTC](https://discourse.nodered.org/t/function-debounce-function-to-output-only-the-final-stable-value/100724/3 "2026-04-06T08:50:23Z")

</div>

> [@Colin](#):
>
> You can use a Trigger node

Never thought of a trigger node... Good shout...

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 April 2026 09:08 UTC](https://discourse.nodered.org/t/function-debounce-function-to-output-only-the-final-stable-value/100724/4 "2026-04-06T09:08:48Z")

</div>

Whenever a timer feature is required then consider the trigger node, it is an extremely flexible and useful node.

---

<div class="post-metadata">

**Author:** ![Tany](https://avatars.discourse-cdn.com/v4/letter/t/dfb087/32.png) [@Tany](https://discourse.nodered.org/u/Tany)\
**Post date:** [7 April 2026 10:17 UTC](https://discourse.nodered.org/t/function-debounce-function-to-output-only-the-final-stable-value/100724/5 "2026-04-07T10:17:47Z")

</div>

for this type of settings i work with standard NR web socket and \<input type="range". A slider you drag to the value wanted, and when released it is saved/handled.  
No debouncing action needed.

`<input type="range" id="rgZB_TS011F_03ModeTime" min="10" max="60" step="10" value="" onchange="input_update('rgZB_TS011F_03ModeTime',this.value)"> <br>`

---

<div class="post-metadata">

**Author:** ![dougle03](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dougle03/32/32979_2.png) [@dougle03](https://discourse.nodered.org/u/dougle03)\
**Post date:** [7 April 2026 13:27 UTC](https://discourse.nodered.org/t/function-debounce-function-to-output-only-the-final-stable-value/100724/6 "2026-04-07T13:27:31Z")

</div>

> [@Tany](#):
>
> A slider

Thanks, but I prefer the precision of the Up/Dn buttons. It was sliders originally.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [7 April 2026 14:00 UTC](https://discourse.nodered.org/t/function-debounce-function-to-output-only-the-final-stable-value/100724/7 "2026-04-07T14:00:37Z")

</div>

In fact the number input node has a built in debounce function.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/b/4b022e9b8a4a7131af7fbaf266dad310190728ac.png)

---

<div class="post-metadata">

**Author:** ![dougle03](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dougle03/32/32979_2.png) [@dougle03](https://discourse.nodered.org/u/dougle03)\
**Post date:** [8 April 2026 08:21 UTC](https://discourse.nodered.org/t/function-debounce-function-to-output-only-the-final-stable-value/100724/8 "2026-04-08T08:21:05Z")

</div>

I don't see those options in the dashboard 1 nodes?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 April 2026 08:39 UTC](https://discourse.nodered.org/t/function-debounce-function-to-output-only-the-final-stable-value/100724/9 "2026-04-08T08:39:44Z")

</div>

You may be right, I moved over to D2 over two years ago.
