Hello. I have two inputs in a node function that input random numerical data read from a solar inverter. PV is the instant production of the inverter and Grid is the consumption from the network.
Through that function, I want to do the following::
var Grid = {payload: msg.payload};
var PV = {payload: msg.payload};
if (PV >1.1 && Grid >-0.4)
{ return 1;}
if (PV <0.7 && Grid <-0.4)
{ return 2; }
if (PV >2.1 && Grid >-0.4)
{ return 3; }
if (PV <1.7 && Grid <-0.4)
{ return 4; }
if (PV >2.8 && Grid >-0.4)
{ return 5; }
if (PV <2.5 && Grid <-0.4)
{ return 6; }
else {
return 0 ;}
data 1,2,3 4,5,6 would be sent to a node switch that controls some switches
Unfortunately, I have nothing on the output, something is not right. I'm at the beginning and I can't figure it out.
Maybe someone can help me with the code from the node function. Thank you
Messages from multiple wires will never arrive at the input of a node at the same time.
You have 2 options here. 1. Connect everything in series and use alternative msg properties e.g msg.result1 & msg.result2 or use a join node to combine the multiple messages into one.
For your particular scenario, I recommend the series approach.
Hi, Thank you for the answer. I cannot connect in series the 2 modbus getter node because the huawei inverter dont respond at 2 requests for 2 differently internal address in the same time . So, i used join node to combine the 2 values : PV and grid and it works.- i have the result in one messages debug4
Yes, i will try with 2 switch but i have 6 contidions and i will need 12 switch
var Grid = {payload: msg.payload};
var PV = {payload: msg.payload};
if (PV.payload >1.1 && Grid.payload >-0.4)
{ return 1;}
if (PV.payload <0.7 && Grid.payload <-0.4)
{ return 2; }
if (PV.payload >2.1 && Grid.payload >-0.4)
{ return 3; }
if (PV.payload <1.7 && Grid.payload <-0.4)
{ return 4; }
if (PV.payload >2.8 && Grid.payload >-0.4)
{ return 5; }
if (PV.payload <2.5 && Grid.payload <-0.4)
{ return 6; }
else {
return 0 ;}
I need a function with one output result ( 1or 2 or 3 or 4 or 5 or6) because after function I have a single switch that controls 3 wireless switches- ex if the function output is 1 first wireless switch is open, if the result is 2 first wireless switch is closed .
So, i need a working function code
@hotNipi and @bakman2 are right to query that chain of if statements.
@satkey3's original version used return statements, so only one if (... && ...) statement would be evaluated true.
In getting rid of the return statements I used else if (... to hopefully achieve the same result.
A chain of compound if statements like that can quickly become impenetrable.
If I were writing the code myself I'd probably split it into two blocks for Grid > -0.4 and Grid < -0.4
And what happens if Grid === -0.4?