Hello everyone,
I got this script with some help of @E1cid and now i would like to call some of the object values later in that same node. Is that possible ?
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("$5600006601/")) {
acc["L" + (obj.phaseId + 1) + "auto"] = obj.power;
acc.auto += obj.power;
} else if (obj.formula.includes("$5600006973/")) {
acc["L" + (obj.phaseId + 1) + "PV"] = obj.power;
acc.PV += obj.power;
} else if (obj.formula.includes("$5600006667/")) {
acc["L" + (obj.phaseId + 1) + "Stopcontacten"] = obj.power;
acc.Stopcontacten += obj.power;
}
return acc
}, { net: 0, auto: 0, PV: 0, Stopcontacten: 0 });
return msg;
[{"id":"cf0f39de322a6ea0","type":"mqtt in","z":"76de9c78a268111d","name":"Real-time energy data (1-second data)","topic":"servicelocation/e734acdc-a528-40ba-8f5c-4f21780b5d46/realtime","qos":"1","datatype":"json","broker":"2197f44a.ad9f2c","nl":false,"rap":true,"rh":0,"inputs":0,"x":170,"y":380,"wires":[["678afc1b0857ce6c","0d56ecda3b488ad6"]]},{"id":"678afc1b0857ce6c","type":"function","z":"76de9c78a268111d","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(\"$5600006601/\")){\nacc[\"L\" + (obj.phaseId+1) + \"auto\"] = obj.power;\nacc.auto += obj.power;\n}else if (obj.formula.includes(\"$5600006973/\")){\nacc[\"L\" + (obj.phaseId+1) + \"PV\"] = obj.power;\nacc.PV += obj.power;\n}else if (obj.formula.includes(\"$5600006667/\")){\nacc[\"L\" + (obj.phaseId+1) + \"Stopcontacten\"] = obj.power;\nacc.Stopcontacten += obj.power;\n}\nreturn acc\n},{net:0,auto:0,PV:0,Stopcontacten:0});\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":380,"wires":[["7d3fd77334f951d9","33b5474b13bbb037"]]},{"id":"26e7ddf548c4f606","type":"comment","z":"76de9c78a268111d","name":"Visualisatie","info":"Dit gedeelte geeft de visualisatie weer van de vermogens op het dashboard","x":90,"y":340,"wires":[]},{"id":"33b5474b13bbb037","type":"debug","z":"76de9c78a268111d","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":420,"wires":[]},{"id":"0d56ecda3b488ad6","type":"debug","z":"76de9c78a268111d","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":410,"y":420,"wires":[]},{"id":"2197f44a.ad9f2c","type":"mqtt-broker","name":"","broker":"192.168.0.249","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]
thanks Olivia