Hello,
Please guide regarding performing average of 4 data coming from sensor using function node.
I have tried something as below.
var val1 = parseInt(flow.get("val1"));
msg.payload = parseInt(flow.get("val2")) + val1;
return msg;
Hello,
Please guide regarding performing average of 4 data coming from sensor using function node.
I have tried something as below.
var val1 = parseInt(flow.get("val1"));
msg.payload = parseInt(flow.get("val2")) + val1;
return msg;
maybe use the smooth
node set to handle 4 messages, if they are just continuously arriving data ? (rather than using flow variables nad aving to manage them).
Thank you for the reply!
No it's not continuously arriving. When ever I will press button on dashboard data will be received.
I am not able to deal with var newMsg = { payload: msg.payload,topic:msg.Agg1 }; or I am not sure
about I have done any mistake with change node.
[{"id":"1d93d5ed.92f58a","type":"change","z":"2349502c.99c05","name":"set topic to agg1","rules":[{"t":"set","p":"topic","pt":"msg","to":"Agg1","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":800,"wires":[["5fc5654e.601e1c","19d4c554.eb8b2b"]],"_type":"node"},{"id":"a9f2abc.c32c658","type":"change","z":"2349502c.99c05","name":"set topic to agg2","rules":[{"t":"set","p":"topic","pt":"msg","to":"Agg2","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":920,"wires":[["1694954b.2bbbab","19d4c554.eb8b2b"]]},{"id":"7026f7e.c6e0808","type":"change","z":"2349502c.99c05","name":"","rules":[{"t":"set","p":"val1","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":1080,"wires":[["108dd60d.a6f95a"]]},{"id":"11d47184.5b5cce","type":"change","z":"2349502c.99c05","name":"","rules":[{"t":"set","p":"val2","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":1160,"wires":[["108dd60d.a6f95a"]]},{"id":"1694954b.2bbbab","type":"debug","z":"2349502c.99c05","name":"","active":true,"console":"false","xaxis":"","complete":"payload","x":1030,"y":980,"wires":[]},{"id":"5fc5654e.601e1c","type":"debug","z":"2349502c.99c05","name":"","active":true,"console":"false","xaxis":"","complete":"payload","x":1030,"y":760,"wires":[]},{"id":"7fd74dbb.3c7404","type":"debug","z":"2349502c.99c05","name":"","active":true,"console":"false","xaxis":"","complete":"payload","x":1263.5,"y":862.97265625,"wires":[]},{"id":"1e4fa120.019a0f","type":"debug","z":"2349502c.99c05","name":"","active":true,"console":"false","xaxis":"","complete":"payload","x":967.50390625,"y":1240.98046875,"wires":[]},{"id":"1e7ec413.c5e2bc","type":"extract parameter","z":"2349502c.99c05","name":"Agg1_Current_Weight","topic":"1a655a707b4a445a98eb4f4e516b02a0/BatchMix_Current_Weight/Agg1_Current_Weight","topicData":"{\"asset\":\"1a655a707b4a445a98eb4f4e516b02a0\",\"assetName\":\"BatchMix\",\"aspect\":\"cde53ccd1ff84624af95951d5dc41188\",\"aspectName\":\"BatchMix_Current_Weight\",\"variable\":\"te977db91a139c\",\"variableName\":\"Agg1_Current_Weight\"}","parameter":"Agg1_Current_Weight","x":620,"y":800,"wires":[["1d93d5ed.92f58a","7026f7e.c6e0808"]]},{"id":"76a15ec5.0ad2d","type":"extract parameter","z":"2349502c.99c05","name":"Agg2_Current_Weight","topic":"1a655a707b4a445a98eb4f4e516b02a0/BatchMix_Current_Weight/Agg2_Current_Weight","topicData":"{\"asset\":\"1a655a707b4a445a98eb4f4e516b02a0\",\"assetName\":\"BatchMix\",\"aspect\":\"cde53ccd1ff84624af95951d5dc41188\",\"aspectName\":\"BatchMix_Current_Weight\",\"variable\":\"tf977db91a139d\",\"variableName\":\"Agg2_Current_Weight\"}","parameter":"Agg2_Current_Weight","x":620,"y":920,"wires":[["a9f2abc.c32c658","11d47184.5b5cce"]]},{"id":"108dd60d.a6f95a","type":"function","z":"2349502c.99c05","name":"add","func":"var val1 = parseInt(flow.get(\"val1\"));\nmsg.payload = parseInt(flow.get(\"val2\")) + val1;\nreturn msg;","outputs":1,"language":"javascript","noerr":0,"x":790,"y":1120,"wires":[["9884e4a1.5dfbe8","1e4fa120.019a0f"]]},{"id":"19d4c554.eb8b2b","type":"function","z":"2349502c.99c05","name":"","func":"var newMsg = { payload: msg.payload,topic:msg.Agg1 };\nreturn newMsg;","outputs":1,"language":"javascript","noerr":0,"x":1060,"y":860,"wires":[["7fd74dbb.3c7404"]],"_type":"node"},{"id":"381866a2.57779a","type":"read timeseries","z":"2349502c.99c05","name":"Agg1_Current_Weight","topic":"1a655a707b4a445a98eb4f4e516b02a0/BatchMix_Current_Weight/Agg1_Current_Weight","topicLabel":"BatchMix/BatchMix_Current_Weight/Agg1_Current_Weight","topicData":"{\"asset\":\"1a655a707b4a445a98eb4f4e516b02a0\",\"assetName\":\"BatchMix\",\"aspects\":[{\"aspectId\":\"cde53ccd1ff84624af95951d5dc41188\",\"aspectName\":\"BatchMix_Current_Weight\",\"variables\":[{\"variableId\":\"te977db91a139c\",\"name\":\"Agg1_Current_Weight\"}]}]}","assetName":"","selectedTopics":"","period":"60","offset":"0","mode":"lastValue","from":"","datetimepickerFrom":"","to":"","datetimepickerTo":"","timezoneoffset":0,"x":380,"y":800,"wires":[["1e7ec413.c5e2bc"]]},{"id":"4026ec1d.ffbf64","type":"read timeseries","z":"2349502c.99c05","name":"Agg2_Current_Weight","topic":"1a655a707b4a445a98eb4f4e516b02a0/BatchMix_Current_Weight/Agg2_Current_Weight","topicLabel":"BatchMix/BatchMix_Current_Weight/Agg2_Current_Weight","topicData":"{\"asset\":\"1a655a707b4a445a98eb4f4e516b02a0\",\"assetName\":\"BatchMix\",\"aspects\":[{\"aspectId\":\"cde53ccd1ff84624af95951d5dc41188\",\"aspectName\":\"BatchMix_Current_Weight\",\"variables\":[{\"variableId\":\"tf977db91a139d\",\"name\":\"Agg2_Current_Weight\"}]}]}","assetName":"","selectedTopics":"","period":"60","offset":"0","mode":"lastValue","from":"","datetimepickerFrom":"","to":"","datetimepickerTo":"","timezoneoffset":0,"x":380,"y":920,"wires":[["76a15ec5.0ad2d"]]},{"id":"bd83ce8.c13c63","type":"ui_button","z":"2349502c.99c05","name":"","group":"933bef30.6e133","order":0,"width":0,"singleBrowser":false,"height":0,"passthru":false,"label":"button_Average","color":"","bgcolor":"","icon":"","payload":"[65]","payloadType":"json","topic":"","powerMode":false,"x":160,"y":860,"wires":[["381866a2.57779a","4026ec1d.ffbf64"]]},{"id":"9884e4a1.5dfbe8","type":"ui_text","z":"2349502c.99c05","group":"933bef30.6e133","order":3,"width":0,"singleBrowser":false,"height":0,"name":"","label":"Result","format":"{{msg.payload}}","layout":"row-spread","x":970,"y":1120,"wires":[]},{"id":"933bef30.6e133","type":"ui_group","z":"","name":"Summation","tab":"71bf6668.e36f88","order":2,"disp":true,"width":"6","collapse":false,"_type":"config"},{"id":"71bf6668.e36f88","type":"ui_tab","z":"","name":"PLANT1","icon":"dashboard","order":3,"publicAccess":"true","fmAccess":"default","fmAccessType":"public","assetType":"","asset":"","assetName":"","assetText":"","image":"","description":"","hideTitleBar":false,"_type":"config"}]```
You could use array.reduce()
e.g.
let vals = flow.get(["val1","val2","val3","val4"]);
let count = 0
msg.payload = vals.reduce((acc, str) => {
let num = parseFloat(str);
if(!isNaN(num)){
acc+=num;
count++;
}
return acc;
},0) / count
return msg;
Thank you so much.
Sorry for bothering but please can you guide me from the basic. I have read about function node. but still not able to perform simple things like an average.
I am stuck here, var newMsg = { payload: msg.payload,topic:msg.Agg1 };
now I don't know how to get that particular value (like 88.18,[296.64]) from the change node and then use it in function node.
It would be great help If you can guide me about how can I learn to do these stuffs.
In the first post what I have posted was done by someone else, I have just taken it from one site.
Sorry - by continuously I meant all the data arriving down the same pipe... so yes sounds like it does to me as the format of the data will be the same every time you click the button. So the smooth node should be able to operate on it for you.
If you want to average the incoming Agg's then @dceejay smooth node suggestion should work.
e.g.
[{"id":"91ed3404248ead63","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"600","payloadType":"num","x":610,"y":2140,"wires":[["3948c6524f476f07"]]},{"id":"3948c6524f476f07","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Agg1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":2280,"wires":[["55361aab2126a937"]]},{"id":"be942040732bbd1b","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"88","payloadType":"num","x":610,"y":2180,"wires":[["3948c6524f476f07"]]},{"id":"4a62b512e2b2df5d","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"200","payloadType":"num","x":610,"y":2220,"wires":[["3948c6524f476f07"]]},{"id":"55361aab2126a937","type":"smooth","z":"452103ea51141731","name":"","property":"payload","action":"mean","count":"4","round":"","mult":"multi","reduce":false,"x":520,"y":2340,"wires":[["b55467f3.7db4a8"]]},{"id":"c6335dab10297ba2","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Agg2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":2400,"wires":[["55361aab2126a937"]]},{"id":"b55467f3.7db4a8","type":"switch","z":"452103ea51141731","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"100","vt":"str"},{"t":"gt","v":"400","vt":"str"},{"t":"btwn","v":"101","vt":"num","v2":"399","v2t":"num"}],"checkall":"true","outputs":3,"x":670,"y":2340,"wires":[["0e73504f05b83fe1"],["935bee49935fc29e"],["b894775069327319"]]},{"id":"3e04b86e4866ba3c","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"300","payloadType":"num","x":590,"y":2460,"wires":[["c6335dab10297ba2"]]},{"id":"af2f1c3d3ab3ccea","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"600","payloadType":"num","x":590,"y":2500,"wires":[["c6335dab10297ba2"]]},{"id":"d707d97320850531","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"88","payloadType":"num","x":590,"y":2540,"wires":[["c6335dab10297ba2"]]},{"id":"0e73504f05b83fe1","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{topic}}: Value at low stage {{payload}}","output":"str","x":820,"y":2280,"wires":[["2886ab01.99ebd4","282f48fec86a2064"]]},{"id":"935bee49935fc29e","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{topic}}: Value at high stage {{payload}}","output":"str","x":820,"y":2320,"wires":[["2886ab01.99ebd4","282f48fec86a2064"]]},{"id":"b894775069327319","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{topic}}: Status:OK {{payload}}","output":"str","x":820,"y":2360,"wires":[["2886ab01.99ebd4","282f48fec86a2064"]]},{"id":"2886ab01.99ebd4","type":"debug","z":"452103ea51141731","name":"","active":false,"console":"false","complete":"false","x":1050,"y":2380,"wires":[]},{"id":"282f48fec86a2064","type":"join","z":"452103ea51141731","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1030,"y":2320,"wires":[["aa11dc31892f3b98"]]},{"id":"aa11dc31892f3b98","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"1:{{payload.Agg1}}<br>\n2:{{payload.Agg2}}<br> ","output":"str","x":1180,"y":2320,"wires":[["608f6c08.c056e4"]]},{"id":"608f6c08.c056e4","type":"debug","z":"452103ea51141731","name":"","active":true,"console":"false","complete":"false","x":1350,"y":2320,"wires":[]}]
Actually, I am not using node-red. I am using mindsphere's api, visual flow creator where I can not download smooth node.
mindsphere have a community forum
To answer the question then you would have to implement the function of the smooth node in a function node.
[{"id":"91ed3404248ead63","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"600","payloadType":"num","x":610,"y":2140,"wires":[["3948c6524f476f07"]]},{"id":"3948c6524f476f07","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Agg1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":2280,"wires":[["0eb9731f3ac45f34"]]},{"id":"be942040732bbd1b","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"88","payloadType":"num","x":610,"y":2180,"wires":[["3948c6524f476f07"]]},{"id":"4a62b512e2b2df5d","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"200","payloadType":"num","x":610,"y":2220,"wires":[["3948c6524f476f07"]]},{"id":"0eb9731f3ac45f34","type":"function","z":"452103ea51141731","name":"function 16","func":"const average_count = 4;\nlet vals = context.get(\"average_array.\" + msg.topic) || [];\nvals.push(msg.payload)\nvals = vals.slice(-average_count);\nmsg.payload = vals.reduce((acc, str) => {\n let num = parseFloat(str);\n if(!isNaN(num)){\n acc+=num;\n }\n return acc;\n},0) / vals.length\ncontext.set(\"average_array.\" + msg.topic, vals)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":2340,"wires":[["b55467f3.7db4a8"]]},{"id":"c6335dab10297ba2","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Agg2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":2400,"wires":[["0eb9731f3ac45f34"]]},{"id":"b55467f3.7db4a8","type":"switch","z":"452103ea51141731","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"100","vt":"str"},{"t":"gt","v":"400","vt":"str"},{"t":"btwn","v":"101","vt":"num","v2":"399","v2t":"num"}],"checkall":"true","outputs":3,"x":670,"y":2340,"wires":[["0e73504f05b83fe1"],["935bee49935fc29e"],["b894775069327319"]]},{"id":"3e04b86e4866ba3c","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"300","payloadType":"num","x":590,"y":2460,"wires":[["c6335dab10297ba2"]]},{"id":"af2f1c3d3ab3ccea","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"600","payloadType":"num","x":590,"y":2500,"wires":[["c6335dab10297ba2"]]},{"id":"d707d97320850531","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"88","payloadType":"num","x":590,"y":2540,"wires":[["c6335dab10297ba2"]]},{"id":"0e73504f05b83fe1","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{topic}}: Value at low stage {{payload}}","output":"str","x":820,"y":2280,"wires":[["2886ab01.99ebd4","282f48fec86a2064"]]},{"id":"935bee49935fc29e","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{topic}}: Value at high stage {{payload}}","output":"str","x":820,"y":2320,"wires":[["2886ab01.99ebd4","282f48fec86a2064"]]},{"id":"b894775069327319","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{topic}}: Status:OK {{payload}}","output":"str","x":820,"y":2360,"wires":[["2886ab01.99ebd4","282f48fec86a2064"]]},{"id":"2886ab01.99ebd4","type":"debug","z":"452103ea51141731","name":"","active":false,"console":"false","complete":"false","x":1050,"y":2380,"wires":[]},{"id":"282f48fec86a2064","type":"join","z":"452103ea51141731","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1030,"y":2320,"wires":[["aa11dc31892f3b98"]]},{"id":"aa11dc31892f3b98","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"1:{{payload.Agg1}}<br>\n2:{{payload.Agg2}}<br> ","output":"str","x":1180,"y":2320,"wires":[["608f6c08.c056e4"]]},{"id":"608f6c08.c056e4","type":"debug","z":"452103ea51141731","name":"","active":true,"console":"false","complete":"false","x":1350,"y":2320,"wires":[]}]
const average_count = 4;
let vals = context.get("average_array." + msg.topic) || [];
vals.push(msg.payload)
vals = vals.slice(-average_count);
msg.payload = vals.reduce((acc, str) => {
let num = parseFloat(str);
if(!isNaN(num)){
acc+=num;
}
return acc;
},0) / vals.length
context.set("average_array." + msg.topic, vals)
return msg;
Thank you so much. I will try to deal with smooth node.
but wait Sorry, I think there is miscommunication. I am trying to do (a+b)/2 kind of thing.
I have tried something but there is some issue. It does not return any value.
[{"id":"bd83ce8.c13c63","type":"ui_button","z":"2349502c.99c05","name":"","group":"933bef30.6e133","order":0,"width":0,"singleBrowser":false,"height":0,"passthru":false,"label":"button_Average","color":"","bgcolor":"","icon":"","payload":"[65]","payloadType":"json","topic":"","powerMode":false,"x":160,"y":860,"wires":[["381866a2.57779a","4026ec1d.ffbf64"]]},{"id":"381866a2.57779a","type":"read timeseries","z":"2349502c.99c05","name":"Agg1_Current_Weight","topic":"1a655a707b4a445a98eb4f4e516b02a0/BatchMix_Current_Weight/Agg1_Current_Weight","topicLabel":"BatchMix/BatchMix_Current_Weight/Agg1_Current_Weight","topicData":"{\"asset\":\"1a655a707b4a445a98eb4f4e516b02a0\",\"assetName\":\"BatchMix\",\"aspects\":[{\"aspectId\":\"cde53ccd1ff84624af95951d5dc41188\",\"aspectName\":\"BatchMix_Current_Weight\",\"variables\":[{\"variableId\":\"te977db91a139c\",\"name\":\"Agg1_Current_Weight\"}]}]}","assetName":"","selectedTopics":"","period":"60","offset":"0","mode":"lastValue","from":"","datetimepickerFrom":"","to":"","datetimepickerTo":"","timezoneoffset":0,"x":380,"y":800,"wires":[["1e7ec413.c5e2bc"]]},{"id":"4026ec1d.ffbf64","type":"read timeseries","z":"2349502c.99c05","name":"Agg2_Current_Weight","topic":"1a655a707b4a445a98eb4f4e516b02a0/BatchMix_Current_Weight/Agg2_Current_Weight","topicLabel":"BatchMix/BatchMix_Current_Weight/Agg2_Current_Weight","topicData":"{\"asset\":\"1a655a707b4a445a98eb4f4e516b02a0\",\"assetName\":\"BatchMix\",\"aspects\":[{\"aspectId\":\"cde53ccd1ff84624af95951d5dc41188\",\"aspectName\":\"BatchMix_Current_Weight\",\"variables\":[{\"variableId\":\"tf977db91a139d\",\"name\":\"Agg2_Current_Weight\"}]}]}","assetName":"","selectedTopics":"","period":"60","offset":"0","mode":"lastValue","from":"","datetimepickerFrom":"","to":"","datetimepickerTo":"","timezoneoffset":0,"x":380,"y":920,"wires":[["76a15ec5.0ad2d"]]},{"id":"1e7ec413.c5e2bc","type":"extract parameter","z":"2349502c.99c05","name":"Agg1_Current_Weight","topic":"1a655a707b4a445a98eb4f4e516b02a0/BatchMix_Current_Weight/Agg1_Current_Weight","topicData":"{\"asset\":\"1a655a707b4a445a98eb4f4e516b02a0\",\"assetName\":\"BatchMix\",\"aspect\":\"cde53ccd1ff84624af95951d5dc41188\",\"aspectName\":\"BatchMix_Current_Weight\",\"variable\":\"te977db91a139c\",\"variableName\":\"Agg1_Current_Weight\"}","parameter":"Agg1_Current_Weight","x":620,"y":800,"wires":[["1d93d5ed.92f58a"]]},{"id":"76a15ec5.0ad2d","type":"extract parameter","z":"2349502c.99c05","name":"Agg2_Current_Weight","topic":"1a655a707b4a445a98eb4f4e516b02a0/BatchMix_Current_Weight/Agg2_Current_Weight","topicData":"{\"asset\":\"1a655a707b4a445a98eb4f4e516b02a0\",\"assetName\":\"BatchMix\",\"aspect\":\"cde53ccd1ff84624af95951d5dc41188\",\"aspectName\":\"BatchMix_Current_Weight\",\"variable\":\"tf977db91a139d\",\"variableName\":\"Agg2_Current_Weight\"}","parameter":"Agg2_Current_Weight","x":620,"y":920,"wires":[["a9f2abc.c32c658"]]},{"id":"1d93d5ed.92f58a","type":"change","z":"2349502c.99c05","name":"set topic to agg1","rules":[{"t":"set","p":"topic","pt":"msg","to":"task1","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":800,"wires":[["5fc5654e.601e1c","62707696.611158"]],"_type":"node"},{"id":"a9f2abc.c32c658","type":"change","z":"2349502c.99c05","name":"set topic to agg2","rules":[{"t":"set","p":"topic","pt":"msg","to":"task2","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":920,"wires":[["1694954b.2bbbab","62707696.611158"]],"_type":"node"},{"id":"5fc5654e.601e1c","type":"debug","z":"2349502c.99c05","name":"","active":true,"console":"false","xaxis":"","complete":"payload","x":1030,"y":760,"wires":[]},{"id":"62707696.611158","type":"function","z":"2349502c.99c05","name":"","func":"context.data= context.data ||{};\nswitch(msg.topic){\n case \"task1\":\n context.data.task1 = msg.payload;\n msg=null;\n break;\n case \"task2\":\n context.data.task2 = msg.payload;\n msg=null;\n break;\n default:\n msg=null;\n break;\n}\n\nif(context.data.task1 !=null && context.data.task2 !=null){\n var Avg=(context.data.task1/context.data.task2)/2;\n context.data=null;\n return{payload:ratio};\n}else return msg;\n","outputs":1,"language":"javascript","noerr":0,"x":1020,"y":860,"wires":[["d8d7a10a.262fb","e4af3fa8.055d1"]],"_type":"node"},{"id":"1694954b.2bbbab","type":"debug","z":"2349502c.99c05","name":"","active":true,"console":"false","xaxis":"","complete":"payload","x":1030,"y":980,"wires":[]},{"id":"e4af3fa8.055d1","type":"ui_text","z":"2349502c.99c05","group":"933bef30.6e133","order":0,"width":0,"singleBrowser":false,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":1210,"y":900,"wires":[],"_type":"node"},{"id":"d8d7a10a.262fb","type":"debug","z":"2349502c.99c05","name":"","active":true,"console":"false","xaxis":"","complete":"payload","x":1233.890625,"y":842.97265625,"wires":[],"_type":"node"},{"id":"933bef30.6e133","type":"ui_group","z":"","name":"Summation","tab":"71bf6668.e36f88","order":2,"disp":true,"width":"6","collapse":false,"_type":"config"},{"id":"71bf6668.e36f88","type":"ui_tab","z":"","name":"PLANT1","icon":"dashboard","order":3,"publicAccess":"true","fmAccess":"default","fmAccessType":"public","assetType":"","asset":"","assetName":"","assetText":"","image":"","description":"","hideTitleBar":false,"_type":"config"}]
you originally said average over 4 ... now you say 2... sorry - mind reading is not one our key skills . In E1cid's example change the 4 to a 2...
If there has been miscommunication, then you need to explain your issue more clearly, I asked if you wanted to average the incoming Agg's in a previous post, you did not reply no.
Just incase you want to average of Agg1 + Agg2, this example shows how. The templates now output objects not strings.
[{"id":"91ed3404248ead63","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"600","payloadType":"num","x":610,"y":2140,"wires":[["3948c6524f476f07"]]},{"id":"3948c6524f476f07","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Agg1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":2280,"wires":[["b55467f3.7db4a8"]]},{"id":"be942040732bbd1b","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"88","payloadType":"num","x":610,"y":2180,"wires":[["3948c6524f476f07"]]},{"id":"4a62b512e2b2df5d","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"200","payloadType":"num","x":610,"y":2220,"wires":[["3948c6524f476f07"]]},{"id":"b55467f3.7db4a8","type":"switch","z":"452103ea51141731","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"100","vt":"str"},{"t":"gt","v":"400","vt":"str"},{"t":"btwn","v":"101","vt":"num","v2":"399","v2t":"num"}],"checkall":"true","outputs":3,"x":670,"y":2340,"wires":[["0e73504f05b83fe1"],["935bee49935fc29e"],["b894775069327319"]]},{"id":"c6335dab10297ba2","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Agg2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":2400,"wires":[["b55467f3.7db4a8"]]},{"id":"0e73504f05b83fe1","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n \"string\": \"{{topic}}: Value at low stage {{payload}}\",\n \"value\": {{payload}}\n}","output":"json","x":820,"y":2280,"wires":[["2886ab01.99ebd4","282f48fec86a2064"]]},{"id":"935bee49935fc29e","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n \"string\": \"{{topic}}: Value at high stage {{payload}}\",\n \"value\": {{payload}}\n}","output":"json","x":820,"y":2320,"wires":[["2886ab01.99ebd4","282f48fec86a2064"]]},{"id":"b894775069327319","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n \"string\": \"{{topic}}: Status:OK {{payload}}\",\n \"value\": {{payload}}\n}","output":"json","x":820,"y":2360,"wires":[["2886ab01.99ebd4","282f48fec86a2064"]]},{"id":"3e04b86e4866ba3c","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"300","payloadType":"num","x":590,"y":2460,"wires":[["c6335dab10297ba2"]]},{"id":"af2f1c3d3ab3ccea","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"600","payloadType":"num","x":590,"y":2500,"wires":[["c6335dab10297ba2"]]},{"id":"d707d97320850531","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"88","payloadType":"num","x":590,"y":2540,"wires":[["c6335dab10297ba2"]]},{"id":"2886ab01.99ebd4","type":"debug","z":"452103ea51141731","name":"","active":false,"console":"false","complete":"false","x":1050,"y":2380,"wires":[]},{"id":"282f48fec86a2064","type":"join","z":"452103ea51141731","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1030,"y":2320,"wires":[["608f6c08.c056e4","196bd4e711ea2aeb"]]},{"id":"608f6c08.c056e4","type":"debug","z":"452103ea51141731","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":790,"y":2540,"wires":[]},{"id":"196bd4e711ea2aeb","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload.average","pt":"msg","to":"$average($$.payload.*.value)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1110,"y":2260,"wires":[["aa11dc31892f3b98"]]},{"id":"aa11dc31892f3b98","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"1:{{payload.Agg1.string}}<br>\n2:{{payload.Agg2.string}}<br> \nAverage: {{payload.average}}","output":"str","x":1180,"y":2320,"wires":[["608f6c08.c056e4"]]}]
I apologize for the inconvenience caused and thank you for the help!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.