Multiple payloads

Hi
How to retrieve the index value of each of the 10 tariffs?

Use a join node set to manual, key/object, count 10 and use msg.tariff as the key. Or use msg.tariff before the join to create a better key.

P.s. I do not like to be taken to third party websites where i need to allow cookies to see an image, when the forum has an upload and paste feature. Which means the images will be viewable until node-red forum no longer exists.

Thank you for this return. With Join I get this error message

Can you paste an example of one msg.payload in text format please.

I'm not sure I understand !

Message missing key property 'msg.tariff' - cannot add to object

One of the 10 incoming payloads before the join.

{"activeElectricalEnergy":58816740,"tariff":5,"validityTariff":false,"validityEnergy":false}

Yes tariff is a number so you will have to create a topic with the tariff and convert it to a string . Check my head, had wrong path. Example works though
e.g.

[{"id":"f380392f0e2e8551","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"activeElectricalEnergy\":58816740,\"tariff\":1,\"validityTariff\":false,\"validityEnergy\":false}","payloadType":"json","x":290,"y":4260,"wires":[["4e438d4b0bb4d30e"]]},{"id":"4e438d4b0bb4d30e","type":"change","z":"65617ffeb779f51c","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"\"tariff\" & $string($$.payload.tariff)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":4360,"wires":[["bbd8489957e9fb7f"]]},{"id":"b9dce646469eeb75","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"activeElectricalEnergy\":58816740,\"tariff\":2,\"validityTariff\":false,\"validityEnergy\":false}","payloadType":"json","x":290,"y":4320,"wires":[["4e438d4b0bb4d30e"]]},{"id":"bbd8489957e9fb7f","type":"join","z":"65617ffeb779f51c","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":550,"y":4300,"wires":[["c93d0f62a19a0380"]]},{"id":"c93d0f62a19a0380","type":"debug","z":"65617ffeb779f51c","name":"debug 250","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":4240,"wires":[]}]

How to import a flow

It should be msg.payload.tariff. I don't know whether the fact that it is a number also matters.

1 Like

How to get an output by tariff that contains the index (activeElectricalEnergy)

Use the copy path button
read here
Talks about copy value and copy path.
Path for tariff2 would be
msg.payload.tariff2.activeElectricalEnergy

@Colin Well spotted i was thinking in terms of msg.topic, which messed me up. Cheers. I think using a change node to set a decent topic works best anyway.

examples of different outputs using JSONata J:

[{"id":"f380392f0e2e8551","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"activeElectricalEnergy\":58816740,\"tariff\":1,\"validityTariff\":false,\"validityEnergy\":false}","payloadType":"json","x":350,"y":4260,"wires":[["4e438d4b0bb4d30e"]]},{"id":"4e438d4b0bb4d30e","type":"change","z":"65617ffeb779f51c","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"\"tariff\" & $string($$.payload.tariff)","tot":"jsonata"},{"t":"set","p":"payload.name","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":4360,"wires":[["bbd8489957e9fb7f"]]},{"id":"b9dce646469eeb75","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"activeElectricalEnergy\":58816740,\"tariff\":2,\"validityTariff\":false,\"validityEnergy\":false}","payloadType":"json","x":350,"y":4320,"wires":[["4e438d4b0bb4d30e"]]},{"id":"bbd8489957e9fb7f","type":"join","z":"65617ffeb779f51c","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":610,"y":4300,"wires":[["c93d0f62a19a0380","242f785d02f73244","e8c1acf3eddbf6f3"]]},{"id":"c93d0f62a19a0380","type":"debug","z":"65617ffeb779f51c","name":"debug 250","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"$$.payload.*.${$.name: $.activeElectricalEnergy}","targetType":"jsonata","statusVal":"","statusType":"auto","x":690,"y":4240,"wires":[]},{"id":"242f785d02f73244","type":"debug","z":"65617ffeb779f51c","name":"debug 251","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":790,"y":4300,"wires":[]},{"id":"e8c1acf3eddbf6f3","type":"debug","z":"65617ffeb779f51c","name":"debug 252","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"$$.payload.*. activeElectricalEnergy","targetType":"jsonata","statusVal":"","statusType":"auto","x":750,"y":4380,"wires":[]}]

If you set the join to 10 items then you will have in msg.payload all the data from all tariffs, so you can combine it in any way you like.

Tell us exactly what format you want if you don't know how to do it.

NR-235-6

Mark those nodes and export the flow and paste it here so we can see what you have done.

[{"id":"419022682c38215a","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"4e438d4b0bb4d30e","type":"change","z":"419022682c38215a","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"\"tariff\" & $string($$.payload.tariff)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":120,"wires":[["bbd8489957e9fb7f"]]},{"id":"bbd8489957e9fb7f","type":"join","z":"419022682c38215a","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1060,"y":180,"wires":[["c93d0f62a19a0380"]]},{"id":"c93d0f62a19a0380","type":"debug","z":"419022682c38215a","name":"debug 250","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1140,"y":120,"wires":[]},{"id":"b1c8a4134afd36af","type":"knxUltimate","z":"419022682c38215a","server":"e91643e.d9013c","topic":"9/7/23","outputtopic":"","dpt":"235.001","initialread":0,"notifyreadrequest":false,"notifyresponse":false,"notifywrite":true,"notifyreadrequestalsorespondtobus":false,"notifyreadrequestalsorespondtobusdefaultvalueifnotinitialized":"0","listenallga":false,"name":"9/7/23 Index compteur Elec TIC","outputtype":"write","outputRBE":false,"inputRBE":false,"formatmultiplyvalue":1,"formatnegativevalue":"leave","formatdecimalsvalue":999,"passthrough":"no","x":690,"y":260,"wires":[["e02e659962a9553a"]]},{"id":"18983cf50481584a","type":"change","z":"419022682c38215a","name":"index tarif 2","rules":[{"t":"set","p":"index_wh","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1130,"y":380,"wires":[["8de431cf295f195a"]]},{"id":"8de431cf295f195a","type":"debug","z":"419022682c38215a","name":"debug 251","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1170,"y":460,"wires":[]},{"id":"e02e659962a9553a","type":"change","z":"419022682c38215a","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"msg.payload.tariff2.activeElectricalEnergy","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":340,"wires":[["37014df0cf94d29f"]]},{"id":"37014df0cf94d29f","type":"join","z":"419022682c38215a","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":990,"y":340,"wires":[["18983cf50481584a"]]},{"id":"e91643e.d9013c","type":"knxUltimate-config","host":"192.168.1.100","port":"3671","physAddr":"15.15.22","hostProtocol":"TunnelUDP","suppressACKRequest":false,"csv":"","KNXEthInterface":"Auto","KNXEthInterfaceManuallyInput":"","statusDisplayLastUpdate":true,"statusDisplayDeviceNameWhenALL":true,"statusDisplayDataPoint":false,"stopETSImportIfNoDatapoint":"skip","loglevel":"error","name":"Passerelle IP-KNX","localEchoInTunneling":true,"delaybetweentelegrams":"40","delaybetweentelegramsfurtherdelayREAD":"1","ignoreTelegramsWithRepeatedFlag":false}]

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

Just looking at it I can see that you have not used the change and join from @E1cid's post.
You were supposed to change the count there to 10 and use it in your flow.

With 10 I have the same error message

Have you used the first Change node and Join settings as in the example @E1cid posted (apart from changing 2 to 10)?

This is what I get with the 1st node keeping 2
(In fact there are 11 tariffs (from 0 to 10))