Send different values from an array to different nodes?

Been searching and trying for a while but I still do something wrong. I have different values coming from the car once in a while (bluelinky). I need some of the values put to different output nodes. I have made a function node to get the values I want.

var newMsg = { payload: [msg.payload.evStatus.batteryStatus, msg.payload.battery.batSoc, msg.payload.evStatus.drvDistance[0].rangeByFuel.evModeRange.value, msg.payload.evStatus.batteryCharge, msg.payload.doorLock] };
return newMsg;

Then I have used a split node with the settings split using payload and fixed lenght of 1. Then I get separated messages from the split node. But I struggle to use the Switch node to route the messages to the correct debug node. Is it possible to set this up in the switch node as it is? Or do I have to add topic in the function node first?

I will greatly appreciate any suggestions who can help me on the way fixing this.

Best regards

Instead of an array, make newmsg.payload a javascript object:

newMsg.payload = {
"status": msg.payload.evStatus.batteryStatus, 
"soc": msg.payload.battery.batSoc, 
"range": msg.payload.evStatus.drvDistance[0].rangeByFuel.evModeRange.value, 
"battery": msg.payload.evStatus.batteryCharge, 

Then your downstream processing can operate on msg.payload.status or msg.payload.doorlock etc.

1 Like

Yes, if you set the switch node property to
and the rules to equals number 0 or 1 or 2 or 3 etc.
Have a look at the output of the split node, using a debug set to complete message object.

Thank you E1cid, this did the trick. I do not know enough code to see the simple solutions yet, so I am very grateful when I get good help as this.

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