Move all payloads of a topic

I have more topics with many payloads and the same structure. Is there a smart possibility to move all payloads "yxz" to "grid_xyz" at a glance without moving all them one by one?

[{"id":"6ea593bfad2ff52c","type":"inject","z":"be6250d9d9f84ee4","name":"Grid M4","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"cfos_mqtt/get/M4","payload":"{\"dev_type\":\"meter_sunspec\",\"device_enabled\":1,\"name\":\"SE Grid-meter\",\"time\":1736096274,\"address\":\"192.168.178.46:1502\",\"id\":1,\"dev_id\":\"M4\",\"number\":34,\"desc\":\"SolarEdge Netzzähler\",\"com_err\":false,\"com_err_secs\":936,\"com_errors\":0,\"status\":\"\",\"last_error\":\"not connected: 192.168.178.46:1502\",\"is_evse\":false,\"used_phases\":7,\"has_history\":true,\"hide_dev\":false,\"show_in_overview\":true,\"show_chart_in_dev_info\":false,\"show_chart_in_overview\":true,\"user_info\":{\"imb_avg\":0.7,\"imbalance\":0.7},\"factor\":1,\"import\":850315,\"export\":6094494,\"power_w\":234,\"current_l1\":424,\"current_l2\":1037,\"current_l3\":322,\"voltage_l1\":233,\"voltage_l2\":236,\"voltage_l3\":234,\"role\":3,\"model\":\"SolarEdge ,SE10K-RWS48BEN4,0004.0022.0039,1.0,7E1FA837,M203\"}","payloadType":"json","x":130,"y":700,"wires":[["6316fcb2bf52e739"]]},{"id":"e7f18b2b9ac1eab9","type":"debug","z":"be6250d9d9f84ee4","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":700,"wires":[]},{"id":"6316fcb2bf52e739","type":"change","z":"be6250d9d9f84ee4","name":"","rules":[{"t":"move","p":"payload.name","pt":"msg","to":"payload.grid_name","tot":"msg"},{"t":"move","p":"payload.time","pt":"msg","to":"payload.grid_time","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":700,"wires":[["e7f18b2b9ac1eab9"]],"info":"delete status as it is already in \none of the other incoming objects"}]

it is possible (using a function or JSONata) however before you go down that path, the question is "why"?

Your payload property names are (currently) sensible as they are, renaming everything the grid_x, grid_y seems like you are trying to arrange the data for some later use (like database insertion?) that may ultimately not be necessary. Perhaps if you give a brief outline of the overall goal, we might save you some future headache?

1 Like

Why:
I've just learned that, if I have duplicate Payload from 2 sources, I have to rename one of them.
Now I have 3 topics with almost identically Payload sets from 3 sources and must distinguish between them to handle the data proper.
The aim is to report and analyze the behaviour of my photovoltaic(PV) system, consisting of PV inverter, home battery and grid power meter.
First goal is to get all power_w data into one line of a csv data file.
My 1st setup is about this:
[edit] replaced setup

[{"id":"a5ae1c7bb459851c","type":"change","z":"be6250d9d9f84ee4","name":"","rules":[{"t":"set","p":"payload.timestamp","pt":"msg","to":"$now(\"[Y]-[M01]-[D01]T[H01]:[m01]:[s01]Z\",\"00:00\")\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":240,"wires":[["dc993c60f1eb6ab3"]]},{"id":"dc993c60f1eb6ab3","type":"join","z":"be6250d9d9f84ee4","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"key","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":true,"timeout":"","count":"38","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":900,"y":240,"wires":[["3d5fc1d4ccfc46a3"]]},{"id":"d5497fcf612ab727","type":"join","z":"be6250d9d9f84ee4","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":"false","timeout":"","count":"","reduceRight":false,"x":750,"y":380,"wires":[["a5ae1c7bb459851c"]]},{"id":"bf6b24ecd00aed61","type":"switch","z":"be6250d9d9f84ee4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"number","vt":"number"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":550,"y":440,"wires":[["bffbd6af2675bdde"],["d5497fcf612ab727"]]},{"id":"c8cf7de8debbece8","type":"change","z":"be6250d9d9f84ee4","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":".","fromt":"str","to":",","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":440,"wires":[["d5497fcf612ab727"]]},{"id":"3d5fc1d4ccfc46a3","type":"csv","z":"be6250d9d9f84ee4","name":"","spec":"rfc","sep":";","hdrin":true,"hdrout":"none","multi":"one","ret":"\\n","temp":"timestamp,dev_id,name,power_w,bat_power_w,grid_power_w","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":1050,"y":240,"wires":[["72cac457d26e2a85","9c666c8358613241"]]},{"id":"014cafb59b0e9afa","type":"split","z":"be6250d9d9f84ee4","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"key","property":"payload","x":510,"y":380,"wires":[["bf6b24ecd00aed61"]]},{"id":"bffbd6af2675bdde","type":"template","z":"be6250d9d9f84ee4","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload}}","output":"str","x":720,"y":440,"wires":[["c8cf7de8debbece8"]]},{"id":"72cac457d26e2a85","type":"debug","z":"be6250d9d9f84ee4","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1240,"y":240,"wires":[]},{"id":"51e79f1521bd1896","type":"inject","z":"be6250d9d9f84ee4","name":"Haus Batterie M6","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"cfos_mqtt/get/M6","payload":"{\"dev_type\":\"meter_LG_Battery\",\"device_enabled\":1,\"name\":\"Haus-Batterie\",\"time\":1736096203,\"address\":\"192.168.178.46:1502\",\"id\":1,\"dev_id\":\"M6\",\"number\":26,\"desc\":\"LG RESU12 Batterie\",\"com_err\":false,\"com_err_secs\":1016,\"com_errors\":1,\"status\":\"\",\"last_error\":\"no response\",\"is_evse\":false,\"used_phases\":7,\"has_history\":true,\"hide_dev\":false,\"show_in_overview\":true,\"show_chart_in_dev_info\":false,\"show_chart_in_overview\":true,\"factor\":1,\"import\":1170,\"export\":0,\"power_w\":0,\"current_l1\":0,\"current_l2\":0,\"current_l3\":0,\"voltage_l1\":230,\"voltage_l2\":230,\"voltage_l3\":230,\"role\":5,\"model\":\"LG,LGC RESU 12,1.0,48V DCDC 2.2.157,7E1FA837\",\"soc\":10}","payloadType":"json","x":160,"y":580,"wires":[["064932f136f73d56"]]},{"id":"6ea593bfad2ff52c","type":"inject","z":"be6250d9d9f84ee4","name":"Grid M4","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"cfos_mqtt/get/M4","payload":"{\"dev_type\":\"meter_sunspec\",\"device_enabled\":1,\"name\":\"SE Grid-meter\",\"time\":1736171884,\"address\":\"192.168.178.46:1502\",\"id\":1,\"dev_id\":\"M4\",\"number\":34,\"desc\":\"SolarEdge Netzzähler\",\"com_err\":false,\"com_err_secs\":38738,\"com_errors\":27,\"status\":\"\",\"last_error\":\"not connected: 192.168.178.46:1502\",\"is_evse\":false,\"used_phases\":7,\"has_history\":true,\"hide_dev\":false,\"show_in_overview\":true,\"show_chart_in_dev_info\":false,\"show_chart_in_overview\":true,\"user_info\":{\"imb_avg\":1,\"imbalance\":1.2},\"factor\":1,\"import\":854207,\"export\":6094578,\"power_w\":-1,\"current_l1\":-450,\"current_l2\":752,\"current_l3\":354,\"voltage_l1\":235,\"voltage_l2\":240,\"voltage_l3\":232,\"role\":3,\"model\":\"SolarEdge ,SE10K-RWS48BEN4,0004.0022.0039,1.0,7E1FA837,M203\"}","payloadType":"json","x":130,"y":700,"wires":[["5a6908a2c4f822d1"]]},{"id":"0ae9375138025049","type":"inject","z":"be6250d9d9f84ee4","name":"WR M5","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"cfos_mqtt/get/E1","payload":"{\"dev_type\":\"meter_SE10K-RWS+Bat_rUIP(ac)\",\"device_enabled\":1,\"name\":\"SolarEdge Wechselrichter\",\"time\":1736171571,\"address\":\"192.168.178.46:1502\",\"id\":1,\"dev_id\":\"M5\",\"number\":5,\"desc\":\"SolarEdge Wechselrichter\",\"com_err\":false,\"com_err_secs\":38426,\"com_errors\":28,\"status\":\"\",\"last_error\":\"not connected: 192.168.178.46:1502\",\"is_evse\":false,\"used_phases\":7,\"has_history\":true,\"hide_dev\":false,\"show_in_overview\":true,\"show_chart_in_dev_info\":false,\"show_chart_in_overview\":true,\"factor\":1,\"import\":8667462,\"export\":0,\"power_w\":277,\"current_l1\":513,\"current_l2\":523,\"current_l3\":533,\"voltage_l1\":234,\"voltage_l2\":239,\"voltage_l3\":236,\"role\":2,\"model\":\"Solaredge,SE10K-RWS48BEN4,0004.0022.0039,n.v.,7E1FA837\"}","payloadType":"json","x":130,"y":300,"wires":[["014cafb59b0e9afa"]]},{"id":"5a6908a2c4f822d1","type":"change","z":"be6250d9d9f84ee4","name":"","rules":[{"t":"move","p":"payload.power_w","pt":"msg","to":"payload.grid_power_w","tot":"msg"},{"t":"move","p":"payload.time","pt":"msg","to":"payload.grid_time","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":700,"wires":[["014cafb59b0e9afa"]],"info":"delete status as it is already in \none of the other incoming objects"},{"id":"064932f136f73d56","type":"change","z":"be6250d9d9f84ee4","name":"","rules":[{"t":"move","p":"payload.power_w","pt":"msg","to":"payload.bat_power_w","tot":"msg"},{"t":"move","p":"payload.time","pt":"msg","to":"payload.bat_time","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":580,"wires":[["014cafb59b0e9afa"]],"info":"delete status as it is already in \none of the other incoming objects"}]

This could also be done with a low code recursive flow.
e.g.

[{"id":"6ea593bfad2ff52c","type":"inject","z":"667cec54c048503c","name":"Grid M4","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"cfos_mqtt/get/M4","payload":"{\"dev_type\":\"meter_sunspec\",\"device_enabled\":1,\"name\":\"SE Grid-meter\",\"time\":1736096274,\"address\":\"192.168.178.46:1502\",\"id\":1,\"dev_id\":\"M4\",\"number\":34,\"desc\":\"SolarEdge Netzzähler\",\"com_err\":false,\"com_err_secs\":936,\"com_errors\":0,\"status\":\"\",\"last_error\":\"not connected: 192.168.178.46:1502\",\"is_evse\":false,\"used_phases\":7,\"has_history\":true,\"hide_dev\":false,\"show_in_overview\":true,\"show_chart_in_dev_info\":false,\"show_chart_in_overview\":true,\"info\":{\"check\":{\"check1\":{\"imb_avg\":0.7,\"imbalance\":0.7},\"imb_avg\":0.7,\"imbalance\":0.7},\"imb_avg\":0.7,\"imbalance\":0.7},\"factor\":1,\"import\":850315,\"export\":6094494,\"power_w\":234,\"current_l1\":424,\"current_l2\":1037,\"current_l3\":322,\"voltage_l1\":233,\"voltage_l2\":236,\"voltage_l3\":234,\"role\":3,\"model\":\"SolarEdge ,SE10K-RWS48BEN4,0004.0022.0039,1.0,7E1FA837,M203\"}","payloadType":"json","x":130,"y":760,"wires":[["d66deb0ef7c12f3f"]]},{"id":"d66deb0ef7c12f3f","type":"split","z":"667cec54c048503c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"key","property":"payload","x":270,"y":760,"wires":[["0e6c1c18a3c673a4","b22cdd9842cab55b"]]},{"id":"d5b391448727048a","type":"template","z":"667cec54c048503c","name":"","field":"key_rec","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{key}}_","output":"str","x":700,"y":760,"wires":[["d66deb0ef7c12f3f"]]},{"id":"0e6c1c18a3c673a4","type":"trigger","z":"667cec54c048503c","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"250","extend":true,"overrideDelay":true,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":320,"y":840,"wires":[["769fb55f5e39c1da"]]},{"id":"b22cdd9842cab55b","type":"template","z":"667cec54c048503c","name":"","field":"key","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{key_rec}}{{key}}","output":"str","x":420,"y":760,"wires":[["8a6adf387967742c"]]},{"id":"8a6adf387967742c","type":"switch","z":"667cec54c048503c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"object","vt":"object"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":550,"y":760,"wires":[["d5b391448727048a"],["8998d32448af64fa"]]},{"id":"769fb55f5e39c1da","type":"change","z":"667cec54c048503c","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"complete","tot":"msg"},{"t":"delete","p":"key","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":840,"wires":[["1e0cddd5132fb125"]]},{"id":"8998d32448af64fa","type":"template","z":"667cec54c048503c","name":"","field":"key","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"grid_{{key}}","output":"str","x":700,"y":820,"wires":[["1e0cddd5132fb125"]]},{"id":"1e0cddd5132fb125","type":"join","z":"667cec54c048503c","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"key","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":830,"y":840,"wires":[["e7f18b2b9ac1eab9"]]},{"id":"e7f18b2b9ac1eab9","type":"debug","z":"667cec54c048503c","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":900,"y":800,"wires":[]}]

Which may be easier for you follow the logic of how it flattens the multi layered object. Else you would have to write a recursive function or JSONata expression.

{which you can call from a link call and a queue.
e.g.

[{"id":"51bad935a25a72d0","type":"delay","z":"667cec54c048503c","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"10","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":280,"y":800,"wires":[["d66deb0ef7c12f3f"]]},{"id":"1854c596b468501c","type":"link in","z":"667cec54c048503c","name":"flatten_object","links":[],"x":145,"y":800,"wires":[["51bad935a25a72d0"]]},{"id":"a9a0c6e9a19f8e0f","type":"function","z":"667cec54c048503c","name":"function 157","func":"return {flush:1}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":130,"y":900,"wires":[["51bad935a25a72d0"]]},{"id":"d66deb0ef7c12f3f","type":"split","z":"667cec54c048503c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"key","property":"payload","x":440,"y":820,"wires":[["0e6c1c18a3c673a4","b22cdd9842cab55b"]]},{"id":"1e0cddd5132fb125","type":"join","z":"667cec54c048503c","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"key","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1000,"y":900,"wires":[["2223455d1663255d","a9a0c6e9a19f8e0f"]]},{"id":"d5b391448727048a","type":"template","z":"667cec54c048503c","name":"","field":"key_rec","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{key}}_","output":"str","x":870,"y":820,"wires":[["d66deb0ef7c12f3f"]]},{"id":"0e6c1c18a3c673a4","type":"trigger","z":"667cec54c048503c","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"250","extend":true,"overrideDelay":true,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":490,"y":900,"wires":[["769fb55f5e39c1da"]]},{"id":"b22cdd9842cab55b","type":"template","z":"667cec54c048503c","name":"","field":"key","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{key_rec}}{{key}}","output":"str","x":590,"y":820,"wires":[["8a6adf387967742c"]]},{"id":"769fb55f5e39c1da","type":"change","z":"667cec54c048503c","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"complete","tot":"msg"},{"t":"delete","p":"key","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":900,"wires":[["1e0cddd5132fb125"]]},{"id":"8998d32448af64fa","type":"template","z":"667cec54c048503c","name":"","field":"key","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{pre}}{{key}}","output":"str","x":870,"y":880,"wires":[["1e0cddd5132fb125"]]},{"id":"2223455d1663255d","type":"link out","z":"667cec54c048503c","name":"link out 10","mode":"return","links":[],"x":1015,"y":820,"wires":[]},{"id":"8a6adf387967742c","type":"switch","z":"667cec54c048503c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"object","vt":"object"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":720,"y":820,"wires":[["d5b391448727048a"],["8998d32448af64fa"]]},{"id":"6ea593bfad2ff52c","type":"inject","z":"667cec54c048503c","name":"Grid M4","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"cfos_mqtt/get/M4","payload":"{\"dev_type\":\"meter_sunspec\",\"device_enabled\":1,\"name\":\"SE Grid-meter\",\"time\":1736096274,\"address\":\"192.168.178.46:1502\",\"id\":1,\"dev_id\":\"M4\",\"number\":34,\"desc\":\"SolarEdge Netzzähler\",\"com_err\":false,\"com_err_secs\":936,\"com_errors\":0,\"status\":\"\",\"last_error\":\"not connected: 192.168.178.46:1502\",\"is_evse\":false,\"used_phases\":7,\"has_history\":true,\"hide_dev\":false,\"show_in_overview\":true,\"show_chart_in_dev_info\":false,\"show_chart_in_overview\":true,\"info\":{\"check\":{\"check1\":{\"imb_avg\":0.7,\"imbalance\":0.7},\"imb_avg\":0.7,\"imbalance\":0.7},\"imb_avg\":0.7,\"imbalance\":0.7},\"factor\":1,\"import\":850315,\"export\":6094494,\"power_w\":234,\"current_l1\":424,\"current_l2\":1037,\"current_l3\":322,\"voltage_l1\":233,\"voltage_l2\":236,\"voltage_l3\":234,\"role\":3,\"model\":\"SolarEdge ,SE10K-RWS48BEN4,0004.0022.0039,1.0,7E1FA837,M203\"}","payloadType":"json","x":340,"y":1020,"wires":[["0bb4e51c1cf0f412"]]},{"id":"0bb4e51c1cf0f412","type":"change","z":"667cec54c048503c","name":"","rules":[{"t":"set","p":"pre","pt":"msg","to":"grid_","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":1020,"wires":[["e2da7daa5772614c"]]},{"id":"e2da7daa5772614c","type":"link call","z":"667cec54c048503c","name":"","links":["1854c596b468501c"],"linkType":"static","timeout":"30","x":750,"y":1020,"wires":[["e7f18b2b9ac1eab9"]]},{"id":"e7f18b2b9ac1eab9","type":"debug","z":"667cec54c048503c","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":1020,"wires":[]}]

Thank you, this helps