Make array from 4 nodes putting out number

I have 4 Nodes polling different data from Home Assistant. They put out the numbers i need to read. But as I want as few modbus node as possible I want to merge the values into an array. Anyeone who could give me a hint to do this?

Freddy

You can have a look at the join node which should do what you need !

That was my impression to, but I can not get any output from the join node. And if I set it to merge i get the following message. 8.11.2021, 16:05:09node: be4a9f06beef7bf7msg : string[29]

"Cannot merge non-object types"

And if I tell it to make an array nothing happens.

Show us how you have configured the Join node.

As you can not guarantee the order of the polling devices, you can not guarantee the order of the array,. Does the array have to have an order?

If you join as array then you could have two array elements filled by same polling device.

Best to join as a key value object, then you can order the output array or not. Each polling device will need a unique topic to create the key value object.

here is an example

[{"id":"381dd7a6.4948b","type":"change","z":"7f59364f045fd16d","name":"unordeed array","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.*","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":740,"wires":[["a966cb14.c37eb"]]},{"id":"2b1f7419.779bc4","type":"join","z":"7f59364f045fd16d","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":420,"y":600,"wires":[["a7cfb606.aecfc","381dd7a6.4948b"]]},{"id":"a966cb14.c37eb","type":"debug","z":"7f59364f045fd16d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":600,"wires":[]},{"id":"47217e33.156a5","type":"inject","z":"7f59364f045fd16d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"b","payload":"2","payloadType":"num","x":190,"y":620,"wires":[["2b1f7419.779bc4"]]},{"id":"d72d6c96.dacd","type":"inject","z":"7f59364f045fd16d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"a","payload":"1","payloadType":"num","x":190,"y":580,"wires":[["2b1f7419.779bc4"]]},{"id":"b663bddc.727438","type":"inject","z":"7f59364f045fd16d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"c","payload":"3","payloadType":"num","x":190,"y":660,"wires":[["2b1f7419.779bc4"]]},{"id":"6c3bf74.56fd688","type":"inject","z":"7f59364f045fd16d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"d","payload":"4","payloadType":"num","x":190,"y":700,"wires":[["2b1f7419.779bc4"]]},{"id":"a7cfb606.aecfc","type":"change","z":"7f59364f045fd16d","name":"Ordered array","rules":[{"t":"set","p":"payload","pt":"msg","to":"$keys($$.payload)^($).$lookup($$.payload, $)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":660,"wires":[["a966cb14.c37eb"]]}]
1 Like

I would look at the example of yours, as they do need to have the correct order. Thank you again for leading me in the right direction,

To make the array : (1) in each of the 4 poll states, make sure the "state type" is set to "number". (2) Connect all 4 outputs of the poll state to the entrance of a "join" node. (3) in the join-node set the "mode" to "manual" ; in the "combine each" keep "msg.payload" ; in the "to create" choose "an Array" ; in "the send a message", set the "after a number of message parts" to "4" ; in the "name" key in the Array name.

I have a similar thing going on using 2 input poll states, and set the number of message parts to "2".
To assure the polling does not overlap I put in a 2 minute interval and output on connect in the "poll state" nodes.

Good luck

That will make me an array, but as E1cid said it gives us an array with four outputs but not in the correct order. Even not all the correct values as some of the values appears twice several times letting some values behind. But thanks anyway.

Maybe it is a timing issue now. I find it is possible in my case of 2 poll state inputs (A,B) to change the position in the arrray by adding a "delay" node between each poll node and the join node. I use
milliseconds in the delays. The first poll node delay I give 10 milliseconds, the second I give 20 milliseconds. The array shows [A,B]. Then I change the values to 20 and 10... the array shows [B,A]

I avoid array mode for that exact reason.

Just set it to key/value mode and you will always get the right value in the right property.

example...

drfIvxjEON

Demo flow...

[{"id":"a0799a0abcae80f1","type":"inject","z":"8ff35f2f8018f9c7","name":"HA Value 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"HA1","payload":"1","payloadType":"num","x":1920,"y":540,"wires":[["12cb0a8ec782f13a"]]},{"id":"e2e404fb6070887c","type":"inject","z":"8ff35f2f8018f9c7","name":"HA Value 2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"HA2","payload":"2","payloadType":"num","x":1920,"y":600,"wires":[["12cb0a8ec782f13a"]]},{"id":"5939c1196812aa26","type":"inject","z":"8ff35f2f8018f9c7","name":"HA Value 3","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"HA3","payload":"3","payloadType":"num","x":1920,"y":660,"wires":[["12cb0a8ec782f13a"]]},{"id":"e19adb51f9022c54","type":"inject","z":"8ff35f2f8018f9c7","name":"HA Value 4","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"HA4","payload":"4","payloadType":"num","x":1920,"y":720,"wires":[["12cb0a8ec782f13a"]]},{"id":"12cb0a8ec782f13a","type":"join","z":"8ff35f2f8018f9c7","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":2150,"y":620,"wires":[["6e3e9d26ed17e763"]]},{"id":"6e3e9d26ed17e763","type":"debug","z":"8ff35f2f8018f9c7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":2190,"y":680,"wires":[]}]
1 Like

I really need that array, so this is what i ended up with. Probably not the best solution, but it works fine, and I got rid off three Modbus nodes.


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