Plotting values from obj

Hello everyone,

@E1cid helped me with a script to make a list of the values that he automaticly searched from a bigger array.
Now I would like to get the values appart from eatch other to plot them in a graph... can someone help me ?

msg.payload = msg.payload.channelPowers.reduce((acc, obj) => {
if(obj.formula.includes("$5600004355/")){
acc["L" + (obj.phaseId+1) + "net"] = obj.power;
acc.net += obj.power;
}else if (obj.formula.includes("$5600004035/")){
acc["L" + (obj.phaseId+1) + "auto"] = obj.power;
acc.auto += obj.power;
}
return acc
},{net:0,auto:0});
return msg;

This is the input array

{"totalPower":10,"totalReactivePower":11,"totalExportEnergy":226800,"totalImportEnergy":100519200,"monitorStatus":0,"utcTimeStamp":1651219140000,"measuredFrequency":50000236,"channelPowers":[{"publishIndex":0,"formula":"$5600004355/2$","power":9,"exportEnergy":32400,"importEnergy":34160400,"phaseId":0,"current":1,"apparentPower":15,"cosPhi":61},{"publishIndex":1,"formula":"$5600004355/1$","power":0,"exportEnergy":0,"importEnergy":10062000,"phaseId":1,"current":0,"apparentPower":0,"cosPhi":42},{"publishIndex":2,"formula":"$5600004355/0$","power":0,"exportEnergy":0,"importEnergy":9043200,"phaseId":2,"current":0,"apparentPower":1,"cosPhi":40},{"publishIndex":3,"formula":"$5500027192/0$","power":0,"exportEnergy":194400,"importEnergy":0,"phaseId":0,"current":0,"apparentPower":0,"cosPhi":22},{"publishIndex":4,"formula":"$5500027192/1$","power":0,"exportEnergy":0,"importEnergy":0,"phaseId":1,"current":0,"apparentPower":0,"cosPhi":-16},{"publishIndex":5,"formula":"$5600004035/0$","power":4,"exportEnergy":0,"importEnergy":29091600,"phaseId":0,"current":0,"apparentPower":9,"cosPhi":43},{"publishIndex":6,"formula":"$5600004035/1$","power":0,"exportEnergy":0,"importEnergy":9133200,"phaseId":1,"current":0,"apparentPower":0,"cosPhi":43},{"publishIndex":7,"formula":"$5600004035/2$","power":0,"exportEnergy":0,"importEnergy":9028800,"phaseId":2,"current":0,"apparentPower":1,"cosPhi":39}],"voltages":[{"voltage":238,"phaseId":0},{"voltage":239,"phaseId":1},{"voltage":241,"phaseId":2}]}

it should look like this...

image

Here you go Olivia,
you can add or remove any values you wish to plot in the change node, you can also rename them to the topic values for each series.

[{"id":"425181e1.f0af8","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"totalPower\":10,\"totalReactivePower\":11,\"totalExportEnergy\":226800,\"totalImportEnergy\":100519200,\"monitorStatus\":0,\"utcTimeStamp\":1651219140000,\"measuredFrequency\":50000236,\"channelPowers\":[{\"publishIndex\":0,\"formula\":\"$5600004355/2$\",\"power\":9,\"exportEnergy\":32400,\"importEnergy\":34160400,\"phaseId\":0,\"current\":1,\"apparentPower\":15,\"cosPhi\":61},{\"publishIndex\":1,\"formula\":\"$5600004355/1$\",\"power\":0,\"exportEnergy\":0,\"importEnergy\":10062000,\"phaseId\":1,\"current\":0,\"apparentPower\":0,\"cosPhi\":42},{\"publishIndex\":2,\"formula\":\"$5600004355/0$\",\"power\":0,\"exportEnergy\":0,\"importEnergy\":9043200,\"phaseId\":2,\"current\":0,\"apparentPower\":1,\"cosPhi\":40},{\"publishIndex\":3,\"formula\":\"$5500027192/0$\",\"power\":0,\"exportEnergy\":194400,\"importEnergy\":0,\"phaseId\":0,\"current\":0,\"apparentPower\":0,\"cosPhi\":22},{\"publishIndex\":4,\"formula\":\"$5500027192/1$\",\"power\":0,\"exportEnergy\":0,\"importEnergy\":0,\"phaseId\":1,\"current\":0,\"apparentPower\":0,\"cosPhi\":-16},{\"publishIndex\":5,\"formula\":\"$5600004035/0$\",\"power\":4,\"exportEnergy\":0,\"importEnergy\":29091600,\"phaseId\":0,\"current\":0,\"apparentPower\":9,\"cosPhi\":43},{\"publishIndex\":6,\"formula\":\"$5600004035/1$\",\"power\":0,\"exportEnergy\":0,\"importEnergy\":9133200,\"phaseId\":1,\"current\":0,\"apparentPower\":0,\"cosPhi\":43},{\"publishIndex\":7,\"formula\":\"$5600004035/2$\",\"power\":0,\"exportEnergy\":0,\"importEnergy\":9028800,\"phaseId\":2,\"current\":0,\"apparentPower\":1,\"cosPhi\":39}],\"voltages\":[{\"voltage\":238,\"phaseId\":0},{\"voltage\":239,\"phaseId\":1},{\"voltage\":241,\"phaseId\":2}]}","payloadType":"json","x":120,"y":860,"wires":[["a3dcafa1.650768"]]},{"id":"a3dcafa1.650768","type":"function","z":"bf9e1e33.030598","name":"","func":"msg.payload = msg.payload.channelPowers.reduce((acc, obj) => {\nif(obj.formula.includes(\"$5600004355/\")){\nacc[\"L\" + (obj.phaseId+1) + \"net\"] = obj.power;\nacc.net += obj.power;\n}else if (obj.formula.includes(\"$5600004035/\")){\nacc[\"L\" + (obj.phaseId+1) + \"auto\"] = obj.power;\nacc.auto += obj.power;\n}\nreturn acc\n},{net:0,auto:0});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":270,"y":860,"wires":[["449b8784.a35e88"]]},{"id":"449b8784.a35e88","type":"change","z":"bf9e1e33.030598","name":"select values to send","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t   \"total Auto\": $$.payload.auto,\t   \"total Net\": $$.payload.net\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":220,"y":920,"wires":[["92d4872a.79ded8"]]},{"id":"92d4872a.79ded8","type":"split","z":"bf9e1e33.030598","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":430,"y":920,"wires":[["854734c8.9d13a","5035082b.e7dbe8"]]},{"id":"854734c8.9d13a","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":820,"wires":[]},{"id":"5035082b.e7dbe8","type":"ui_chart","z":"bf9e1e33.030598","name":"","group":"8b5cde76.edd58","order":2,"width":0,"height":0,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#d73920","#ffcb13","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":590,"y":920,"wires":[[]]},{"id":"37a1df10.89c0d8","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[]","payloadType":"json","x":450,"y":1000,"wires":[["5035082b.e7dbe8"]]},{"id":"8b5cde76.edd58","type":"ui_group","name":"default","tab":"8f03e639.85956","order":1,"disp":false,"width":"12","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","order":2,"disabled":false,"hidden":false}]
1 Like

Thanks @E1cid !

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