If not equal to "string" and equal to number - function node

Hello NodeRED Community,

i have a quite bad issue which i can not solve out of the box:

Currently i have a function node which has this function that is not working:

var valueSensorMode = msg.payload.valueSensorMode
var valueHardUpperLimit = msg.payload.valueHardUpperLimit
var valueLimitValue = msg.payload.valueLimitValue
var valueHardLowerLimit = msg.payload.valueHardLowerLimit
var currentValue = msg.payload.valueInteger

if(valueSensorMode!== "standby" && currentValue > valueHardUpperLimit){
    msg.payload.valueResult = "out of upper limit"    
    return msg
}
if(valueSensorMode!== "standby" && currentValue < valueHardLowerLimit){
    msg.payload.valueResult= "out of lower limit"
    return msg
}
if(valueSensorMode!== "standby" && currentValue > valueHardLowerLimit && currentValue < valueHardUpperLimit){
    msg.payload.valueResult = "value ok"
    return msg
}
if(valueSensorMode=== "standby"){
    msg.payload.valueResult == "evaluation not available"
    return msg
}

I have the following message / msg.payload as an input format:

{
   "sensorTime":1673284939618,
   "valueInteger":114.9,
   "valueMachineMode":"standby",
   "valueHardUpperLimit":2,
   "valueLimitValue":0,
   "valueHardLowerLimit":-2
}

And I am expecting an output message / msg.payload (according to the dedicated intput) that has an additional field which is the "valueResult":

{
   "sensorTime":1673284939618,
   "valueInteger":114.9,
   "valueMachineMode":"standby",
   "valueHardUpperLimit":2,
   "valueLimitValue":0,
   "valueHardLowerLimit":-2,
   "valueResult": "evaluation not available"
}

Can anybody help?

You have the standby result shown originating from msg.payload.valueSensorMode

and yet in in your input, the standby result is at msg.payload.valueMachineMode

Shouldn't you be using - var valueSensorMode = msg.payload.valueMachineMode

1 Like

Hi there. I’m not at a computer at the moment, so I can’t run your code, but the first thing that stands out to me is that the line where you set the valueResult to “evaluation not available”, you have == and not =
(So you are performing a test, and not an assignment)

2 Likes

Thats it... I didn't see that..

Thank you very much for your input!

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