Added Content
This commit is contained in:
26
mqtt-domo-in/miOnOffConv.js
Normal file
26
mqtt-domo-in/miOnOffConv.js
Normal file
@@ -0,0 +1,26 @@
|
||||
module.exports = function(RED) {
|
||||
function mqttdomoinonoff(config) {
|
||||
RED.nodes.createNode(this,config);
|
||||
this.idx = config.idx;
|
||||
this.Savetocontex = config.Savetocontex;
|
||||
var flowContext = this.context().flow;
|
||||
var node = this;
|
||||
node.on('input', function(msg) {
|
||||
var stat = msg.payload.nvalue;
|
||||
if (stat === 0) {
|
||||
msg.payload = false;
|
||||
} else {
|
||||
msg.payload = true;
|
||||
}
|
||||
node.send(msg);
|
||||
if (node.Savetocontex === true) {
|
||||
if (node.idx === 'undefined' || node.idx === null || node.idx === "" ) {
|
||||
node.warn("IDX not set");
|
||||
} else{
|
||||
flowContext.set(node.idx + "-state", msg.payload)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("mqtt-domo-in-onoff",mqttdomoinonoff);
|
||||
}
|
||||
Reference in New Issue
Block a user