How do I pull values out of an array of objects

Hey All, Not to sure exactly how to go about this. Been spending a good part of the week getting
atleast this far and was wondering if anyone knew how to pull out values from an item within an
object which is within an array. Its coming out of a get request for my inverter and id like to display
the values in a dashboard.

Im using 2 split nodes and a switch node to get the data for my inverter using the site ID to get the
right object. I have used a debug to drill down to the value i want but I dont know how to pull the value
out of the object. Any help would be appreciated . I would really like to be able to get the Voltage value for instance under raw value.

Here is some pictures though and will put the output into a text file. I wish I knew more about Json or
Java as id been told i could probably pull everything out through a function node... One day I will get
there.

Thankyou anyone willing to help
Output.txt (8.3 KB)


Some news is finally made a semi breakthrough? its not ideal but it will work and that is i will have to have multiple function nodes with a similar text to pull all my inverter information. Here is the code for the function node.

let BV = msg.payload.extended[2].rawValue;
msg.payload = BV;
return msg;

Hi!

I'm not sure if I understood what you want to achieve. If you just want all rawValues from your JSON inone array, use a function node with:

let pe = msg.payload.extended;
let e = pe.map(x => x.rawValue);
msg.payload = e;
return msg;

Hi Simon and thanks for the reply,

Not really that way, But i have a number of data values i'm interested in.
with their own differential paths being something like.

let GrAlarmText = msg.payload.extended[19].textValue;
let BChargSt = msg.payload.extended[3].rawValue;
let Bchargtex = msg.payload.extended[5].textValue;
let ALR1 = msg.payload.alarm;

I tried an approach which where I would have multiple outputs from a function node
to feed the home dashboard.but with my understanding that didn't work out.
I tried something like this.

msg.payload = ALR1;
   return [ null, msg ];
msg.payload = GrAlarmText;
   return [ msg, null ];
;

This did not work. So I am currently using maybe 60 function nodes lol for each break
off message I plan to use.

If you want to display an attribute from a message in the dashboard, most dashboard nodes allow you to put, in the Value Format field something like
{{msg.payload.extended[3].rawValue}}
Then you can feed the full message to all dashboard nodes.

Oh no way.... I have got to try this hahahaha. do some other nodes operate the same way?
Like for instance switch and change nodes? There is this awesome little UI someone here made
that Ive been using like a traffic light and needs to be fed color changes which then i use a change
node to act on content of a message.

Thank you for the information. this should save a fair bit on node usage

Can you give an example of exactly what you want to do in those nodes?

Well right now its something like this, With the logics being that it looks for the Grid ok/lost,
But if the battery is low it should show amber , I wish I knew how to add the next level of logic
which is that if grid is lost and battery is low then send red . any ideas? The battery percentage
and the Grid state come from 2 separate function nodes at the moment

[
    {
        "id": "31643f00.8068a2",
        "type": "ui_template",
        "z": "3b34e0bec79715e3",
        "group": "19d977f5.9091e",
        "name": "Status",
        "order": 4,
        "width": 2,
        "height": 1,
        "format": "<style>\n.led-green {\nmargin: 0 auto;\nwidth: 24px;\nheight: 24px;\nbackground-color: #ABFF00;\nborder-radius: 50%;\n{\n</style>\n<table>\n<tr>\n<td><div class=\"led-green\" style=\"background-color:{{msg.payload}}\"></div></td>\n<td></td>\n</tr>\n</table>\n",
        "storeOutMessages": true,
        "fwdInMessages": true,
        "resendOnRefresh": false,
        "templateScope": "local",
        "x": 1430,
        "y": 220,
        "wires": [
            []
        ]
    },
    {
        "id": "7d926e81.1c9fb",
        "type": "change",
        "z": "3b34e0bec79715e3",
        "name": "change to red",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "red",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1400,
        "y": 180,
        "wires": [
            [
                "31643f00.8068a2"
            ]
        ]
    },
    {
        "id": "eba70a4.b228078",
        "type": "switch",
        "z": "3b34e0bec79715e3",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "cont",
                "v": "Grid ok",
                "vt": "str"
            },
            {
                "t": "lt",
                "v": "40",
                "vt": "num"
            },
            {
                "t": "cont",
                "v": "Grid lost",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 1070,
        "y": 140,
        "wires": [
            [
                "e0c5f60a.79228"
            ],
            [
                "ab956068591ffd7b"
            ],
            [
                "7d926e81.1c9fb"
            ]
        ]
    },
    {
        "id": "5c433262.392e74",
        "type": "change",
        "z": "3b34e0bec79715e3",
        "name": "change to orange",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "orange",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1410,
        "y": 140,
        "wires": [
            [
                "31643f00.8068a2"
            ]
        ]
    },
    {
        "id": "e0c5f60a.79228",
        "type": "change",
        "z": "3b34e0bec79715e3",
        "name": "change to green",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "green",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1410,
        "y": 100,
        "wires": [
            [
                "31643f00.8068a2"
            ]
        ]
    },
    {
        "id": "ab956068591ffd7b",
        "type": "delay",
        "z": "3b34e0bec79715e3",
        "name": "",
        "pauseType": "delay",
        "timeout": "100",
        "timeoutUnits": "milliseconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "x": 1210,
        "y": 140,
        "wires": [
            [
                "5c433262.392e74"
            ]
        ]
    },
    {
        "id": "ddc48e96.3454c8",
        "type": "function",
        "z": "3b34e0bec79715e3",
        "name": "",
        "func": "let GrAlarmText = msg.payload.extended[19].textValue;\nmsg.payload = GrAlarmText;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 800,
        "y": 120,
        "wires": [
            [
                "9ca58e3e.16a668",
                "eba70a4.b228078"
            ]
        ]
    },
    {
        "id": "8e6ac797.8ce97",
        "type": "function",
        "z": "3b34e0bec79715e3",
        "name": "",
        "func": "let BChargSt = msg.payload.extended[3].rawValue;\nmsg.payload = BChargSt;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 800,
        "y": 160,
        "wires": [
            [
                "1d6fb8b3.ce6dc7",
                "eba70a4.b228078"
            ]
        ]
    },
    {
        "id": "19d977f5.9091e",
        "type": "ui_group",
        "name": "CC-Oakhurst-Rondebosch",
        "tab": "3ceee6af.390d22",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "3ceee6af.390d22",
        "type": "ui_tab",
        "name": "Cash Crusaders Overview",
        "icon": "business",
        "order": 2,
        "disabled": false,
        "hidden": false
    }
]

Replace the function nodes with Switch nodes. Either in parallel or feed one into the other dependant on what you are trying to achieve. In the Switch node you can set the Property field to any property of the message that you want. For example msg.payload.extended[19].textValue

I will give this a shot thankyou,

What I am looking to get out is that the state is good if both grid connected
and battery over 50 percent, It must change to amber if batter is below 50 percent and must be red when
grid is lost.

Can you rewrite that using the property names please? To save me trying to understand the data.

I am going to try , If i understand your question correctly..

This msg gives me grid state which only comes in answes of "Grid ok" or "Grid lost"
msg.payload.extended[21].textValue

This msg gives me the battery charge Percent which is 0-100
msg.payload.extended[3].rawValue

This msg gives me the battery state in 3 text string forms "idle" or "charging" or "discharging"
msg.payload.extended[5].textValue

This msg gives me the power consumption from the grid in a string number from -2000 to 5000
msg.payload.extended[15].rawValue

I hope this helps

Is that all in one message?

If it is all in one message, which I think it is, then I think that can be rewritten as
If msg.payload.extended[21].textValue is "Grid lost" then set status Red
Otherwise, if msg.payload.extended[3].rawValue is <= 50 set status Amber
Otherwise set status Green.

That can be done using Switch nodes as in this flow.

[{"id":"12b9fa3ceda3a249","type":"switch","z":"84405ff5.25fa6","name":"","property":"payload.extended[21].textValue","propertyType":"msg","rules":[{"t":"eq","v":"Grid lost","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":190,"y":3160,"wires":[["556fbc5abe4caaf9"],["80c124c13585e360"]]},{"id":"80c124c13585e360","type":"switch","z":"84405ff5.25fa6","name":"","property":"payload.extended[3].rawValue","propertyType":"msg","rules":[{"t":"lte","v":"50","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":350,"y":3200,"wires":[["9028bd9635ca9428"],["fcf4ef05d789e732"]]},{"id":"556fbc5abe4caaf9","type":"change","z":"84405ff5.25fa6","name":"change to red","rules":[{"t":"set","p":"payload","pt":"msg","to":"red","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":3140,"wires":[[]]},{"id":"9028bd9635ca9428","type":"change","z":"84405ff5.25fa6","name":"change to orange","rules":[{"t":"set","p":"payload","pt":"msg","to":"orange","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":3180,"wires":[[]]},{"id":"fcf4ef05d789e732","type":"change","z":"84405ff5.25fa6","name":"change to green","rules":[{"t":"set","p":"payload","pt":"msg","to":"green","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":3220,"wires":[[]]}]

Yes you are right it comes from one large message, Sorry for the delay I had to attend to kids :smiley: ,
I see when feeding it from source message it takes it as one and then makes arguments about the
whole content. I was really thinking that it would get both and split off a message which could have
overwritten the desired state . Thanks for the insight

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