# Reset dashboard values

**URL:** <https://discourse.nodered.org/t/reset-dashboard-values/88800>\
**Category:** General\
**Created:** [19 June 2024 13:24 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800 "2024-06-19T13:24:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)\
**Post date:** [19 June 2024 13:24 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/1 "2024-06-19T13:24:29Z")

</div>

Hey node heads, i had a quick question. if i've got a dash readout like this:

 ![dashboard readings](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/3/73a7a833924e5b18e02013fe4d8112525da1e7e8.png)

and i wanted to (on press of a reset button on the dash) empty the value fields of all those message nodes... does anyone know of how to organise the function to do it? i tried having the reset button feed into a for loop, but i couldn't get it to work. it only ever wiped the timestamp.

i cant upload the flow as it is too big. but here is a SS of the flow:

 ![node-flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/a/0a0112c344f24d656af91448b2e5c11d26146368.png)

it's not a game breaking thing, i just thought it would be neat for the user to have between tests to start from an empty dashboard

---

<div class="post-metadata">

**Author:** ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)\
**Post date:** [19 June 2024 13:26 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/2 "2024-06-19T13:26:09Z")

</div>

i will add. that i am able to successfully do it by linking the reset function which forces the msg.payload = "";, to the message nodes at the end. but then i end up with 21 wires which gets messy. just curious if you guys with more experience and knowledge know of a more elegant functional way

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [19 June 2024 13:42 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/3 "2024-06-19T13:42:19Z")

</div>

If you want a message to flow from one place to another you need wires.

But maybe you could use the existing wires by adding some code to your message parser function node. Something like this might work, depending on what your change nodes do.

```auto
if (msg.payload === "reset") {
    msg = {"payload": ""}
    return[msg, msg, msg, msg, ...] // as many as the function has outputs
}
// normal node processing here

```

ps Would you end up with less wiring if your function only had one output?  
Do you actually need all those change nodes?  
Remember the dashboard nodes are not limited to displaying `msg.payload`, they can also be set to display eg `msg.payload.B1`

---

<div class="post-metadata">

**Author:** ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)\
**Post date:** [19 June 2024 13:58 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/4 "2024-06-19T13:58:50Z")

</div>

hi Jbudd, there are most certainly wires in the flow lol... but i do use out \> in nodules to make the wires less messy (invisible).

the change nodes are just there to do some conversion from string to number to allow for range calculation of the value and thus changing the text colour (as in first image) the reason for the string to number conversion is because after some arbitrary point, the colour change node wasn't listening / outputting the correct response to the message node any more because it wasn't able to actually read the number in the string (it was a whole thing, but don't worry it doesn't affect the need for a function to delete all the values currently shown on dash).

as for the number of outputs, that function takes 20 readings coming in from a single serial string and parses them out into the grid / timestamp you see in dash

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [19 June 2024 14:10 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/5 "2024-06-19T14:10:42Z")

</div>

> [@Boerwors](#):
>
> the change nodes are just there to do some conversion from string to number

So you could get rid of them and use the Javascript Number() function in the message parser function. 🙂

---

<div class="post-metadata">

**Author:** ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)\
**Post date:** [19 June 2024 14:20 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/6 "2024-06-19T14:20:24Z")

</div>

i tried that but i ran into a bugger where if any of the boards aren't connected, the message displays a string error. and then node-red throws a tizzy about not being able to conver "error" to a number. i could just do what i do in the change node where i declare the error to have a value of 1000000 and then convert that to number. then on the other side of the node i read the number 1000000 and declare it as "ERROR".

here's what those changes do to the message in order from left to right:  
1)  
 ![change 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/9/b9c0f5bb8c695da5fc8e55fa538d1688871596b1.png)  
2)

 ![change 2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/e/eef6e98622c8b17ae95851d41696608ddf8cc41c.png)

i'm aware it's a roundabout way of doing it, but it works lol (constraints upon constraints).

to avoid going off topic

is there any way to write a function in JS / node-red that effectively tells all message nodes to become a clean slate? without a simple re-declare and 21 wires anyway

---

<div class="post-metadata">

**Author:** ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)\
**Post date:** [19 June 2024 14:22 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/7 "2024-06-19T14:22:16Z")

</div>

> [@jbudd](#):
>
> Remember the dashboard nodes are not limited to displaying `msg.payload`, they can also be set to display eg `msg.payload.B1`

what do you mean by this exactly?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [19 June 2024 14:31 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/8 "2024-06-19T14:31:50Z")

</div>

> [@Boerwors](#):
>
> is there any way to write a function in JS / node-red that effectively tells all message nodes to become a clean slate?

I thought I answered that question, perhaps I misunderstood?

> [@jbudd](#):
>
> But maybe you could use the existing wires by adding some code to your message parser function node. Something like this might work, depending on what your change nodes do.
> 
> ```auto
> if (msg.payload === "reset") {
> msg = {"payload": ""}
> return[msg, msg, msg, msg, ...] // as many as the function has outputs
> }
> // normal node processing here
> 
> ```

---

<div class="post-metadata">

**Author:** ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)\
**Post date:** [19 June 2024 14:50 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/9 "2024-06-19T14:50:01Z")

</div>

hmmm unfortunately i tried that too and all it does it deletes only the first output, none of the others. i then tried to make it output an array, but then it just replaced the timestamp with the word reset.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [19 June 2024 15:05 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/10 "2024-06-19T15:05:06Z")

</div>

> [@Boerwors](#):
>
> what do you mean by this exactly?

I was thinking if your function emits an object something like this

```auto
{
"B1":1500,
"B2":1000000,
"B3":900
}

```

then your ui-texts can display `{{msg.payload.B1}}`, `{{msg.payload.B2}}` or `{{msg.payload.B3}}` (etc)

Which implies a single output and should get rid of some of the change node processing.

However I can't immediately think of a simple way to combine this with colouring the output depending on the value, so probably not worth the effort.

> [@Boerwors](#):
>
> hmmm unfortunately i tried that too and all it does it deletes only the first output, none of the others.

Impossible to comment without seeing the function code and it's input data.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [20 June 2024 00:04 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/11 "2024-06-20T00:04:28Z")

</div>

I agree with @jbudd, it would be simpler to process this in the message parser node.

Can you share just the function node and a sample of the data it receives ?

---

<div class="post-metadata">

**Author:** ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)\
**Post date:** [20 June 2024 06:39 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/12 "2024-06-20T06:39:58Z")

</div>

> [@jbudd](#):
>
> then your ui-texts can display `{{msg.payload.B1}}`, `{{msg.payload.B2}}` or `{{msg.payload.B3}}` (etc)
> 
> Which implies a single output and should get rid of some of the change node processing.
> 
> However I can't immediately think of a simple way to combine this with colouring the output depending on the value, so probably not worth the effort.

ah, no the data is coming in just as numbers:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/4/e448461e69bd775fc54794a74267061d6d7353e7.png)

so the message payload is each reading separated by a tab but only the value of the reading as i use the dashboard and csv node to format headings etc.

i assume you mean the message parser function code?:

```auto
var display = [];
var values = msg.payload.split("\t");
for(var v in values){
    display.push({payload:values[v]});
}

return display;

```

---

<div class="post-metadata">

**Author:** ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)\
**Post date:** [20 June 2024 06:45 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/13 "2024-06-20T06:45:24Z")

</div>

@Sean-McG

i've taken a picture of how the message parser receives data (one msg.payload with multiple values in a single message separated by tabs)

and copied in the parser code.

i wonder if using a for statement could work in some fashion combined with the IF == reset example jbudd suggested. so:

```auto
if (msg.payload == reset){
for iterations{
msg.payload = ""}
}

```

or perhaps a change node that has an if statement on the input of the message parser function?

---

<div class="post-metadata">

**Author:** ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)\
**Post date:** [20 June 2024 07:03 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/14 "2024-06-20T07:03:55Z")

</div>

just another update, this is what i've attempted following jbudds suggestion:

```auto
var output = [];
var values = msg.payload.trim().split("\t");

if (msg.payload === "reset") {
    msg.payload = " " + "\t" + " " + "\t" + " " + "\t"

}
for(var v in values){
    output.push({payload:values[v]});
}

return output;

```

this is what is does to the dashboard:

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

even if i get rid of the tabs in the new msg.payload and just have ""+""+""+""+... etc, it does same thing... weird.

---

<div class="post-metadata">

**Author:** ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)\
**Post date:** [20 June 2024 07:36 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/15 "2024-06-20T07:36:23Z")

</div>

So i managed to get it to work, however the message changing nodes to allow for ERROR vs number to be properly displayed didn't like that the message wasn't a number anymore (can't convert " " to a number after all.

i think i'll have to just link a forced message change function directly to the dashboard nodes ☹

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [20 June 2024 07:45 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/16 "2024-06-20T07:45:21Z")

</div>

There are always multiple ways to achieve the same ends.  
I don't think this is a better solution than yours, just that it handles a RESET injection.

Considering that your input data is an array of numbers (though you have hinted it might sometimes contain numbers as strings and perhaps "ERROR BOARD NOT FOUND"), I might approach it like this.

Use a split node to break the input into messages each with a single value.  
A function to process these messages.  
A switch node to route the output to the dashboard widgets based on msg.parts.index.

To achieve the reset function inject an array of 21 empty strings and topic "RESET"

The function node would be something like this

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/d/1da2e6ba8e07542c7abbe4de0827785b408039c8.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a4acd7cd45d281aa1d7d6fec8084554681edea74.png)

```auto
[{"id":"356c4f0ce5e69212","type":"inject","z":"845828586139eeb4","name":"Sample data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1,\"2\",\"ERROR\"]","payloadType":"jsonata","x":110,"y":260,"wires":[["6ff80d1b39744e05"]]},{"id":"6ff80d1b39744e05","type":"split","z":"845828586139eeb4","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":370,"y":260,"wires":[["c1456f65f632c1c5"]]},{"id":"c1456f65f632c1c5","type":"function","z":"845828586139eeb4","name":"function 1","func":"if (msg.payload === \"ERROR\") { // Handle ERROR\n msg.payload = \"-1\"\n}\nif (msg.topic === \"RESET\") { // Send \" \" for RESET topic\n msg.payload = \" \"\n}\nelse {\n msg.payload = Number(msg.payload)\n msg.colour = \"green\"\n if (msg.payload > 1200 || msg.payload < 10) {\n msg.colour = \"red\"\n }\n}\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":260,"wires":[["6dd4c24e0413fd1c"]]},{"id":"6dd4c24e0413fd1c","type":"switch","z":"845828586139eeb4","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"},{"t":"eq","v":"4","vt":"num"},{"t":"eq","v":"5","vt":"num"},{"t":"eq","v":"6","vt":"num"},{"t":"eq","v":"7","vt":"num"},{"t":"eq","v":"8","vt":"num"},{"t":"eq","v":"9","vt":"num"},{"t":"eq","v":"10","vt":"num"},{"t":"eq","v":"11","vt":"num"},{"t":"eq","v":"12","vt":"num"},{"t":"eq","v":"13","vt":"num"},{"t":"eq","v":"14","vt":"num"},{"t":"eq","v":"15","vt":"num"},{"t":"eq","v":"16","vt":"num"},{"t":"eq","v":"17","vt":"num"},{"t":"eq","v":"18","vt":"num"},{"t":"eq","v":"19","vt":"num"},{"t":"eq","v":"20","vt":"num"}],"checkall":"true","repair":false,"outputs":21,"x":630,"y":260,"wires":[["1292dfe446098937"],["4ae09484e4d3130a"],["c57cfc0b45de138d"],["fedb633e6e0d2891"],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],["0538a0270a693b3d"]]},{"id":"1292dfe446098937","type":"debug","z":"845828586139eeb4","name":"0","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":100,"wires":[]},{"id":"4ae09484e4d3130a","type":"debug","z":"845828586139eeb4","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":140,"wires":[]},{"id":"c57cfc0b45de138d","type":"debug","z":"845828586139eeb4","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":180,"wires":[]},{"id":"fedb633e6e0d2891","type":"debug","z":"845828586139eeb4","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":220,"wires":[]},{"id":"4ff544b6599472a2","type":"inject","z":"845828586139eeb4","name":"Reset - array of empty strings","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"RESET","payload":"[\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \"]","payloadType":"json","x":160,"y":300,"wires":[["6ff80d1b39744e05"]]},{"id":"0538a0270a693b3d","type":"debug","z":"845828586139eeb4","name":"etc","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":400,"wires":[]}]

```

> [@Boerwors](#):
>
> ERROR vs number to be properly displayed didn't like that the message wasn't a number anymore

I agree it's a bit of a pain to handle an input which might be a string, might be a number and might contain "ERROR".  
That is why my function has `if(msg.payload === "ERROR)` and not ` if (msg.payload.includes("ERROR))`

---

<div class="post-metadata">

**Author:** ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)\
**Post date:** [20 June 2024 08:19 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/17 "2024-06-20T08:19:45Z")

</div>

hmmmm i've copied your flow in and it looks at a glance that it should replicate what my change nodes need to do... if i get some free time today i'll have a look at integrating it. thank you for your help 🙂

---

<div class="post-metadata">

**Author:** ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)\
**Post date:** [20 June 2024 08:26 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/18 "2024-06-20T08:26:29Z")

</div>

i have just realised about your error = -1 solution, i do want the dashboard to display error board not found, so i assume i would have to convert -1 back to error after the colour change statement in your function?

also i just tested it, doesn't allow my timestamp to output... maybe if i inject the timestamp manually past the function it might work?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [20 June 2024 09:12 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/19 "2024-06-20T09:12:32Z")

</div>

> [@Boerwors](#):
>
> so i assume i would have to convert -1 back to error after the colour change statement in your function?

There is nothing special about the "-1".

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/27f9e97ac5517c8ecd3e5cbaae5c7763d73b3231.png)

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [20 June 2024 12:51 UTC](https://discourse.nodered.org/t/reset-dashboard-values/88800/20 "2024-06-20T12:51:05Z")

</div>

I will take a look at this later today, and see if I can come up with a neat solution for you 😉

Can you confirm the payload to the parse function always contains 20 values in the correct order ?

[Next page](https://discourse.nodered.org/t/reset-dashboard-values/88800.md?page=2)
