Need to assure this array comes in correct order each time

[
    {
        "id": "b76bac04bae58859",
        "type": "tibber-data",
        "z": "916e1a31b235314f",
        "name": "",
        "active": true,
        "apiEndpointRef": "8a80f84f.0cbd98",
        "queryName": "getCurrentEnergyPrice",
        "homeId": "",
        "energyResolution": "HOURLY",
        "lastCount": 10,
        "x": 710,
        "y": 200,
        "wires": [
            [
                "527c76b98e64bd93"
            ]
        ]
    },
    {
        "id": "527c76b98e64bd93",
        "type": "change",
        "z": "916e1a31b235314f",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.total",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 900,
        "y": 200,
        "wires": [
            [
                "19d6db953848fe43"
            ]
        ]
    },
    {
        "id": "ff8fe8efde48e044",
        "type": "debug",
        "z": "916e1a31b235314f",
        "name": "Timepris ",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1520,
        "y": 360,
        "wires": []
    },
    {
        "id": "19d6db953848fe43",
        "type": "calculator",
        "z": "916e1a31b235314f",
        "name": "",
        "inputMsgField": "payload",
        "outputMsgField": "payload",
        "operation": "mult",
        "constant": "100",
        "round": false,
        "decimals": 0,
        "x": 1080,
        "y": 200,
        "wires": [
            [
                "fb673cbd43be0041"
            ]
        ]
    },
    {
        "id": "fb673cbd43be0041",
        "type": "join",
        "z": "916e1a31b235314f",
        "name": "",
        "mode": "custom",
        "build": "array",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "3",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 610,
        "y": 360,
        "wires": [
            [
                "df3839bb8411426e"
            ]
        ]
    },
    {
        "id": "df3839bb8411426e",
        "type": "calculator",
        "z": "916e1a31b235314f",
        "name": "",
        "inputMsgField": "payload",
        "outputMsgField": "payload",
        "operation": "sum",
        "constant": "",
        "round": false,
        "decimals": 0,
        "x": 730,
        "y": 360,
        "wires": [
            [
                "ab0fa8af9b21ba6e"
            ]
        ]
    },
    {
        "id": "ab0fa8af9b21ba6e",
        "type": "calculator",
        "z": "916e1a31b235314f",
        "name": "",
        "inputMsgField": "payload",
        "outputMsgField": "payload",
        "operation": "round",
        "constant": "",
        "round": true,
        "decimals": 0,
        "x": 920,
        "y": 360,
        "wires": [
            [
                "3ba0492845fb143d"
            ]
        ]
    },
    {
        "id": "bb7c54c590d49062",
        "type": "cronplus",
        "z": "916e1a31b235314f",
        "name": "Effektledd/fastpris jan-mars/april-des",
        "outputField": "payload",
        "timeZone": "",
        "persistDynamic": false,
        "commandResponseMsgOutput": "output2",
        "outputs": 2,
        "options": [
            {
                "name": "Januar til mars",
                "topic": "schedule1",
                "payloadType": "num",
                "payload": "9.91",
                "expressionType": "cron",
                "expression": "0 1/1 0-23 * 1-3 * *",
                "location": "",
                "offset": "0",
                "solarType": "all",
                "solarEvents": "sunrise,sunset"
            },
            {
                "name": "April til desember",
                "topic": "schedule2",
                "payloadType": "num",
                "payload": "16.41",
                "expressionType": "cron",
                "expression": "0 1/1 0-23 * 4-12 *",
                "location": "",
                "offset": "0",
                "solarType": "all",
                "solarEvents": "sunrise,sunset"
            }
        ],
        "x": 490,
        "y": 540,
        "wires": [
            [
                "fb673cbd43be0041"
            ],
            []
        ]
    },
    {
        "id": "1a8371d7bfb189bc",
        "type": "cronplus",
        "z": "916e1a31b235314f",
        "name": "Timepris",
        "outputField": "payload",
        "timeZone": "",
        "persistDynamic": false,
        "commandResponseMsgOutput": "output1",
        "outputs": 1,
        "options": [
            {
                "name": "schedule1",
                "topic": "schedule1",
                "payloadType": "default",
                "payload": "",
                "expressionType": "cron",
                "expression": "0 * * * * * *",
                "location": "",
                "offset": "0",
                "solarType": "all",
                "solarEvents": "sunrise,sunset"
            }
        ],
        "x": 260,
        "y": 200,
        "wires": [
            [
                "b76bac04bae58859"
            ]
        ]
    },
    {
        "id": "1a26cd6e33e1ba42",
        "type": "cronplus",
        "z": "916e1a31b235314f",
        "name": "Nettleie hverdag 6-22",
        "outputField": "payload",
        "timeZone": "",
        "persistDynamic": false,
        "commandResponseMsgOutput": "output1",
        "outputs": 1,
        "options": [
            {
                "name": "schedule1",
                "topic": "schedule1",
                "payloadType": "num",
                "payload": "20",
                "expressionType": "cron",
                "expression": "0 0/1 6-21 *  * 1-5  * ",
                "location": "",
                "offset": "0",
                "solarType": "all",
                "solarEvents": "sunrise,sunset"
            }
        ],
        "x": 540,
        "y": 240,
        "wires": [
            [
                "fb673cbd43be0041"
            ]
        ]
    },
    {
        "id": "c70faf7abb290bb8",
        "type": "cronplus",
        "z": "916e1a31b235314f",
        "name": "Nettleie kveld",
        "outputField": "payload",
        "timeZone": "",
        "persistDynamic": false,
        "commandResponseMsgOutput": "output1",
        "outputs": 1,
        "options": [
            {
                "name": "schedule1",
                "topic": "schedule1",
                "payloadType": "num",
                "payload": "11.2",
                "expressionType": "cron",
                "expression": "0  * 22-23   *  * 1-5 *",
                "location": "",
                "offset": "0",
                "solarType": "all",
                "solarEvents": "sunrise,sunset"
            }
        ],
        "x": 440,
        "y": 300,
        "wires": [
            [
                "fb673cbd43be0041"
            ]
        ]
    },
    {
        "id": "5d731bad5486400f",
        "type": "cronplus",
        "z": "916e1a31b235314f",
        "name": "Nettleie natt",
        "outputField": "payload",
        "timeZone": "",
        "persistDynamic": false,
        "commandResponseMsgOutput": "output1",
        "outputs": 1,
        "options": [
            {
                "name": "schedule1",
                "topic": "schedule1",
                "payloadType": "num",
                "payload": "11.2",
                "expressionType": "cron",
                "expression": "0  * 0-05   *  * 1-5 *",
                "location": "",
                "offset": "0",
                "solarType": "all",
                "solarEvents": "sunrise,sunset"
            }
        ],
        "x": 430,
        "y": 360,
        "wires": [
            [
                "fb673cbd43be0041"
            ]
        ]
    },
    {
        "id": "5b77f39cf1f5fe36",
        "type": "cronplus",
        "z": "916e1a31b235314f",
        "name": "Nettleie helg",
        "outputField": "payload",
        "timeZone": "",
        "persistDynamic": false,
        "commandResponseMsgOutput": "output1",
        "outputs": 1,
        "options": [
            {
                "name": "schedule1",
                "topic": "schedule1",
                "payloadType": "num",
                "payload": "11.2",
                "expressionType": "cron",
                "expression": "0  * 0-23   *  * 6-7 *",
                "location": "",
                "offset": "0",
                "solarType": "all",
                "solarEvents": "sunrise,sunset"
            }
        ],
        "x": 430,
        "y": 420,
        "wires": [
            [
                "fb673cbd43be0041"
            ]
        ]
    },
    {
        "id": "4034386af776a54d",
        "type": "cronplus",
        "z": "916e1a31b235314f",
        "name": "Nettleie Holidays",
        "outputField": "payload",
        "timeZone": "",
        "persistDynamic": false,
        "commandResponseMsgOutput": "output1",
        "outputs": 1,
        "options": [
            {
                "name": "schedule1",
                "topic": "topic1",
                "payloadType": "num",
                "payload": "11.2",
                "expressionType": "cron",
                "expression": "0 * * * * * *",
                "location": "",
                "offset": "0",
                "solarType": "all",
                "solarEvents": "sunrise,sunset"
            }
        ],
        "x": 450,
        "y": 480,
        "wires": [
            [
                "fb673cbd43be0041"
            ]
        ]
    },
    {
        "id": "64f5552a704760b2",
        "type": "modbus-write",
        "z": "916e1a31b235314f",
        "name": "",
        "showStatusActivities": false,
        "showErrors": false,
        "unitid": "",
        "dataType": "MHoldingRegisters",
        "adr": "1020",
        "quantity": "2",
        "server": "99dc7536a319fb39",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "x": 1320,
        "y": 360,
        "wires": [
            [
                "ff8fe8efde48e044"
            ],
            []
        ]
    },
    {
        "id": "137cd1765b45900a",
        "type": "debug",
        "z": "916e1a31b235314f",
        "name": "Timepris med desimaler kroner",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 870,
        "y": 540,
        "wires": []
    },
    {
        "id": "3ba0492845fb143d",
        "type": "join",
        "z": "916e1a31b235314f",
        "name": "",
        "mode": "custom",
        "build": "array",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "2",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 1130,
        "y": 360,
        "wires": [
            [
                "64f5552a704760b2"
            ]
        ]
    },
    {
        "id": "58902c1d819c1cea",
        "type": "cronplus",
        "z": "916e1a31b235314f",
        "name": "Faste avgifter i dag",
        "outputField": "payload",
        "timeZone": "",
        "persistDynamic": false,
        "commandResponseMsgOutput": "output1",
        "outputs": 1,
        "options": [
            {
                "name": "schedule 1",
                "topic": "topic1",
                "payloadType": "num",
                "payload": "10.2328767",
                "expressionType": "cron",
                "expression": "0 0/1 * *  *  * ",
                "location": "",
                "offset": "0",
                "solarType": "all",
                "solarEvents": "sunrise,sunset"
            }
        ],
        "x": 710,
        "y": 620,
        "wires": [
            [
                "9a982dd6adf64ac0"
            ]
        ]
    },
    {
        "id": "9a982dd6adf64ac0",
        "type": "change",
        "z": "916e1a31b235314f",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "fasteavgifter",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 950,
        "y": 620,
        "wires": [
            [
                "c4d85df240c3dc66",
                "3ba0492845fb143d"
            ]
        ]
    },
    {
        "id": "c4d85df240c3dc66",
        "type": "time-range-switch",
        "z": "916e1a31b235314f",
        "name": "",
        "lat": "",
        "lon": "",
        "startTime": "00:00",
        "endTime": "00:02",
        "startOffset": 0,
        "endOffset": 0,
        "x": 1130,
        "y": 620,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "8a80f84f.0cbd98",
        "type": "tibber-api-endpoint",
        "feedUrl": "wss://api.tibber.com/v1-beta/gql/subscriptions",
        "queryUrl": "https://api.tibber.com/v1-beta/gql",
        "name": "Demo"
    },
    {
        "id": "99dc7536a319fb39",
        "type": "modbus-client",
        "name": "",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "tcpHost": "10.0.0.45",
        "tcpPort": "1502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "unit_id": 2,
        "commandDelay": 1,
        "clientTimeout": 1000,
        "reconnectOnTimeout": true,
        "reconnectTimeout": 2000,
        "parallelUnitIdsAllowed": true
    }
]


So I have made this and put two values into a modbus node. It is important that these values do come in the same order each time. What can I do to get it right?

The values from the array now looks like this:

fasteavgifter : msg.payload : Object

object

value: array[2]

0: 30

1: 10.2328767

unitid: ""

fc: 16

address: 1020

quantity: "2"

messageId: "62cf3ca003dda59ee62a6954"

The solution is to not use array mode in the join node. Use object key val mode.

Make sure the 2 items to join have individual topics before they enter the join node. After the join node you will see the two values are always in the same named items within the payload. You can then arrange these in an array if you need to.

Yes, you have told me that before. I have been looking into it, and tried it, but I didnt get it to pass the modbus write node. So for now I have just delayed the second message with 10ms.

Did you use a debug output to check what was coming out of the join node??

Did you rearrange the object to make an array before you send it to the modbus node?

Adding a delay is an ugly hack (sorry). If ever one of the messages are delayed by more than 10 seconds, you will have a similar problem

The output was like 1:29,95, 2: 10,2125

Or something like that. Sorry for my maybe dumb question, how do I make an array out of that.
I know delay isnt a good thing but in this case the two values are initiated by two cronplus nodes so I hope that will work until I solved it the best/correct way.

i think you have to review the logic of your flow.
Why do you need a Join node ? why not just send the Modbus values to Modbus Flex Write node directly from the Cron plus node with the payload set as image and with the msg structure the Modbus node expects.

The reason i point this out is that when you use the Join node (for example: set to wait 3 messages) there will be a delay waiting for the msgs to arrive and the modbus device may not get its message on the time as it was set with Cron+

I fixed it using @Steve-Mcl solution. I just hade to figure out how to make it an array again, just put a simple jsonata expression into a change node ($spread($$.payload) ). So now its showing like this:

image

Why i didnt use the Flex Write? Just the lack of knowledge at this point. Have to study the Flex Write function to learn how it works. Still pretty new into the world of programming but learning something everyday, and I want to thank everybody answering my and other peoples question to contribute to that.

EDIT: By the way @Steve-Mcl the delay node worked for at least the three first messages sent. So you were completely right about that as well.

@FSHelgeland

A function node with

msg.payload = [ msg.payload["1"], msg.payload["2"] ]
return msg

will give you an answer of [39, 10.2328767] (i.e. an array of numbers instead of an array of objects) - is that not what you really need?

1 Like

Yes it is, just discovered that 5 seconds ago, was searching for that solution now. Happy you were ahead of me.

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