Hello,
I would like to write the payloads from the VRM forecast api to an influxdb.
Does anyone have the function for this?
This site is now in read-only archive mode. Please move all discussion, and create a new account at the new Victron Community site.
Hello,
I would like to write the payloads from the VRM forecast api to an influxdb.
Does anyone have the function for this?
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 influxdb
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]" } ]
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.
many thanks for your help.
There is still an error in the script
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.
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]" } ]
Webinar Part 1 - Intro to Node-Red
Webinar Part 2- Basic Palettes
Webinar Part 3 - Advanced example
Victron Node-RED for dummies guide by Fideri
Node Red Community Space (normally hidden)
Venus OS Large (Node-RED) manual
Victron Node-RED github readme
Victron Node-RED custom nodes docs
Additional resources still need to be added for this topic
56 People are following this question.