OEE with Node-Red

Hi, I am trying to make OEE calculations with the help of node red. In this function i'm trying to calculate the availability parameter (A).
I am trying to write a function to give me the availability value, but no matter what I do, the output is NaN. It is simple math but Im new using node-red and Javascript.

the code:

var hinicioproducao = flow.get("HoraInicio");
var hfimproducao = flow.get("HoraProducao");
var setup = flow.get("HoraSetup");
var downtimeloss = flow.get("Avarias");
msg.payload = [(hfimproducao - hinicioproducao)-(downtimeloss + setup)]/[(hfimproducao - hinicioproducao)]*100;
effectiveproductiontime = msg.payload;
return msg;

Square brackets in Javascript are used to build arrays, not for grouping expressions. Try changing the first-pair of brackets to parentheses, and just eliminate the extra second-pair of brackets:

msg.payload = ((hfimproducao - hinicioproducao)-(downtimeloss + setup))/(hfimproducao - hinicioproducao)*100;

But you must ensure that ALL of your variables are defined, or the answer will be NaN (not a number). A common way to do that in Javascript is to use the 'or' operator || to set a default if there is a missing flow value, like so:

var setup = flow.get("HoraSetup") || 0;

This line effectively does nothing, and should be eliminated -- unless you plan on doing something with that value? At a minimum, it should be declared as a var, not just left as a bare name.

Thanks for the answer. The calculation formula was incorrect which did not allow me to define all the variables well. :+1:

Nice tip. Didn't know about that.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.