Added magnet
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('xiaomi-ht', {
|
||||
category: 'function',
|
||||
color: '#a6bbcf',
|
||||
category: 'xiaomi',
|
||||
color: '#3FADB5',
|
||||
defaults: {
|
||||
gateway: {value:"", type:"xiaomi-configurator"},
|
||||
name: {value: ""},
|
||||
@@ -13,6 +13,7 @@
|
||||
inputs: 1,
|
||||
outputs: 2,
|
||||
outputLabels: ["Temperature","Humidity"],
|
||||
paletteLabel: "sensor HT",
|
||||
icon: "thermometer-icon.png",
|
||||
label: function () {
|
||||
return this.name || "xiaomi-ht";
|
||||
|
||||
BIN
node-red-contrib-xiaomi-magnet/icons/door-icon.png
Normal file
BIN
node-red-contrib-xiaomi-magnet/icons/door-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.6 KiB |
BIN
node-red-contrib-xiaomi-magnet/icons/outlet-icon.png
Normal file
BIN
node-red-contrib-xiaomi-magnet/icons/outlet-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
89
node-red-contrib-xiaomi-magnet/xiaomi-magnet.html
Normal file
89
node-red-contrib-xiaomi-magnet/xiaomi-magnet.html
Normal file
@@ -0,0 +1,89 @@
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('xiaomi-magnet', {
|
||||
category: 'xiaomi',
|
||||
color: '#3FADB5',
|
||||
defaults: {
|
||||
gateway: {value:"", type:"xiaomi-configurator"},
|
||||
name: {value: ""},
|
||||
sid: {value: "", required: true},
|
||||
openmsg: {value: ""},
|
||||
closemsg: {value: ""},
|
||||
output: {value: "0"}
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 1,
|
||||
outputLabels: ["Status"],
|
||||
paletteLabel: "contact",
|
||||
icon: "door-icon.png",
|
||||
label: function () {
|
||||
return this.name || "xiaomi-magnet";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var node = this;
|
||||
|
||||
// Get the config node id from the select box:
|
||||
var configNodeID = $('#node-input-gateway').val();
|
||||
// Get the config node using the ID:
|
||||
var configNode = RED.nodes.node(configNodeID);
|
||||
|
||||
$("#node-input-output").change(function () {
|
||||
if ($(this).val() == "2") {
|
||||
$(".node-input-msg").show();
|
||||
} else {
|
||||
$(".node-input-msg").hide();
|
||||
}
|
||||
});
|
||||
|
||||
$("#node-input-gateway").change(function () {
|
||||
|
||||
});
|
||||
|
||||
for (key in configNode.deviceList) {
|
||||
var device = configNode.deviceList[key];
|
||||
if (device.model === "magnet") {
|
||||
$('#node-input-sid').append('<option value="' + device.sid + '">' + device.desc + '</option>');
|
||||
}
|
||||
}
|
||||
$('#node-input-sid').val(node.sid);
|
||||
},
|
||||
oneditsave: function() {
|
||||
var node = this;
|
||||
node.sid = $("#node-input-sid").val();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="xiaomi-magnet">
|
||||
<div class="form-row">
|
||||
<label for="node-input-gateway"><i class="icon-tag"></i> Gateway</label>
|
||||
<input type="text" id="node-input-gateway" placeholder="xiaomi gateway">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-sid"><i class="icon-tag"></i> Device</label>
|
||||
<select id="node-input-sid" placeholder="xiaomi gateway"></select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-output"><i class="icon-tag"></i> Output</label>
|
||||
<select id="node-input-output" style="width:70%;">
|
||||
<option value="0">Full data</option>
|
||||
<option value="1">Just values</option>
|
||||
<option value="2">Template</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row node-input-msg">
|
||||
<label for="node-input-openmsg"><i class="fa fa-power-off"></i> Open msg</label>
|
||||
<input type="text" id="node-input-openmsg">
|
||||
</div>
|
||||
<div class="form-row node-input-msg">
|
||||
<label for="node-input-closemsg"><i class="fa fa-power-off"></i> Close msg</label>
|
||||
<input type="text" id="node-input-closemsg">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="xiaomi-magnet">
|
||||
<p>A simple node that converts the message payloads into a ON or OFF message</p>
|
||||
</script>
|
||||
80
node-red-contrib-xiaomi-magnet/xiaomi-magnet.js
Normal file
80
node-red-contrib-xiaomi-magnet/xiaomi-magnet.js
Normal file
@@ -0,0 +1,80 @@
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var mustache = require("mustache");
|
||||
|
||||
function XiaomiMagnetNode(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
this.gateway = RED.nodes.getNode(config.gateway);
|
||||
this.sid = config.sid;
|
||||
this.output = config.output;
|
||||
this.openmsg = config.openmsg;
|
||||
this.closemsg = config.closemsg;
|
||||
|
||||
var node = this;
|
||||
var state = "";
|
||||
|
||||
// node.status({fill:"yellow", shape:"dot", text:"unknown state"});
|
||||
node.status({fill:"grey",shape:"ring",text:"battery"});
|
||||
|
||||
if (this.gateway) {
|
||||
node.on('input', function(msg) {
|
||||
// var payload = JSON.parse(msg);
|
||||
var payload = msg.payload;
|
||||
|
||||
if (payload.sid == node.sid && payload.model == "magnet") {
|
||||
var data = JSON.parse(payload.data)
|
||||
|
||||
// if (data.status && data.status == "open") {
|
||||
// node.status({fill:"green", shape:"dot", text:"open"});
|
||||
// state = "open";
|
||||
// } else if (data.status && data.status == "close") {
|
||||
// node.status({fill:"red", shape:"dot", text:"closed"});
|
||||
// state = "closed";
|
||||
// }
|
||||
|
||||
if (data.voltage) {
|
||||
if (data.voltage < 2500) {
|
||||
node.status({fill:"red",shape:"dot",text:"battery"});
|
||||
} else if (data.voltage < 2900) {
|
||||
node.status({fill:"yellow",shape:"dot",text:"battery"});
|
||||
} else {
|
||||
node.status({fill:"green",shape:"dot",text:"battery"});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (node.output == "0") {
|
||||
msg.payload = payload;
|
||||
node.send([msg]);
|
||||
} else if (node.output == "1") {
|
||||
var status = null;
|
||||
|
||||
if (data.status) {
|
||||
status = {"payload": data.status};
|
||||
}
|
||||
node.send([status]);
|
||||
} else if (node.output == "2") {
|
||||
var status = null;
|
||||
|
||||
if (data.status === 'open') {
|
||||
status = {"payload": mustache.render(node.openmsg, data)}
|
||||
} else {
|
||||
status = {"payload": mustache.render(node.closemsg, data)}
|
||||
}
|
||||
node.send([status]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
node.on("close", function() {
|
||||
});
|
||||
|
||||
} else {
|
||||
// no gateway configured
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RED.nodes.registerType("xiaomi-magnet", XiaomiMagnetNode);
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('xiaomi-plug', {
|
||||
category: 'function',
|
||||
color: '#a6bbcf',
|
||||
category: 'xiaomi',
|
||||
color: '#3FADB5',
|
||||
defaults: {
|
||||
gateway: {value:"", type:"xiaomi-configurator"},
|
||||
name: {value: ""},
|
||||
@@ -13,6 +13,7 @@
|
||||
inputs: 1,
|
||||
outputs: 2,
|
||||
outputLabels: ["Status","Control"],
|
||||
paletteLabel: "plug (zigbee)",
|
||||
icon: "outlet-icon.png",
|
||||
label: function () {
|
||||
return this.name || "xiaomi-plug";
|
||||
|
||||
BIN
node-red-contrib-xiaomi-switch/icons/light-icon.png
Normal file
BIN
node-red-contrib-xiaomi-switch/icons/light-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
93
node-red-contrib-xiaomi-switch/xiaomi-switch.html
Normal file
93
node-red-contrib-xiaomi-switch/xiaomi-switch.html
Normal file
@@ -0,0 +1,93 @@
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('xiaomi-switch', {
|
||||
category: 'xiaomi',
|
||||
color: '#3FADB5',
|
||||
defaults: {
|
||||
gateway: {value:"", type:"xiaomi-configurator"},
|
||||
name: {value: ""},
|
||||
sid: {value: "", required: true},
|
||||
outmsg: {value: "{{click}}"},
|
||||
outmsgdbcl: {value: "{{double_click}}"},
|
||||
output: {value: "0"}
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 2,
|
||||
outputLabels: ["Single-click", "Double-click"],
|
||||
paletteLabel: "switch",
|
||||
icon: "light-icon.png",
|
||||
label: function () {
|
||||
return this.name || "xiaomi-switch";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var node = this;
|
||||
|
||||
// Get the config node id from the select box:
|
||||
var configNodeID = $('#node-input-gateway').val();
|
||||
// Get the config node using the ID:
|
||||
var configNode = RED.nodes.node(configNodeID);
|
||||
|
||||
$("#node-input-output").change(function () {
|
||||
if ($(this).val() == "2") {
|
||||
$(".node-input-msg").show();
|
||||
} else {
|
||||
$(".node-input-msg").hide();
|
||||
}
|
||||
});
|
||||
|
||||
$(".node-input-msg").hide();
|
||||
$("#node-input-output").val(node.output);
|
||||
|
||||
$("#node-input-gateway").change(function () {
|
||||
|
||||
});
|
||||
|
||||
for (key in configNode.deviceList) {
|
||||
var device = configNode.deviceList[key];
|
||||
if (device.model === "switch") {
|
||||
$('#node-input-sid').append('<option value="' + device.sid + '">' + device.desc + '</option>');
|
||||
}
|
||||
}
|
||||
$('#node-input-sid').val(node.sid);
|
||||
},
|
||||
oneditsave: function() {
|
||||
var node = this;
|
||||
node.sid = $("#node-input-sid").val();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="xiaomi-switch">
|
||||
<div class="form-row">
|
||||
<label for="node-input-gateway"><i class="icon-tag"></i> Gateway</label>
|
||||
<input type="text" id="node-input-gateway" placeholder="xiaomi gateway">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-sid"><i class="icon-tag"></i> Device</label>
|
||||
<select id="node-input-sid" placeholder="xiaomi gateway"></select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-output"><i class="icon-tag"></i> Output</label>
|
||||
<select id="node-input-output" style="width:70%;">
|
||||
<option value="0">Full data</option>
|
||||
<option value="1">Just values</option>
|
||||
<option value="2">Template</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row node-input-msg">
|
||||
<label for="node-input-outmsg"><i class="fa fa-hand-pointer-o"></i> Single-click</label>
|
||||
<input type="text" id="node-input-outmsg">
|
||||
</div>
|
||||
<div class="form-row node-input-msg">
|
||||
<label for="node-input-outmsgdbcl"><i class="fa fa-hand-peace-o"></i> Double-click</label>
|
||||
<input type="text" id="node-input-outmsgdbcl">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="xiaomi-ht">
|
||||
<p>A simple node that converts the message payloads from a switch into an output message</p>
|
||||
|
||||
</script>
|
||||
72
node-red-contrib-xiaomi-switch/xiaomi-switch.js
Normal file
72
node-red-contrib-xiaomi-switch/xiaomi-switch.js
Normal file
@@ -0,0 +1,72 @@
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var mustache = require("mustache");
|
||||
|
||||
function XiaomiSwitchNode(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
this.gateway = RED.nodes.getNode(config.gateway);
|
||||
this.sid = config.sid;
|
||||
this.output = config.output;
|
||||
this.outmsg = config.outmsg;
|
||||
this.outmsgdbcl = config.outmsgdbcl;
|
||||
|
||||
var node = this;
|
||||
|
||||
node.status({fill:"grey",shape:"ring",text:"battery"});
|
||||
|
||||
if (this.gateway) {
|
||||
node.on('input', function(msg) {
|
||||
// var payload = JSON.parse(msg);
|
||||
var payload = msg.payload;
|
||||
|
||||
if (payload.sid == node.sid && payload.model == "switch") {
|
||||
var data = JSON.parse(payload.data)
|
||||
|
||||
if (data.voltage) {
|
||||
if (data.voltage < 2500) {
|
||||
node.status({fill:"red",shape:"dot",text:"battery"});
|
||||
} else if (data.voltage < 2900) {
|
||||
node.status({fill:"yellow",shape:"dot",text:"battery"});
|
||||
} else {
|
||||
node.status({fill:"green",shape:"dot",text:"battery"});
|
||||
}
|
||||
}
|
||||
|
||||
if (node.output == "0") {
|
||||
msg.payload = payload;
|
||||
node.send([msg]);
|
||||
} else if (node.output == "1") {
|
||||
var status = null;
|
||||
|
||||
if (data.status) {
|
||||
status = {"payload": data.status};
|
||||
}
|
||||
node.send([status]);
|
||||
} else if (node.output == "2") {
|
||||
var status = null;
|
||||
|
||||
if (data.status && data.status == "click") {
|
||||
status = {"payload": mustache.render(node.outmsg, data)}
|
||||
node.send([[status],[]]);
|
||||
}
|
||||
|
||||
if (data.status && data.status == "double_click") {
|
||||
status = {"payload": mustache.render(node.outmsgdbcl, data)}
|
||||
node.send([[],[status]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
node.on("close", function() {
|
||||
});
|
||||
|
||||
} else {
|
||||
// no gateway configured
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RED.nodes.registerType("xiaomi-switch", XiaomiSwitchNode);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user