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?
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.
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 !