How to use the function node to extract multiple data values

Hi,
unfortunately i can't get it to extract the needed values out of a data output (from MobileAlerts).
Basically I can get the data out using the Node function, but the output of Mobile Alerts returns many records at once and with the same names.
So for example for "t1" there are several records and I can't target them.

How can I read out the values as "t1", separately from "Meerscheinhaus" and "Hot Pot"?

function node:
return { payload: msg.payload.measurements[0].t1};

data record:

msg.payload : Object

object

deviceid: "03194EFD88B8"

devicetypeid: 3

name: "Meerschweinhaus"

lang: "de"

lastseen: 1669201932

lowbattery: false

alertwasactive: false

oldestmeasurementt: 1515176626

cloninginprocess: false

settings: object

measurements: array[1]

0: object

idx: 7050685

ts: 1669201924

tx: 1037

c: 1669201932

pr: false

lb: false

t1: 8.8

h: 99

alertevents: array[0]

25.11.2022, 16:52:54node: debug 51

msg.payload : Object

object

deviceid: "015D5F88E64F"

devicetypeid: 1

name: "Hot Pot "

lang: "de"

lastseen: 1669391157

lowbattery: false

alertwasactive: false

oldestmeasurementt: 1668927848

cloninginprocess: false

t1min: 5.6

t1mint: 1669354854

t1max: 19.5

t1maxt: 1669042711

t1resett: 1669042715

t2min: 9.2

t2mint: 1669357772

t2max: 25.2

t2maxt: 1669042711

t2resett: 1669042715

settings: object

measurements: array[1]

0: object

idx: 1107

ts: 1669391153

tx: 1110

c: 1669391157

pr: false

lb: false

t1: 8.7

t2: 10.1

alertevents: array[0]

For the input that you show, exactly what do you want out?

Also, there is a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

in my payload there are two values for "t1"
one under: name: "Meerschweinhaus"
t1: 8.8
an one under: name: "Hot Pot "
t1: 8.7
how can i get these tow different values, my function node extract only one of them

Can you share usable data?

Instead of using you mouse to drag and select the payload data, please use the Copy Value button

BX00Cy7yHi

Also, please paste this copied data in a code block: 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 
```

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

Where do you want them and how will you identify which is which?

I will simply display the values in a dasboard text node

Identify: the first value is under "Meerschweinhaus" and the secound under "Hot Pot "

I think you need first to use a Switch node on msg.payload.name so that the Meerschweinhaus data goes down one path and the Hot Pot data down the other. Then you can use the function to extract the data.
There are more efficient ways of doing it but if you check that simple method works first then we can improve it.

I have already tried this, unfortunately it seems to be possible with the MobileAlerts node only to deliver all data at once at a node. When I create a second MobilieAlerts node, the first one does not anymore return any data. Yes, otherwise this would be a good way to separate this.
Would be great if you have another tip for me.

I did not suggest that. Add a Switch node after the MobileAlerts node and use the Switch node to send the messages down the two paths.

sorry I had not understood
I will test

I unfortunately do not get it, with the split

[
    {
        "id": "0de373e5982cb8ec",
        "type": "switch",
        "z": "0bea014635181a34",
        "name": "",
        "property": "payloadpayload.deviceid",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "03194EFD88B8",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "015D5F88E64F",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 430,
        "y": 760,
        "wires": [
            [
                "ae665d685908ab0f"
            ],
            [
                "d0236cad2ad4addc"
            ]
        ]
    }
]

image

Why have you specified msg.payloadpayload.deviceid in the switch. Looking at your earlier post where you showed us the data it appears to be msg.payload.deviceid

great, it works now
thanks for your quick help

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