# Decrease Dashboard Value

**URL:** <https://discourse.nodered.org/t/decrease-dashboard-value/46771>\
**Category:** General\
**Created:** [6 June 2021 11:30 UTC](https://discourse.nodered.org/t/decrease-dashboard-value/46771 "2021-06-06T11:30:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChrisTs99](https://avatars.discourse-cdn.com/v4/letter/c/779978/32.png) [@ChrisTs99](https://discourse.nodered.org/u/ChrisTs99)\
**Post date:** [6 June 2021 11:30 UTC](https://discourse.nodered.org/t/decrease-dashboard-value/46771/1 "2021-06-06T11:30:11Z")

</div>

Hello,

I am new to node-red and I am trying to find a way to decrease a gauge value by 1 every 4 seconds. The problem is that have set timestamp as number 10 and when I deploy it becomes 9 and then it keeps generating 9 instead of 9 (wait 4 seconds) 8 (wait.....) until 0. Is there any way to implement this?

Thanks for your time, appreciate your help!

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/85ee463ff0d8cf6c89eb67bae299c6d67285c553.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/1/6146cab173c569c323a07fdc9efa963136cfd89d.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/0/90ab928bd82307fe6c45be2c03e2b5b2cbaccaea.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/1/818f7607cfa0aaebcca7bbf7a4a5eb52ea24b5e1.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/8/687517a6b4723af321bf49413119aa423275b36e.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 June 2021 11:37 UTC](https://discourse.nodered.org/t/decrease-dashboard-value/46771/2 "2021-06-06T11:37:23Z")

</div>

you need to store the previous value in the function then recall it when it runs again.

e.g...

```auto
var counter = context.get("counter");
if(!counter) {
  counter = msg.payload;
} else {
  counter--;
}
msg.payload = counter;
context.set("counter",counter);
return msg;

```

Read the node-red docs on functions and context.

---

<div class="post-metadata">

**Author:** ![ChrisTs99](https://avatars.discourse-cdn.com/v4/letter/c/779978/32.png) [@ChrisTs99](https://discourse.nodered.org/u/ChrisTs99)\
**Post date:** [6 June 2021 11:41 UTC](https://discourse.nodered.org/t/decrease-dashboard-value/46771/3 "2021-06-06T11:41:46Z")

</div>

Thanks a lot for your help !

---

<div class="post-metadata">

**Author:** ![ChrisTs99](https://avatars.discourse-cdn.com/v4/letter/c/779978/32.png) [@ChrisTs99](https://discourse.nodered.org/u/ChrisTs99)\
**Post date:** [6 June 2021 14:39 UTC](https://discourse.nodered.org/t/decrease-dashboard-value/46771/4 "2021-06-06T14:39:24Z")

</div>

Is there anyway to reset it when pressing the timestamp? Thanks for your time !

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 June 2021 14:51 UTC](https://discourse.nodered.org/t/decrease-dashboard-value/46771/5 "2021-06-06T14:51:04Z")

</div>

Connect another inject directly to the function & set the topic to something like reset. Then in your function code, test the msg.topic for equalling "reset" and reset the counter value.

However, be aware, due to the way you set this up (using the trigger node) messages will continue to be sent into the function. So you might also want to send msg.reset = true to the trigger node to stop it.

Tbh there are many ways to achieve this using many different techniques, have a play, give it a go.

---

<div class="post-metadata">

**Author:** ![ChrisTs99](https://avatars.discourse-cdn.com/v4/letter/c/779978/32.png) [@ChrisTs99](https://discourse.nodered.org/u/ChrisTs99)\
**Post date:** [6 June 2021 15:08 UTC](https://discourse.nodered.org/t/decrease-dashboard-value/46771/7 "2021-06-06T15:08:58Z")

</div>

I am trying to reset using the following line inside the function:  
if (msg.topic=="reset") counter = 0;  
but I am not sure if I am using this right because it doesn't reset.  
Instead of "counter=0" I tried "context.set("counter",0)" but still nothing. (I connected an inject directly to the function and the topic is reset)  
Thanks again for your help ! Appreciate it a lot !

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 June 2021 15:09 UTC](https://discourse.nodered.org/t/decrease-dashboard-value/46771/8 "2021-06-20T15:09:57Z")

</div>

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