I need a sanity check

I think I'm either going nuts or I'm missing something obvious. I have a relay board that returns a string 0 or 1 based on the relay state. I'm trying to convert the "int" to on/off and pass it as the payload to a switch.

For some reason I can't get the function node to convert this correctly.

Function Node:
image

Output from the exec node that is passed to the function node above:
image

Hard to tell with those screen shots & without seeing the whole flow i can only guess. Perhaps msg.payload has a newline or other non printable character in it? - meaning msg.payload != "0"

e.g...

TcEQLrjM5r

You could try trimming before checking...

var pl = msg.payload.trim()
if(pl == "0" )
  msg.payload = "off"
else if(pl == "1" )
  msg.payload = "on"
return msg;

EDIT...
if necessary, check payload is a string before calling trim
e.g.

if(typeof msg.payload == "string")
  // ok, its a string - to a trim()

Trim did it. I knew it was something simple I was missing. Thanks