diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d52e73d --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +################################################################################ +# This .gitignore file was automatically created by Microsoft(R) Visual Studio. +################################################################################ + +/.vs/node-red-contib-domoticzconverter/v16 +/.vs diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 03a4893..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,2 +0,0 @@ -# node-red-contib-domoticzconverter - diff --git a/http-domo-out/hoBrightConv.html b/http-domo-out/hoBrightConv.html new file mode 100644 index 0000000..bd32e8e --- /dev/null +++ b/http-domo-out/hoBrightConv.html @@ -0,0 +1,32 @@ + + + + + diff --git a/http-domo-out/hoBrightConv.js b/http-domo-out/hoBrightConv.js new file mode 100644 index 0000000..893e87b --- /dev/null +++ b/http-domo-out/hoBrightConv.js @@ -0,0 +1,23 @@ +module.exports = function(RED) { + function httpdomooutbright(config) { + RED.nodes.createNode(this,config); + this.idx = parseInt(config.idx, 10); + 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 newbright = msg.payload; + msg.payload = { + "idx": node.idx, + "level": newbright, + "type": "command", + "param": "switchlight", + "switchcmd": "Set Level" + }; + node.send(msg); + }); + } + RED.nodes.registerType("http-domo-out-bright",httpdomooutbright); +} diff --git a/http-domo-out/hoOnOffConv.html b/http-domo-out/hoOnOffConv.html new file mode 100644 index 0000000..a2e372f --- /dev/null +++ b/http-domo-out/hoOnOffConv.html @@ -0,0 +1,32 @@ + + + + + diff --git a/http-domo-out/hoOnOffConv.js b/http-domo-out/hoOnOffConv.js new file mode 100644 index 0000000..0494af8 --- /dev/null +++ b/http-domo-out/hoOnOffConv.js @@ -0,0 +1,28 @@ +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); +} diff --git a/http-domo-out/hoRGBConv.html b/http-domo-out/hoRGBConv.html new file mode 100644 index 0000000..f3c3f8b --- /dev/null +++ b/http-domo-out/hoRGBConv.html @@ -0,0 +1,32 @@ + + + + + diff --git a/http-domo-out/hoRGBConv.js b/http-domo-out/hoRGBConv.js new file mode 100644 index 0000000..051f9c6 --- /dev/null +++ b/http-domo-out/hoRGBConv.js @@ -0,0 +1,33 @@ +module.exports = function(RED) { + function httpdomooutrgb(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 flowbrightness = flowContext.get(node.idx + "-brightness") + if (flowbrightness === 'undefined' || isNaN(flowbrightness) || flowbrightness === null || flowbrightness === "" ) { + node.warn("Brightness for this device is not defined in the flow, Setting to 100"); + var curbrightness = 100 + } else { + var curbrightness = flowbrightness + } + + var newcolor = msg.payload; + msg.payload = { + "idx": node.idx, + "hex": newcolor, + "brightness": curbrightness, + "type": "command", + "param": "setcolbrightnessvalue", + "iswhite": false + }; + node.send(msg); + }); + } + RED.nodes.registerType("http-domo-out-rgb",httpdomooutrgb); +} diff --git a/mqtt-domo-in/icons/domo.png b/mqtt-domo-in/icons/domo.png new file mode 100644 index 0000000..1a6d3ec Binary files /dev/null and b/mqtt-domo-in/icons/domo.png differ diff --git a/mqtt-domo-in/miBrightConv.html b/mqtt-domo-in/miBrightConv.html new file mode 100644 index 0000000..5d760be --- /dev/null +++ b/mqtt-domo-in/miBrightConv.html @@ -0,0 +1,37 @@ + + + + + diff --git a/mqtt-domo-in/miBrightConv.js b/mqtt-domo-in/miBrightConv.js new file mode 100644 index 0000000..e9a4071 --- /dev/null +++ b/mqtt-domo-in/miBrightConv.js @@ -0,0 +1,21 @@ +module.exports = function(RED) { + function mqttdomoinbright(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) { + msg.payload = msg.payload.Level; + 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 + "-brightness", msg.payload) + } + } + }); + } + RED.nodes.registerType("mqtt-domo-in-bright",mqttdomoinbright); +} diff --git a/mqtt-domo-in/miOnOffConv.html b/mqtt-domo-in/miOnOffConv.html new file mode 100644 index 0000000..a9d5736 --- /dev/null +++ b/mqtt-domo-in/miOnOffConv.html @@ -0,0 +1,37 @@ + + + + + diff --git a/mqtt-domo-in/miOnOffConv.js b/mqtt-domo-in/miOnOffConv.js new file mode 100644 index 0000000..56be26f --- /dev/null +++ b/mqtt-domo-in/miOnOffConv.js @@ -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); +} diff --git a/mqtt-domo-in/miRGBConv.html b/mqtt-domo-in/miRGBConv.html new file mode 100644 index 0000000..0b2c440 --- /dev/null +++ b/mqtt-domo-in/miRGBConv.html @@ -0,0 +1,37 @@ + + + + + diff --git a/mqtt-domo-in/miRGBConv.js b/mqtt-domo-in/miRGBConv.js new file mode 100644 index 0000000..32b8515 --- /dev/null +++ b/mqtt-domo-in/miRGBConv.js @@ -0,0 +1,29 @@ +module.exports = function(RED) { + function mqttdomoinrgb(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 r = msg.payload.Color.r; + var g = msg.payload.Color.g; + var b = msg.payload.Color.b; + function componentToHex(c) { + var hex = c.toString(16); + return hex.length == 1 ? "0" + hex : hex; + } + msg.payload = "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); + 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 + "-color", msg.payload) + } + } + }); + } + RED.nodes.registerType("mqtt-domo-in-rgb",mqttdomoinrgb); +} diff --git a/mqtt-domo-in/miTempConv.html b/mqtt-domo-in/miTempConv.html new file mode 100644 index 0000000..3340565 --- /dev/null +++ b/mqtt-domo-in/miTempConv.html @@ -0,0 +1,32 @@ + + + + + diff --git a/mqtt-domo-in/miTempConv.js b/mqtt-domo-in/miTempConv.js new file mode 100644 index 0000000..e22f9f0 --- /dev/null +++ b/mqtt-domo-in/miTempConv.js @@ -0,0 +1,16 @@ +module.exports = function(RED) { + function mqttdomointemp(config) { + RED.nodes.createNode(this,config); + this.sname = config.sname; + var node = this; + node.on('input', function(msg) { + msg.payload = msg.payload.svalue1; + if (node.sname === 'undefined' || node.sname === null || node.sname === "" ) { + } else{ + msg.topic = node.sname + } + node.send(msg); + }); + } + RED.nodes.registerType("mqtt-domo-in-temp",mqttdomointemp); +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..a95086f --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name" : "node-red-contib-domoticzconverter", + "version" : "0.0.3", + "description" : "Domoticz converter for use with dashboard", + "dependencies" : {} , + "node-red" : { + "nodes": { + "domo-mmqtt-in-rgb": "mqtt-domo-in/miRGBConv.js", + "domo-mmqtt-in-onoff": "mqtt-domo-in/miOnOffConv.js", + "domo-mmqtt-in-temp": "mqtt-domo-in/miTempConv.js", + "domo-mmqtt-in-bright": "mqtt-domo-in/miBrightConv.js", + "domo-http-out-bright": "http-domo-out/hoOnOffConv.js", + "domo-http-out-onoff": "http-domo-out/hoBrightConv.js", + "domo-http-out-rgb": "http-domo-out/hoRGBConv.js" + + } + } +} diff --git a/package.json.bck b/package.json.bck new file mode 100644 index 0000000..3f2314d --- /dev/null +++ b/package.json.bck @@ -0,0 +1,18 @@ +{ + "name" : "node-red-contib-domoticzconverter", + "version" : "0.0.3", + "description" : "Domoticz converter for use with dashboard", + "dependencies" : {} , + "node-red" : { + "nodes": { + "domommqttin-rgb": "mqtt-domo-in/miRGBConv.js", + "domommqttin-onoff": "mqtt-domo-in/miOnOffConv.js", + "domommqttin-temp": "mqtt-domo-in/miTempConv.js", + "domommqttin-bright": "mqtt-domo-in/miBrightConv.js", + "domohttpout-bright": "http-domo-out/hoOnOffConv.js", + "domohttpout-onoff": "http-domo-out/hoBrightConv.js", + "domohttpout-rgb": "http-domo-out/hoRGBConv.js" + + } + } +}