29 lines
969 B
JavaScript
29 lines
969 B
JavaScript
module.exports = function(RED) {
|
|
function httpdomooutonoff(config) {
|
|
RED.nodes.createNode(this,config);
|
|
this.idx = parseInt(config.idx, 10);
|
|
var flowContext = this.context().flow;
|
|
var node = this;
|
|
node.on('input', function(msg) {
|
|
if (node.idx === 'undefined' || isNaN(node.idx) || node.idx === null || node.idx === "" ) {
|
|
node.error("IDX not set");
|
|
return;
|
|
}
|
|
var setstat = msg.payload;
|
|
if (setstat === true) {
|
|
var newstat = "On";
|
|
} else if (setstat === false) {
|
|
var newstat = "Off";
|
|
}
|
|
msg.payload = {
|
|
"idx": node.idx,
|
|
"type": "command",
|
|
"param": "switchlight",
|
|
"switchcmd": newstat
|
|
};
|
|
node.send(msg);
|
|
});
|
|
}
|
|
RED.nodes.registerType("http-domo-out-onoff",httpdomooutonoff);
|
|
}
|