Sum function of two sensor data

I can't sum the numbers which are collected from sensors.

 [{"id":"a451fd95.e588d","type":"tab","label":"IoT Imaginary","disabled":false,"info":""},{"id":"9c84ad2a.aa978","type":"http response","z":"a451fd95.e588d","name":"","statusCode":"","headers":{},"x":1470,"y":320,"wires":[]},{"id":"79a9e37d.36d9bc","type":"comment","z":"a451fd95.e588d","name":"Get information Users","info":"Get information from load sensor","x":160,"y":300,"wires":[]},{"id":"909b9546.22b4b8","type":"comment","z":"a451fd95.e588d","name":"Challenge number","info":"","x":130,"y":100,"wires":[]},{"id":"eedb0dc8.653a9","type":"http in","z":"a451fd95.e588d","name":"","url":"/target","method":"get","upload":false,"swaggerDoc":"","x":330,"y":100,"wires":[["ef3dd8b3.074008"]]},{"id":"589db0bc.c9874","type":"http response","z":"a451fd95.e588d","name":"","statusCode":"","headers":{},"x":750,"y":120,"wires":[]},{"id":"ef3dd8b3.074008","type":"template","z":"a451fd95.e588d","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<!DOCTYPE html>\n<html>\n    <body>\n        <form action=\"/target\" method=\"post\">\n            <input type=\"radio\" name=\"status\" value=\"100\"> 100 <br>\n            <input type=\"radio\" name=\"status\" value=\"90\"> 90 <br>\n            <input type=\"radio\" name=\"status\" value=\"80\"> 80\n        <input type=\"submit\" value=\"Submit\">\n        </form>\n        \n    </body>\n    \n</html>","output":"str","x":540,"y":100,"wires":[["589db0bc.c9874"]]},{"id":"936222b4.80eb7","type":"switch","z":"a451fd95.e588d","name":"","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"0","vt":"num","v2":"0.24","v2t":"num"},{"t":"btwn","v":"0.25","vt":"num","v2":"0.49","v2t":"num"},{"t":"btwn","v":"0.50","vt":"num","v2":"0.99","v2t":"num"},{"t":"btwn","v":"1","vt":"num","v2":"1.25","v2t":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":5,"x":950,"y":320,"wires":[["fcb70e40.3976f"],["ced18342.3a5f4"],["ecfe2bbd.448148"],["e5492f8e.e7e38"],["4d71f88a.407eb8"]]},{"id":"fcb70e40.3976f","type":"change","z":"a451fd95.e588d","name":"5 Cigarettes","rules":[{"t":"set","p":"payload","pt":"msg","to":"5","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":240,"wires":[["9c84ad2a.aa978"]]},{"id":"ced18342.3a5f4","type":"change","z":"a451fd95.e588d","name":"10 Cigarettes","rules":[{"t":"set","p":"payload","pt":"msg","to":"10","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":280,"wires":[["9c84ad2a.aa978"]]},{"id":"ecfe2bbd.448148","type":"change","z":"a451fd95.e588d","name":"15 Cigarettes","rules":[{"t":"set","p":"payload","pt":"msg","to":"15","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":320,"wires":[["9c84ad2a.aa978"]]},{"id":"e5492f8e.e7e38","type":"change","z":"a451fd95.e588d","name":"20 Cigarettes","rules":[{"t":"set","p":"payload","pt":"msg","to":"20","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":360,"wires":[["9c84ad2a.aa978"]]},{"id":"4d71f88a.407eb8","type":"change","z":"a451fd95.e588d","name":"Unknown","rules":[{"t":"set","p":"payload","pt":"msg","to":"Unknown","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1220,"y":400,"wires":[["9c84ad2a.aa978"]]},{"id":"d916285b.fb23f8","type":"http in","z":"a451fd95.e588d","name":"","url":"/sensor/load/solo1","method":"get","upload":false,"swaggerDoc":"","x":400,"y":260,"wires":[["4d156285.98367c"]]},{"id":"d19fd759.310f88","type":"http in","z":"a451fd95.e588d","name":"","url":"/sensor/load/solo2","method":"get","upload":false,"swaggerDoc":"","x":400,"y":380,"wires":[["3f7e6862.2877d8"]]},{"id":"4d156285.98367c","type":"random","z":"a451fd95.e588d","name":"","low":"0","high":"1.25","inte":"false","property":"payload","x":710,"y":320,"wires":[["dc59a747.6fa558","936222b4.80eb7"]]},{"id":"f3036ac1.e9a8a8","type":"inject","z":"a451fd95.e588d","name":"","topic":"","payload":"","payloadType":"date","repeat":"5","crontab":"","once":false,"onceDelay":0.1,"x":420,"y":580,"wires":[["d9e1568.02e60a8","fdddbe89.435a1"]]},{"id":"d9e1568.02e60a8","type":"http request","z":"a451fd95.e588d","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"http://localhost:1880/sensor/load/solo1","tls":"","proxy":"","authType":"basic","x":650,"y":560,"wires":[["b4e36c95.47f58","74fb5f4c.8164f"]]},{"id":"b4e36c95.47f58","type":"debug","z":"a451fd95.e588d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":970,"y":540,"wires":[]},{"id":"fdddbe89.435a1","type":"http request","z":"a451fd95.e588d","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"http://localhost:1880/sensor/load/solo2","tls":"","proxy":"","authType":"basic","x":610,"y":620,"wires":[["b4e36c95.47f58","8221d996.bc3c78"]]},{"id":"8221d996.bc3c78","type":"ui_gauge","z":"a451fd95.e588d","name":"","group":"df0f0026.364d9","order":2,"width":0,"height":0,"gtype":"wave","title":"S02","label":"Cig","format":"{{value}}","min":0,"max":"20","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1020,"y":680,"wires":[]},{"id":"dc59a747.6fa558","type":"debug","z":"a451fd95.e588d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":970,"y":440,"wires":[]},{"id":"4848ce9e.39aa4","type":"comment","z":"a451fd95.e588d","name":"Chart","info":"Change the weight of ashes to Number of cigarettes","x":190,"y":580,"wires":[]},{"id":"74fb5f4c.8164f","type":"ui_gauge","z":"a451fd95.e588d","name":"","group":"f48a683a.03ab88","order":3,"width":0,"height":0,"gtype":"wave","title":"S.01","label":"Cig","format":"{{value}}","min":0,"max":"20","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1040,"y":620,"wires":[]},{"id":"3f7e6862.2877d8","type":"random","z":"a451fd95.e588d","name":"","low":"0","high":"1.25","inte":"false","property":"payload","x":720,"y":380,"wires":[["936222b4.80eb7","dc59a747.6fa558"]]},{"id":"43622cad.c44734","type":"ui_gauge","z":"a451fd95.e588d","name":"","group":"fc70f4eb.d19968","order":1,"width":0,"height":0,"gtype":"wave","title":"S1+S2","label":"Cig","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1270,"y":900,"wires":[]},{"id":"d8c36831.0a2eb8","type":"comment","z":"a451fd95.e588d","name":"sum the cigarettes","info":"","x":230,"y":760,"wires":[]},{"id":"3b0ee3f0.0e7f4c","type":"change","z":"a451fd95.e588d","name":"","rules":[{"t":"set","p":"var1","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":760,"wires":[["4cbaa952.6aa0c8"]]},{"id":"f2db7303.c9f6a","type":"debug","z":"a451fd95.e588d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","x":1250,"y":820,"wires":[]},{"id":"bbc6bae4.6ad6f8","type":"change","z":"a451fd95.e588d","name":"","rules":[{"t":"set","p":"var2","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":820,"wires":[["4cbaa952.6aa0c8"]]},{"id":"5fa7cc2e.149b04","type":"http response","z":"a451fd95.e588d","name":"","statusCode":"","headers":{},"x":1210,"y":760,"wires":[]},{"id":"b7600d49.43634","type":"change","z":"a451fd95.e588d","name":"sum","rules":[{"t":"set","p":"payload","pt":"msg","to":"$flowContext('var1')+$flowContext('var2')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1010,"y":760,"wires":[["5fa7cc2e.149b04","f2db7303.c9f6a","43622cad.c44734"]]},{"id":"4cbaa952.6aa0c8","type":"join","z":"a451fd95.e588d","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":830,"y":760,"wires":[["b7600d49.43634"]]},{"id":"480bc06f.d1d71","type":"http in","z":"a451fd95.e588d","name":"","url":"/sensor/load/solo2","method":"get","upload":false,"swaggerDoc":"","x":440,"y":820,"wires":[["bbc6bae4.6ad6f8"]]},{"id":"84a182d8.e8c34","type":"http in","z":"a451fd95.e588d","name":"","url":"/sensor/load/solo1","method":"get","upload":false,"swaggerDoc":"","x":440,"y":760,"wires":[["3b0ee3f0.0e7f4c"]]},{"id":"df0f0026.364d9","type":"ui_group","z":"","name":"Chart Solo 02","tab":"671e00e4.f26dd","order":2,"disp":true,"width":"6","collapse":false},{"id":"f48a683a.03ab88","type":"ui_group","z":"","name":"Chart Solo 01","tab":"671e00e4.f26dd","order":1,"disp":true,"width":"6","collapse":false},{"id":"fc70f4eb.d19968","type":"ui_group","z":"","name":"S1+S2","tab":"671e00e4.f26dd","order":3,"disp":true,"width":"6","collapse":false},{"id":"671e00e4.f26dd","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Unfortunately your flow isn't currently importable.Please read the following post How to share code or flow json and then edit the above message.

Take a look at the cookbook that might have an example that helps... http://cookbook.nodered.org

1 Like

There are a few ways to do this. I believe the join node will work however my preferred method is to store the values in flow context & then when any one changes, pull them both back from flow context & add them together.

Unfortunately, my major is product design and I'm not familiar with the node red environment. In fact, the university has forced on to work on this project

have you tried anything?

Have you tried a join node to see what happens?

Have you read up on context?

Lastly, have you searched this forum? There are many examples.

Heres one i adapted slightly...

[{"id":"123c9490.2e5d7b","type":"ui_numeric","z":"80855e36.822e4","name":"","label":"User input","tooltip":"","group":"3a2a4dcc.dcbe52","order":2,"width":0,"height":0,"passthru":true,"topic":"","format":"{{value}}","min":0,"max":"65535","step":1,"x":132,"y":419,"wires":[["7bfa89f5.6cd918"]]},{"id":"52d1cae0.928e64","type":"ui_text","z":"80855e36.822e4","group":"3a2a4dcc.dcbe52","order":3,"width":0,"height":0,"name":"","label":"Result","format":"{{msg.payload}}","layout":"row-spread","x":670,"y":400,"wires":[]},{"id":"897f5f4f.ba462","type":"change","z":"80855e36.822e4","name":"","rules":[{"t":"set","p":"val1","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":360,"wires":[["8f1ffaa.e986308"]]},{"id":"8f1ffaa.e986308","type":"function","z":"80855e36.822e4","name":"add","func":"var val1 = parseInt(flow.get(\"val1\") || \"0\");\nmsg.payload = parseInt(flow.get(\"val2\") || \"0\") + val1;\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":400,"wires":[["52d1cae0.928e64"]]},{"id":"7bfa89f5.6cd918","type":"change","z":"80855e36.822e4","name":"","rules":[{"t":"set","p":"val2","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":420,"wires":[["8f1ffaa.e986308"]]},{"id":"a5bad124.1f4b9","type":"ui_numeric","z":"80855e36.822e4","name":"","label":"User input","tooltip":"","group":"3a2a4dcc.dcbe52","order":2,"width":0,"height":0,"passthru":true,"topic":"","format":"{{value}}","min":0,"max":"65535","step":1,"x":130,"y":360,"wires":[["897f5f4f.ba462"]]},{"id":"3a2a4dcc.dcbe52","type":"ui_group","z":"","name":"Default","tab":"7a83039f.32968c","disp":true,"width":"6","collapse":false},{"id":"7a83039f.32968c","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

edit...
This example requires node-red-dashboard
Steps to use it...

  1. Press CTRL+I (to open the import dialog)
  2. Paste the code in
  3. Deploy.
  4. Press CTRL+SHIFT+D to access the dashboard
1 Like

I've read this:

but it doesn't work.


How can I use it?

[{"id":"123c9490.2e5d7b","type":"ui_numeric","z":"80855e36.822e4","name":"","label":"User input","tooltip":"","group":"3a2a4dcc.dcbe52","order":2,"width":0,"height":0,"passthru":true,"topic":"","format":"{{value}}","min":0,"max":"65535","step":1,"x":132,"y":419,"wires":[["7bfa89f5.6cd918"]]},{"id":"52d1cae0.928e64","type":"ui_text","z":"80855e36.822e4","group":"3a2a4dcc.dcbe52","order":3,"width":0,"height":0,"name":"","label":"Result","format":"{{msg.payload}}","layout":"row-spread","x":670,"y":400,"wires":[]},{"id":"897f5f4f.ba462","type":"change","z":"80855e36.822e4","name":"","rules":[{"t":"set","p":"val1","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":360,"wires":[["8f1ffaa.e986308"]]},{"id":"8f1ffaa.e986308","type":"function","z":"80855e36.822e4","name":"add","func":"var val1 = parseInt(flow.get(\"val1\") || \"0\");\nmsg.payload = parseInt(flow.get(\"val2\") || \"0\") + val1;\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":400,"wires":[["52d1cae0.928e64"]]},{"id":"7bfa89f5.6cd918","type":"change","z":"80855e36.822e4","name":"","rules":[{"t":"set","p":"val2","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":420,"wires":[["8f1ffaa.e986308"]]},{"id":"a5bad124.1f4b9","type":"ui_numeric","z":"80855e36.822e4","name":"","label":"User input","tooltip":"","group":"3a2a4dcc.dcbe52","order":2,"width":0,"height":0,"passthru":true,"topic":"","format":"{{value}}","min":0,"max":"65535","step":1,"x":130,"y":360,"wires":[["897f5f4f.ba462"]]},{"id":"3a2a4dcc.dcbe52","type":"ui_group","z":"","name":"Default","tab":"7a83039f.32968c","disp":true,"width":"6","collapse":false},{"id":"7a83039f.32968c","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

Use what? The flow you posted is the one I posted 5 mins ago.

Use it like that ^

Or take the functioning parts and adapt them into your flow. I dont understand what you want?

I have two sensors. Each of them gives numbers between 0-1.25. Then I've changed them to numbers between 0-25. I have a chart for each sensor and now I need the chart which shows the sum of these two.

So where you get the value for gauge1 and gauge2, connect them also into the "set val1" and "set val2" nodes I provided. Then connect the output of the add function to your gauge3?

All the pieces are there - give it a go.

1 Like

It Works!!! Thanks :heart_eyes::heart_eyes::heart_eyes:

Thanks Steve - it work's like charm! :slight_smile:

One question: I added six values, the debug now sends six times the same value.. is there a solution to that?

Hi @cwein87 welcome to the forum.

That post is over 3 years old. A lot has changed in that time.

Please start a new thread detailing what you have done & what you are seeing.
Ensure the title is descriptive to draw the correct attension (e.g. "I have a problem" is not a good title. "How can 6 values in separate messages be added together" is a good title)

closing this old thread.