question

dl9msr avatar image
dl9msr asked

VRM Solar Yield Forecast api NodeRed write into influxdb

Hello,

I would like to write the payloads from the VRM forecast api to an influxdb.

Does anyone have the function for this?

vrm-forecast-2024-05-20-114517.png

Node-REDsolar forecast
2 |3000

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

8 Answers
matt1309 avatar image
matt1309 answered ·

I imagine there's a node built for sending data to influxdbs.

I've found this guide that might help:

Send data from your Node-RED flows into InfluxDB • FlowFuse


You'd just adjust your data to be similar to the form of the data in step 4.

2 |3000

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

dl9msr avatar image
dl9msr answered ·

Thank you for reply

write data to influxdb is not my problem. I write a lot of data from Cerbo into the influxdb and visualize it with Grafana.

I need a jave function code that puts the forecast array in the correct format for influxdbvictron2024-05-20-125130.png


2 comments
2 |3000

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

Alistair Warburton avatar image Alistair Warburton commented ·
What format do you need? Whatever it is it isn't going to be hard, function node being the most flexible but JSON / JsonAta expression in a change node would do it too.
0 Likes 0 ·
dl9msr avatar image dl9msr Alistair Warburton commented ·

I need the format as in the screenshot for each array

vrm-2024-05-20-131237.png

0 Likes 0 ·
Alistair Warburton avatar image
Alistair Warburton answered ·

Send me a screenshot of your API node cionfig...

2 |3000

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

dl9msr avatar image
dl9msr answered ·

thanks for reply

vrm-api-20230210-204744.png


2 |3000

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

Alistair Warburton avatar image
Alistair Warburton answered ·

This should work, it is a change node but the basic code should work in a function.

I only did the first 3 records, you will need to the modify the JSON expression


[
    {
        "id": "a96dd4060da051a4",
        "type": "change",
        "z": "bcb0be278709987b",
        "name": "Convert array to object",
        "rules": [
            {
                "t": "set",
                "p": "payload.newrecords",
                "pt": "msg",
                "to": "{\t    solar_yield_forecast & $string(payload.records.solar_yield_forecast[0][0]) : payload.records.solar_yield_forecast[0][1],\t    solar_yield_forecast & $string(payload.records.solar_yield_forecast[1][0]) : payload.records.solar_yield_forecast[0][1],\t    solar_yield_forecast & $string(payload.records.solar_yield_forecast[2][0]) : payload.records.solar_yield_forecast[0][1]\t}",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "payload.records.solar_yield_forecast",
                "pt": "msg",
                "to": "payload.newrecords",
                "tot": "msg",
                "dc": true
            },
            {
                "t": "delete",
                "p": "payload.newrecords",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 660,
        "y": 380,
        "wires": [
            [
                "176b13b3b0d0676e"
            ]
        ],
        "info": "$string(payload.records.solar_yield_forecast[0][0])\n\n.records.solar_yield_forcast\n\npayload.records.solar_yield_forecast[0]"
    }
]
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.

Alistair Warburton avatar image Alistair Warburton commented ·

BTW, there are probably many other ways to do this and are you absolutely sure the timestamps will always be unique?

if not you shouldn't be using them as path elements.

Also... as you are using now to end of day the number or records will vary, which complicates things.

You could use a function and create a loop that checks the array length and then process that many but you are probably better getting a known time period, and thus number of record, so you can use hard code to process them and let the database sort stuff out.

0 Likes 0 ·
dl9msr avatar image
dl9msr answered ·

many thanks for your help.

There is still an error in the script

vrm-2024-05-20-160512.png


2 |3000

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

dl9msr avatar image
dl9msr answered ·

I found the mistake.

Thank you so much so I can continue testing and see the result in Grafana

2 |3000

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

Alistair Warburton avatar image
Alistair Warburton answered ·

Sorry, silly error...

This :-

    solar_yield_forecast & $string(payload.records.solar_yield_forecast[0][0]) : payload.records.solar_yield_forecast[0][1],
    solar_yield_forecast & $string(payload.records.solar_yield_forecast[1][0]) : payload.records.solar_yield_forecast[0][1],
    solar_yield_forecast & $string(payload.records.solar_yield_forecast[2][0]) : payload.records.solar_yield_forecast[0][1]

Should be this :

    solar_yield_forecast & $string(payload.records.solar_yield_forecast[0][0]) : payload.records.solar_yield_forecast[0][1],
    solar_yield_forecast & $string(payload.records.solar_yield_forecast[1][0]) : payload.records.solar_yield_forecast[1][1],
    solar_yield_forecast & $string(payload.records.solar_yield_forecast[2][0]) : payload.records.solar_yield_forecast[2][1]

The first element ordinal is wrong on the right side after the colon.

Do you understand what it is doing, you will need to to alter it!

...solar_yield_forcast[a][b] is a two element array with the where [a] is effectively the record number, 0 to n and [b] is an array of two values so ...[0][1] is the timestamp of the first record and ...[2][1] is the value of the third record.

1716241349762.png

And here is the corrected code...


[
    {
        "id": "a96dd4060da051a4",
        "type": "change",
        "z": "bcb0be278709987b",
        "name": "Convert array to object",
        "rules": [
            {
                "t": "set",
                "p": "payload.newrecords",
                "pt": "msg",
                "to": "{\t    solar_yield_forecast & $string(payload.records.solar_yield_forecast[0][0]) : payload.records.solar_yield_forecast[0][1],\t    solar_yield_forecast & $string(payload.records.solar_yield_forecast[1][0]) : payload.records.solar_yield_forecast[1][1],\t    solar_yield_forecast & $string(payload.records.solar_yield_forecast[2][0]) : payload.records.solar_yield_forecast[2][1]\t}",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "payload.records.solar_yield_forecast",
                "pt": "msg",
                "to": "payload.newrecords",
                "tot": "msg",
                "dc": true
            },
            {
                "t": "delete",
                "p": "payload.newrecords",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 660,
        "y": 380,
        "wires": [
            [
                "176b13b3b0d0676e"
            ]
        ],
        "info": "$string(payload.records.solar_yield_forecast[0][0])\n\n.records.solar_yield_forcast\n\npayload.records.solar_yield_forecast[0]"
    }
]

1716241349762.png (38.4 KiB)
2 |3000

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