Money total counter

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

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

@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
Screen Shot 2021-11-21 at 3.01.54 PM

[{"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}]

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

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

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' 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.

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?

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

[{"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

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

to

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

and save the file.

@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

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