Hi,
I´ve made a function which is calculating the "unbalanced load" from grid ("Schieflast").
but in the case, when 2 values are the same I get "0".
example:
I1 = 12A
I2 = -15A
I3 = -15A
[
{
"id": "bc97dbc59e7fba8b",
"type": "inject",
"z": "9f6752b0.b55988",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"I1\":12,\"I2\":-15,\"I3\":-15}",
"payloadType": "json",
"x": 450,
"y": 1500,
"wires": [
[
"b1cf5dccc16d85e3",
"88d1c3acdc0c6f43"
]
]
},
{
"id": "b1cf5dccc16d85e3",
"type": "function",
"z": "9f6752b0.b55988",
"name": "Schieflast",
"func": "var I1 = msg.payload.I1;\nvar I2 = msg.payload.I2;\nvar I3 = msg.payload.I3;\nvar Ia = I1-I2;\nvar Ib = I1-I3;\nvar Ic = I2-I3;\nvar Iaa = Math.abs(Ia);\nvar Ibb = Math.abs(Ib);\nvar Icc = Math.abs(Ic);\nif (Iaa > Ibb && Icc ) {\n I = Iaa;\n} \nelse if (Ibb > Iaa && Icc) {\n I = Ibb;\n}\nelse if (Icc > Iaa && Ibb) {\n I = Icc;\n}\nmsg.payload = I\nmsg.payload = msg.payload.toFixed(1).replace('.', ',');\nmsg.topic = \"Schieflast\";\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 840,
"y": 1540,
"wires": [
[
"88d1c3acdc0c6f43"
]
]
},
{
"id": "88d1c3acdc0c6f43",
"type": "debug",
"z": "9f6752b0.b55988",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1380,
"y": 1560,
"wires": []
}
]
with "or" ( || ) I get 0
maybe there is a simple function in JS for this case