Node Red: Help wanted to create flow for switching relais on Cerbo

Hi, Please help!
I am not very familiar with node red but i am struggling all day now.
I want to switch relais on cerbo (to trigger rapid shutdown on PV) based on AC in off (Multiplus 2) and 100% SOC of battery.
I created some nodes which indicate the correct status of SOC and AC in. Switching relais is also working.
But the function node is to difficult for me. I copied some info from Harold Halewijn, but without luck.

The text I used in function node is based on 95% SOC:

context.soc = context.soc || 0.0;
context.grid = context.grid || 1;

if (msg.topic === “com.victronenergy.system – /Ac/ActiveIn/Source”) {
// if (msg.topic === “com.victronenergy.system – /Dc/Battery/State”) {
context.grid = msg.payload;

} else if (msg.topic === “com.victronenergy.system – /Dc/Battery/Soc”) {
context.soc = msg.payload;
}

// remember: switch is inversed!!!

if (context.grid === 0) {
if (context.soc > 95)
return {topic: “set relais to off”, payload: 1}
} else {
return {topic: “set relais to on”, payload: 0}
}

What am I doing wrong?

I like to keep an overview of all variables I’m using.
Before using variables in the function node I set them like this:

var SoC = msg.payload || 0;
flow.set(“SoC”,SoC);

Then in the function node I get them back:

var SoC = flow.get(‘SoC’);

After that a lot of if and then to controle everything.
The output goes in the opposite direction:

gridSetpoint = global.get(‘gridSetpoint’);
msg.payload = gridSetpoint;
return msg;

Looks like you need to change the msg.topic. I have included a modified flow that should work. It is a txt file just need to copy the flow from it
Cerbo Relay Control.txt (2.5 KB)

1 Like

Thanks a lot, I will try.

Hi,

I am afraid it did not work.
Doublechecked the relais is set on manual, copied text in function node but no luck.
Inputs are showing values for SOC and grid. Turning off AC in, SOC >95 resulted in value 240.
Tonight I tested your import by changing grid from 0 to 1 and SOC from >95 to <81. This worked because grid was on and SOC went below 81. Relais switched. Could it be that the value 240 should be in for AC in?

240 means Inverting.

From the node:
Value types:
0 - Not available
1 - Grid
2 - Generator
3 - Shore
240 - Inverting

Hi Diederik,

I know what it means, the overview is in the Node visible.
That’s not the point. I want to know what is the difference between “0” and “240”.
If the grid is not present at input of MPll I would expect “0” to be displayed because grid is not present.
So in my function Node which was made for me the “0” was used in the settings instead of “240”. After I changed it to “240” it worked.
So I want to understand…

0 mean the input is not available.

The GX in system set up has allowance for two ac inputs for the quattro. If you have a MP you would mark ac2 as unavailable.

Yes I know that it means that input is not available.
But why is Node red showing status 240 if input is not available if I disconnect grid.

Means you are now inverting.

0 means the input is not available and can’t be used.

Yes that’s clear, the main question is when I will get a “0”, Disconnecting grid gives “240”!

Because it is switching to inverting.

0 - 1 -2 -3 are input related.

240 is output.

If 1-3 are connected it cannot be inverting (240)