Extract data from msg.payload.response

Hi, Id like to extract an integer from a msg.payload.response

I just need the power data. tried many functions, but don't get it.
can someone help me out here?

this is the payload result:

{
"power": 3.037565,
"relay": true
}

best regards
Jens

Is the response from http - whats the format ? UTF or JSON object ? Did you try to converting it to JSON object. Then should be straight forward.

I think its a http response. I'm totally new in node-red and java js. dont know how to convert it to a JSON object.

when using this command in bash, i get the power data:
curl http://192.168.0.86/report | sed -n 2p | awk 'NF>1{print $NF}' | sed 's/.$//'

this is the complete msg.payload i get, when using the mystrom plugin.

Bildschirmfoto 2022-02-19 um 21.09.42

Ok. It may/may not be http.
You need to send it to JSON node to convert it to JSON object.
In json node - configure - the value as msg.payload.response and setting as Convert to JSON Object.
Should work.

First use a change node and set the payload to payload.response. With this feed the json node and the get the value by extracting the power.

[
    {
        "id": "3c52b18925bace22",
        "type": "change",
        "z": "ebe8134f6b5af26c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.response",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 450,
        "y": 1360,
        "wires": [
            [
                "b87e294ee7801cb8"
            ]
        ]
    },
    {
        "id": "b87e294ee7801cb8",
        "type": "json",
        "z": "ebe8134f6b5af26c",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 650,
        "y": 1360,
        "wires": [
            [
                "89193357b0838718"
            ]
        ]
    },
    {
        "id": "89193357b0838718",
        "type": "change",
        "z": "ebe8134f6b5af26c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.power",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 850,
        "y": 1360,
        "wires": [
            [
                "759c0e7163544516"
            ]
        ]
    },
    {
        "id": "759c0e7163544516",
        "type": "debug",
        "z": "ebe8134f6b5af26c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1080,
        "y": 1360,
        "wires": []
    },
    {
        "id": "ef1f93c641c49c47",
        "type": "inject",
        "z": "ebe8134f6b5af26c",
        "name": "",
        "props": [
            {
                "p": "payload.response",
                "v": "{\"power\":2123}",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 250,
        "y": 1360,
        "wires": [
            [
                "3c52b18925bace22"
            ]
        ]
    }
]

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