question

jonnyg avatar image
jonnyg asked

NR-API Structure

Hey guys,

I'm trying to fetch site stats via the API in node red or the HTTP request node. Basically I need to get my site total energy consumption. I've played around HEAPS with the configs to figure out how to the make the call but can't get it to work. The HTTP node doesn't seem to work but the API node by Victron works but not with a custom request.

Can anyone provide some examples of how they setup theirs?

Kind Regards

Node-REDapi
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

1 Answer
matt1309 avatar image
matt1309 answered ·

Using HTTP node.

I'm no programmer so probably way better/cleaner way to do this but this is what i used

Just replace the input node with whatever sensor and change the topic:


[
    {
        "id": "7bf8703fa63a0587",
        "type": "http in",
        "z": "dc8aacd7d9dc536b",
        "name": "Endpoint location",
        "url": "/hello",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 560,
        "y": 280,
        "wires": [
            [
                "138716507abcf2e8"
            ]
        ]
    },
    {
        "id": "971c8e977c463207",
        "type": "http response",
        "z": "dc8aacd7d9dc536b",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 1050,
        "y": 460,
        "wires": []
    },
    {
        "id": "138716507abcf2e8",
        "type": "function",
        "z": "dc8aacd7d9dc536b",
        "name": "function 2",
        "func": "\n\n//set variable if grid node sends data\nif(msg.topic === \"grid\"){\n    \n    global.set(\"grid\",msg.payload);\n    \n}\n\n//set variable if pv node sends data\nif(msg.topic === \"pv\"){\n    \n    global.set(\"pv\",msg.payload);\n    \n}\n\n\n\nmsg.payload.grid = global.get(\"grid\");\nmsg.payload.pv = global.get(\"pv\");\n\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 740,
        "y": 460,
        "wires": [
            [
                "971c8e977c463207"
            ]
        ]
    },
    {
        "id": "5f7d449d3a8675fc",
        "type": "change",
        "z": "dc8aacd7d9dc536b",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "grid",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 530,
        "y": 420,
        "wires": [
            [
                "138716507abcf2e8"
            ]
        ]
    },
    {
        "id": "b4c429d8b476e12d",
        "type": "change",
        "z": "dc8aacd7d9dc536b",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "pv",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 530,
        "y": 500,
        "wires": [
            [
                "138716507abcf2e8"
            ]
        ]
    },
    {
        "id": "698adc685a73e76d",
        "type": "inject",
        "z": "dc8aacd7d9dc536b",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "grid data",
        "payloadType": "str",
        "x": 200,
        "y": 420,
        "wires": [
            [
                "5f7d449d3a8675fc"
            ]
        ]
    },
    {
        "id": "2333a52205a202d0",
        "type": "inject",
        "z": "dc8aacd7d9dc536b",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "pv data",
        "payloadType": "str",
        "x": 190,
        "y": 500,
        "wires": [
            [
                "b4c429d8b476e12d"
            ]
        ]
    }
]
1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

jonnyg avatar image jonnyg commented ·
Hey Matt, thankyou for the code! I will have a play.


Kind Regards,

0 Likes 0 ·