I am trying to control a device and create a generic function that can take a topic with the device name and a payload with ON or OFF but I can't seem to figure out the code for this. I am trying to pass this to an alex.remote2 custom routine node set to custom and msg.payload as the data input.
I have the following in the function:
var state = msg.payload.toUpperCase();
var device = msg.topic;
msg = {};
if(state==="ON")
{
msg.payload={type: "smarthome", payload: {entity: [device], action: "turnOn"}};
node.status({fill:"green",shape:"ring",text:"ON"});
}
else
{
msg.payload={type: "smarthome", payload: {entity: [device], action: "turnOff"}};
node.status({fill:"red",shape:"ring",text:"OFF"});
}
return msg;
I get the following in the debug output:
invalid sequence node: "{"type":"smarthome","payload":{"entity":["Front room fan"],"action":"turnOff"}}" expected layout: "{"entity":"","action":""}"
This is what I output from the function:
{"payload":{"type":"smarthome","payload":{"entity":["Front room fan"],"action":"turnOn"}},"_msgid":"c028a4cd.8e16d8"}
Any ideas where I am going wrong?