# Money total counter

**URL:** <https://discourse.nodered.org/t/money-total-counter/54048>\
**Category:** Dashboard\
**Tags:** node-red-dashboard\
**Created:** [21 November 2021 00:45 UTC](https://discourse.nodered.org/t/money-total-counter/54048 "2021-11-21T00:45:04Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Becherer](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@Becherer](https://discourse.nodered.org/u/Becherer)\
**Post date:** [21 November 2021 00:45 UTC](https://discourse.nodered.org/t/money-total-counter/54048/1 "2021-11-21T00:45:04Z")

</div>

I am looking to use node red to make a simple money counter. I would like to have a dashboard that has a starting number of zero, and someone can have a number pad to enter a number and press - or + to add to rolling total. What’s the best way about doing something like this?

I plan to use as such 2.22 + 6 + 3 -

After each entry, the total number changes to show total.

Thanks for your input on this, I am trying to learn my way around node red

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [21 November 2021 00:53 UTC](https://discourse.nodered.org/t/money-total-counter/54048/2 "2021-11-21T00:53:59Z")

</div>

A couple questions

1. are you looking to use a dashboard number pad or a physical number pad?
2. if a physical pad, how are you going to connect it to a computer? What pad is it?
3. how will you reset the number back to zero after the counting is done?
4. what device will you be running Node-RED on?
5. what have you tried so far?

If you haven't done it yet, I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![Becherer](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@Becherer](https://discourse.nodered.org/u/Becherer)\
**Post date:** [21 November 2021 21:09 UTC](https://discourse.nodered.org/t/money-total-counter/54048/3 "2021-11-21T21:09:35Z")

</div>

@zenofmud,  
Thank you for your quick response.  
Per your questoins

1. are you looking to use a dashboard number pad or a physical number pad?  
**-Using a keyboard**
2. if a physical pad, how are you going to connect it to a computer? What pad is it?  
**-USB Keyboard with number pad.**
3. how will you reset the number back to zero after the counting is done?  
**-I will just subtract the actual number with itself to bring it back to "0"**
4. what device will you be running Node-RED on?  
**-Raspberry pi**
5. what have you tried so far?  
**-This is what I have so far.**

I want to be able to have the result automatically get added as the "Number1". See in attachments. Once I add two numbers, the total is displayed as a value. I want that value to automatically get added to the Number1 field.

Also is there a way to have the "Operation" be able to be selected by pressing the "-" or "+" on the number pad instead of selecting the field and entering the "Operation". I will only need to use the "-" or "+".  
 ![Screen Shot 2021-11-21 at 3.01.22 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/f/5f3784a697c6d1127e2f814d3e79acb213402112.png)  
 ![Screen Shot 2021-11-21 at 3.01.54 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/57cdf2300d31303052b872ed8800058a415b8fef.png)

```auto
[{"id":"753ea53bad373a24","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"6b1fbe08e324839c","type":"ui_form","z":"753ea53bad373a24","name":"","label":"Person1","group":"33e5c339802ecf45","order":2,"width":"0","height":"0","options":[{"label":"Number 1","value":"n1","type":"number","required":true,"rows":null},{"label":"Number 2","value":"n2","type":"number","required":true,"rows":null},{"label":"Operation","value":"op","type":"text","required":true,"rows":null}],"formValue":{"n1":"","n2":"","op":""},"payload":"","submit":"submit","cancel":"cancel","topic":"topic","topicType":"msg","splitLayout":true,"className":"","x":380,"y":40,"wires":[["7c6bd57c2327a1fd"]]},{"id":"7c6bd57c2327a1fd","type":"function","z":"753ea53bad373a24","name":"Person1","func":"n1 = msg.payload.n1;\nn2 = msg.payload.n2;\nop = msg.payload.op;\n\nswitch(op){\n case \"+\" : msg.payload.result = n1+n2;\n break;\n case \"-\" : msg.payload.result = n1 - n2;\n break;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":40,"wires":[["c5e8c10b3cf33f44"]]},{"id":"c5e8c10b3cf33f44","type":"ui_text","z":"753ea53bad373a24","group":"33e5c339802ecf45","order":1,"width":0,"height":0,"name":"","label":"","format":"{{msg.payload.result}}","layout":"row-spread","className":"","x":670,"y":40,"wires":[]},{"id":"fbd14e9c750ff16c","type":"ui_form","z":"753ea53bad373a24","name":"","label":"Person2","group":"958b6ed2724a72dc","order":3,"width":"0","height":"0","options":[{"label":"Number 1","value":"n1","type":"number","required":true,"rows":null},{"label":"Number 2","value":"n2","type":"number","required":true,"rows":null},{"label":"Operation","value":"op","type":"text","required":true,"rows":null}],"formValue":{"n1":"","n2":"","op":""},"payload":"","submit":"submit","cancel":"cancel","topic":"topic","topicType":"msg","splitLayout":true,"className":"","x":380,"y":120,"wires":[["61abcf6078aa9aa3"]]},{"id":"61abcf6078aa9aa3","type":"function","z":"753ea53bad373a24","name":"Person2","func":"n1 = msg.payload.n1;\nn2 = msg.payload.n2;\nop = msg.payload.op;\n\nswitch(op){\n case \"+\" : msg.payload.result = n1+n2;\n break;\n case \"-\" : msg.payload.result = n1 - n2;\n break;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":120,"wires":[["de93f9f828d36ad4"]]},{"id":"de93f9f828d36ad4","type":"ui_text","z":"753ea53bad373a24","group":"958b6ed2724a72dc","order":2,"width":0,"height":0,"name":"","label":"","format":"{{msg.payload.result}}","layout":"row-spread","className":"","x":670,"y":120,"wires":[]},{"id":"604326f671a3b8db","type":"ui_form","z":"753ea53bad373a24","name":"","label":"Person3","group":"958b6ed2724a72dc","order":8,"width":"0","height":"0","options":[{"label":"Number 1","value":"n1","type":"number","required":true,"rows":null},{"label":"Number 2","value":"n2","type":"number","required":true,"rows":null},{"label":"Operation","value":"op","type":"text","required":true,"rows":null}],"formValue":{"n1":"","n2":"","op":""},"payload":"","submit":"submit","cancel":"cancel","topic":"topic","topicType":"msg","splitLayout":true,"className":"","x":380,"y":200,"wires":[["c87fd25ae2f14358"]]},{"id":"c87fd25ae2f14358","type":"function","z":"753ea53bad373a24","name":"Person3","func":"n1 = msg.payload.n1;\nn2 = msg.payload.n2;\nop = msg.payload.op;\n\nswitch(op){\n case \"+\" : msg.payload.result = n1+n2;\n break;\n case \"-\" : msg.payload.result = n1 - n2;\n break;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":200,"wires":[["163bdc33ed0d32a0"]]},{"id":"163bdc33ed0d32a0","type":"ui_text","z":"753ea53bad373a24","group":"958b6ed2724a72dc","order":7,"width":0,"height":0,"name":"","label":"","format":"{{msg.payload.result}}","layout":"row-spread","className":"","x":670,"y":200,"wires":[]},{"id":"87cb85be1cbda6cf","type":"ui_spacer","z":"753ea53bad373a24","name":"spacer","group":"958b6ed2724a72dc","order":1,"width":1,"height":1},{"id":"33e5c339802ecf45","type":"ui_group","name":"","tab":"c5575cfe102a97de","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"958b6ed2724a72dc","type":"ui_group","name":"","tab":"c5575cfe102a97de","order":2,"disp":false,"width":"6","collapse":false,"className":""},{"id":"c5575cfe102a97de","type":"ui_tab","name":"Budget","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [21 November 2021 22:17 UTC](https://discourse.nodered.org/t/money-total-counter/54048/4 "2021-11-21T22:17:19Z")

</div>

Hi, in order to make code more readable and importable it is important to surround your code with three backticks  
`````  
`like this`  
`````

You can edit and correct your post by clicking the pencil icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![Becherer](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@Becherer](https://discourse.nodered.org/u/Becherer)\
**Post date:** [21 November 2021 22:29 UTC](https://discourse.nodered.org/t/money-total-counter/54048/6 "2021-11-21T22:29:44Z")

</div>

@zenofmud ,  
just did as you said, thanks for the trick!

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [21 November 2021 23:28 UTC](https://discourse.nodered.org/t/money-total-counter/54048/7 "2021-11-21T23:28:36Z")

</div>

Can ask why you want to do it in Node-RED? Why not just use a calculator?

Why do you have person 1-3 in the flow?  
Is this intended for multiple people to use it at the same time? NodeRED doesn't support multiuser access (at this point - maybe some time in the future) But you could run multiple occurances of NR (separate installations)

Right now your flow works if I remove two of your flows and go to the dashboard I can  
1 - hit the `tab` key till the focus is on `Number1`  
2 - enter the number and hit the `tab` key  
3 - enter the number for Number2 and hit the tab key  
4 - press the + or - key and hit `tab`  
5 - `Submit` should be hi-lighted, press enter.  
At this point the information is sent to your function node which will need to retrieve a flow variable (see '[Storing Data](https://nodered.org/docs/user-guide/writing-functions#storing-data)' in the function node documation) add the new value to it, store it back into the flow variable and sending the result to to your `text` node.

---

<div class="post-metadata">

**Author:** ![Becherer](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@Becherer](https://discourse.nodered.org/u/Becherer)\
**Post date:** [22 November 2021 01:08 UTC](https://discourse.nodered.org/t/money-total-counter/54048/8 "2021-11-22T01:08:35Z")

</div>

Yes I could use a calculator, but this will be used for me to track different budgets over a months to year time. Think of this as a POS calculator for various categories.

As it relates to passing the total back to the “Number1” field. I viewed the link, is there an example you can provide, I am a bit lost. I don’t know where to start. Do I add a function after the dashboard or before?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 November 2021 11:31 UTC](https://discourse.nodered.org/t/money-total-counter/54048/9 "2021-11-22T11:31:16Z")

</div>

I've edited your flow to add the 'flow.get()' and 'flow.set()' to show you how it could be done.

```auto
[{"id":"6b1fbe08e324839c","type":"ui_form","z":"753ea53bad373a24","name":"","label":"Person1","group":"33e5c339802ecf45","order":3,"width":"0","height":"0","options":[{"label":"Number 1","value":"n1","type":"number","required":true,"rows":null},{"label":"Number 2","value":"n2","type":"number","required":true,"rows":null},{"label":"Operation","value":"op","type":"text","required":true,"rows":null}],"formValue":{"n1":"","n2":"","op":""},"payload":"","submit":"submit","cancel":"cancel","topic":"topic","topicType":"msg","splitLayout":true,"className":"","x":100,"y":160,"wires":[["7c6bd57c2327a1fd","7b9e123981459c7f"]]},{"id":"7c6bd57c2327a1fd","type":"function","z":"753ea53bad373a24","name":"Person1","func":"// get p1-total - if it doesn't exist set it to zero\nlet total = flow.get('p1-total')||0\n\n//node.warn(\"total = \"+total) // for debugging\n\nn1 = msg.payload.n1;\nn2 = msg.payload.n2;\nop = msg.payload.op;\n\nswitch(op){\n case \"+\" : msg.payload.result = n1+n2;\n break;\n case \"-\" : msg.payload.result = n1 - n2;\n break;\n}\n\n// add the result to total\ntotal += msg.payload.result\n\n//node.warn(\"total2 = \"+total) // for debugging\n\n// put the ttal into the msg\nmsg.total = total\n// store the total in the flow variable 'p1-total'\nflow.set('p1-total', total)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":160,"wires":[["c5e8c10b3cf33f44","e496871970ab3759"]]},{"id":"c5e8c10b3cf33f44","type":"ui_text","z":"753ea53bad373a24","group":"33e5c339802ecf45","order":1,"width":0,"height":0,"name":"sum","label":"Sum","format":"{{msg.payload.result}}","layout":"row-spread","className":"","x":550,"y":120,"wires":[]},{"id":"7b9e123981459c7f","type":"debug","z":"753ea53bad373a24","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":280,"y":100,"wires":[]},{"id":"7f0220cd80e7f5d8","type":"inject","z":"753ea53bad373a24","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":220,"wires":[["3778482bea798984"]]},{"id":"3778482bea798984","type":"change","z":"753ea53bad373a24","name":"Delete fow variable 'p1-total'","rules":[{"t":"delete","p":"p1-total","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":220,"wires":[[]]},{"id":"e496871970ab3759","type":"ui_text","z":"753ea53bad373a24","group":"33e5c339802ecf45","order":2,"width":0,"height":0,"name":"running total","label":"Running Total","format":"{{msg.total}}","layout":"row-spread","className":"","x":570,"y":160,"wires":[]},{"id":"33e5c339802ecf45","type":"ui_group","name":"","tab":"c5575cfe102a97de","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"c5575cfe102a97de","type":"ui_tab","name":"Budget","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

You should also change your `settings.js` file to save the context data (if you haven't yet) so it will remain over reboots of NR.

Edit your `settings.js` file in the `.node-red` folder and change the lines

```auto
    //contextStorage: {
    // default: {
    // module:"localfilesystem"
    // },

```

to

```auto
    contextStorage: {
        default: {
            module:"localfilesystem"
        },

```

and save the file.

---

<div class="post-metadata">

**Author:** ![Becherer](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@Becherer](https://discourse.nodered.org/u/Becherer)\
**Post date:** [22 November 2021 22:51 UTC](https://discourse.nodered.org/t/money-total-counter/54048/10 "2021-11-22T22:51:52Z")

</div>

@zenofmud  
Thank you, I see what you did. For some reason after making the change to the settings.js it doesn't update the dashboard with the "p1-total". It keeps it stored as I can see in the context Flow. But how do I have it repopulate to the dashboard?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/9/0919f33eaf4219a0fd4be1084957c1767a733e12.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [23 November 2021 01:01 UTC](https://discourse.nodered.org/t/money-total-counter/54048/11 "2021-11-23T01:01:23Z")

</div>

If you have the new ui-text node in, make sure it is using msg.total as the value.

---

<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:** [23 December 2021 01:01 UTC](https://discourse.nodered.org/t/money-total-counter/54048/12 "2021-12-23T01:01:47Z")

</div>

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