I am using the WeMo node plugin for Node Red with a WeMo switch.
Using the "WeMo Lookup" function I receive the following message payload:
2/8/2018, 12:30:34 PMnode: 6dece90e.84b898 WemoCheck : msg.payload : Object { state: 1 }
From what I understand, I should use the JSON Function to obtain the actual value. Using the JSON function with the format option enabled I receive the following message payload:
2/8/2018, 12:41:11 PMnode: 5ae2b7bf.1e0e98 WemoCheck : msg.payload : string[18] "{↵ "state": 1↵}"
I believe this is the desired result.
However I cannot obtain just the value using a function. I have tried the following two and both return "msg.payload : undefined"
var value = msg.payload[0].state;
msg.payload = value;
return msg;
or
var value = msg.payload.state;
msg.payload = value;
return msg;
I think I might be missing something obvious. Any assistance would be appreciated.
You don't need to use the JSON node at all, the output is already a JSON object.
If you just want the payload to be 1 or 0 from the state value then your second version of your function node should work (even if it has an extra un needed step).
msg.payload = msg.payload.state;
return msg;
You shouldn't need a function node to do this, the change node will let you move values around with something like this