Why is the result always false?

Hi,

why is the output always false instead of true, as it is defined?

var CO2 = msg.payload;

var L1 = {
  payload: {
    On:  msg.payload.On === true}}

var L2 = {
  payload: {
    On:  msg.payload.On === true}}

var L3 = {
  payload: {
    On:  msg.payload.On === true}}

var L4 = {
  payload: {
    On:  msg.payload.On === true}}


if (CO2 > 1600){ 
    return [null, null, L4];
    }
else if (CO2 > 1200){
    return [null, L3, null];
    }
else if (CO2 < 650){
    return [L2, null, null];
    }

Debug Output:

msg.payload : Object
object
On: false

Thanks for helping!

I see a couple potential issues here -- but without some sample input data, it's just a guess...

Using the triple equal operator forces JS to compare both the value and datatype for equality. So if you expect the output should be true, then I suspect your incoming value is the string "true", not a boolean. If you use the more forgiving == operator, then you may get what you expect.

In the previous code you are trying to access the field payload.On which means your payload is an Object, not a number. So you cannot compare any object to a number and get a truthy value.

Also, if you click onobject in the debug pane it will expand it so you can see what is there.

Hi,

you pointed me to the solution. I wanted to set the msg.payload.On to true. So a simple "=" solved it...

Thank you very much!

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