question

michaltylki avatar image
michaltylki asked

NodeRed script

Hi.
I wanted to ask if anyone has a script for NodeRED that delays the charging of the energy storage during periods of high sunlight (from April to August). The idea is that until, say, 11 a.m., Victron will transmit energy from PV to the grid, and after 11 a.m. or when the voltage increases to 249V, it will charge the energy storage.
Node-RED
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.

kevgermany avatar image kevgermany ♦♦ commented ·
Moved to modifications as it's a Node-Red question.
0 Likes 0 ·
1 Answer
matt1309 avatar image
matt1309 answered ·

Hi @michal.tylki

I do not have a script however you could make one relatively easily

Input will be PVProduction and ACLoads and ACVoltage

You will then set grid setpoint = max(0,PVProduction - ACLoads);


I'll help with some code below but please note this is untested (and I'm not a developer). And you'll need to debug appropriately on your system. However hopefully a good starting point for you.


In terms of getting the data for the variables if you're using 3.20 I think you can just access these using global context. Which is explained by Dirk here:

https://community.victronenergy.com/questions/267183/output-power-from-four-inverters-in-one-sum-node-r.html?childToView=267261#answer-267261


If you're on earlier version i would get PVProduction from a victron node then use a change node to assign msg.topic = PVProduction.

Then do the same with ACLoads and ACVoltage.

And have the output of those 3 change nodes go into a function node that does the logic described above:

//setting variables and getting Current time. 
//you can probably wrap all of this in the timing IF to minimise it running if needed

var currentTime = new Date();
var currentHour = currentTime.getHours();
var ACLoads = global.get('ACLoads');
var ACVoltage= global.get('ACLoads');
var PVProduction= global.get('ACLoads');


/*
storing variables in global context (this is only needed if on earlier versions of
venus os. As explained by Dirk in the link above
*/
if (msg.topic === "ACLoads") {
  ACLoads= msg.payload; // Extract payload from input 1
  global.set('ACLoads',ACLoads);
}
if (msg.topic === "ACVoltage") {
  ACVoltage= msg.payload; // Extract payload from input 1
  global.set('ACVoltage',ACVoltage);
}

if (msg.topic === "PVProduction") {
  PVProduction = msg.payload; // Extract payload from input 1
  global.set('PVProduction',PVProduction);
}


//Now for the gridsetpoint logic
// Check if current time is between 4 am and 11 am, can go earlier if sunny at 4am
if (currentHour >= 4 && currentHour < 11 && ACVoltage <249) {
    
    msg.payload = max(0,PVProduction - ACLoads);
return msg;
} else if (currentHour >= 4 && currentHour < 11){
  /* 
I've added if here to stop spamming gridsetpoint outside of this timeframe
And also to set grid setpoint to 0 if voltage criteria is exceeded. 
*/
    msg.payload = 0; 
return msg;
}


The output of this function needs to go to a node that sets grid setpoint.


You will also need a seperate flow that set grid setpoint to 0 at 11am to undo the above.

2 |3000

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