I have hit the rate limit against the api while developing and it doesn’t appear to be releasing. I was no where near the 200 hits per period of time. I was calling once every 15 minutes to get todays data to extract the export and solar generation.
Most endpoints are by default rate limited with a rolling window of max 200 requests, where every 0.33 seconds a request gets removed from the rolling window. (so on average maximum of 3 requests per second won’t get rate limited). There are different types of ratelimiting in VRM. If you receive a 429 with a JSON response, you can check the Retry-After response header to check the amount of seconds you have to wait until retrying
To get this round i’d like to calculate the daily usage locally. I have tried this a few times in the past but I haven’t been able to massage the values i get from the various nodes into any form of useful numbers. I’ve tried integrating but the numbers make no sense. Obviously this is in node-red. Has anyone had any joy? I want to calculate the solar exported today and the grid exported today as kWh.
DO you want to do this exclusively on the gx device or have you got another system/pi you could use. If so you could use Victron’s influx/grafana integrations to do the heavy lifting for you.
Hi Matt,
thanks, that is using the mqtt values which I already use and is comprised of the live data. It unfortunately doesn’t have a cumulative energy values. I’ve tried using the data and integrating it but I am usually a kWh or more out from the VRM calculations at the end of the day. I did get something workingish. I have a node subscribing to the mqtt N/xxxxxx/system/0/Ac/Grid/L1/Power. This is passed into the function below.
Cheers
Andy
// Function to check if it's midnight
function isMidnight() {
var now = new Date();
return now.getHours() === 0 && now.getMinutes() === 0;
}
// Retrieve stored tracking data (or initialize if not set)
var tracking = flow.get("todaysExport") ?? { total: 0.0, lastTime: 0.0 };
// Get current timestamp
var now = new Date().getTime();
// Use last recorded time, or default to now if not set
var lastTime = tracking.lastTime === 0 ? now : tracking.lastTime;
// Reset total at midnight
if (isMidnight()) {
tracking.total = 0;
}
// Get current grid power reading
const grid = parseFloat(msg.payload.value);
if (grid>=0)
return null
// Calculate time difference in seconds
const timeDiff = (now - lastTime) / 1000.0;
// Calculate export energy (only sum negative grid power values)
if (grid < 0) {
var newkWh = Math.abs(grid) * (timeDiff / 3600000.0); // Convert to kWh
tracking.total += newkWh;
}
// Store updated values
tracking.lastTime = now;
flow.set("todaysExport", tracking);
// Round total kWh to 3 decimal places and send as output
msg.payload = Math.round(tracking.total * 1000) / 1000;
return msg;