@@ -4,7 +4,9 @@
|
|||||||
color: '#3FADB5',
|
color: '#3FADB5',
|
||||||
defaults: {
|
defaults: {
|
||||||
gateway: {value:"", type:"xiaomi-configurator"},
|
gateway: {value:"", type:"xiaomi-configurator"},
|
||||||
name: {value: ""}
|
name: {value: ""},
|
||||||
|
onlyModels: {value: []},
|
||||||
|
excludedSids: { value: []}
|
||||||
},
|
},
|
||||||
inputs: 1,
|
inputs: 1,
|
||||||
outputs: 1,
|
outputs: 1,
|
||||||
@@ -13,6 +15,44 @@
|
|||||||
icon: "mi-all.png",
|
icon: "mi-all.png",
|
||||||
label: function () {
|
label: function () {
|
||||||
return this.name || "xiaomi-all";
|
return this.name || "xiaomi-all";
|
||||||
|
},
|
||||||
|
oneditprepare: function() {
|
||||||
|
var node = this;
|
||||||
|
|
||||||
|
function changeGateway(gateway, onlyModels, excludedSids) {
|
||||||
|
var configNodeID = gateway || $('#node-input-gateway').val();
|
||||||
|
if (configNodeID) {
|
||||||
|
var configNode = RED.nodes.node(configNodeID);
|
||||||
|
if(configNode) {
|
||||||
|
onlyModels = onlyModels || $('#node-input-onlyModels').val() || [];
|
||||||
|
excludedSids = excludedSids || $('#node-input-excludedSids').val() || [];
|
||||||
|
$('#node-input-excludedSids').empty();
|
||||||
|
for (key in configNode.deviceList) {
|
||||||
|
var device = configNode.deviceList[key];
|
||||||
|
if (onlyModels.length == 0 || onlyModels.indexOf(device.model) >= 0) {
|
||||||
|
var option = $('<option value="' + device.sid + '">' + device.desc + '</option>');
|
||||||
|
if(excludedSids && excludedSids.indexOf(device.sid) >= 0) {
|
||||||
|
option.prop('selected', true);
|
||||||
|
}
|
||||||
|
$('#node-input-excludedSids').append(option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
changeGateway(this.gateway, this.onlyModels, this.excludedSids);
|
||||||
|
$("#node-input-gateway, #node-input-onlyModels").change(function () {
|
||||||
|
changeGateway();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
oneditsave: function() {
|
||||||
|
if(!$('#node-input-onlyModels').val()) {
|
||||||
|
this.onlyModels = [];
|
||||||
|
}
|
||||||
|
if(!$('#node-input-excludedSids').val()) {
|
||||||
|
this.excludedSids = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@@ -26,11 +66,35 @@
|
|||||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||||
<input type="text" id="node-input-name" placeholder="Name">
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
</div>
|
</div>
|
||||||
|
<hr />
|
||||||
|
<h5>Filters</h5>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-onlyModels"><i class="icon-tag"></i> Only</label>
|
||||||
|
<select multiple id="node-input-onlyModels">
|
||||||
|
<option value="sensor_ht">Temperature/humidty</option>
|
||||||
|
<option value="motion">Motion</option>
|
||||||
|
<option value="switch">Switches</option>
|
||||||
|
<option value="magnet">Contacts</option>
|
||||||
|
<option value="plug">Plugs</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-excludedSids"><i class="icon-tag"></i> Exclude</label>
|
||||||
|
<select multiple id="node-input-excludedSids" size=10></select>
|
||||||
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="xiaomi-all">
|
<script type="text/x-red" data-help-name="xiaomi-all">
|
||||||
<p>All devices registred in the gateway, except gateway itself.</p>
|
<p>All devices registred in the gateway, except gateway itself.</p>
|
||||||
|
|
||||||
|
<h3>Inputs</h3>
|
||||||
|
<dl class="message-properties">
|
||||||
|
<dt>payload
|
||||||
|
<span class="property-type">object</span>
|
||||||
|
</dt>
|
||||||
|
<dd>When use as an incoming filter node, <code>sid</code> and <code>model</code> are mandatory.</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
<h3>Outputs</h3>
|
<h3>Outputs</h3>
|
||||||
<ol class="node-ports">
|
<ol class="node-ports">
|
||||||
<li>Devices output
|
<li>Devices output
|
||||||
|
|||||||
@@ -1,11 +1,39 @@
|
|||||||
module.exports = (RED) => {
|
module.exports = (RED) => {
|
||||||
|
|
||||||
|
|
||||||
function XiaomiAllNode(config) {
|
function XiaomiAllNode(config) {
|
||||||
RED.nodes.createNode(this, config);
|
RED.nodes.createNode(this, config);
|
||||||
this.gateway = RED.nodes.getNode(config.gateway);
|
this.gateway = RED.nodes.getNode(config.gateway);
|
||||||
|
this.onlyModels = config.onlyModels;
|
||||||
|
this.excludedSids = config.excludedSids;
|
||||||
|
|
||||||
|
|
||||||
|
this.isDeviceValid = (device) => {
|
||||||
|
if((!this.onlyModels || this.onlyModels.length == 0) && (!this.excludedSids || this.excludedSids.length == 0)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if((this.excludedSids && this.excludedSids.length != 0) && this.excludedSids.indexOf(device.sid) >= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if((this.onlyModels && this.onlyModels.length != 0) && this.onlyModels.indexOf(device.model) >= 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.gateway) {
|
if (this.gateway) {
|
||||||
this.on('input', (msg) => {
|
this.on('input', (msg) => {
|
||||||
msg.payload = this.gateway.deviceList;
|
// Filter input
|
||||||
|
if(msg.payload.model && msg.payload.sid) {
|
||||||
|
if(!this.isDeviceValid(msg.payload)) {
|
||||||
|
msg = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Prepare for request
|
||||||
|
else {
|
||||||
|
msg.payload = this.gateway.deviceList.filter((device) => this.isDeviceValid(device));
|
||||||
|
}
|
||||||
this.send(msg);
|
this.send(msg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,8 +48,6 @@
|
|||||||
$("#node-input-gateway").change(function () {
|
$("#node-input-gateway").change(function () {
|
||||||
changeGateway("sensor_ht");
|
changeGateway("sensor_ht");
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".node-input-msg").hide();
|
|
||||||
},
|
},
|
||||||
oneditsave: function() {
|
oneditsave: function() {
|
||||||
var node = this;
|
var node = this;
|
||||||
@@ -79,21 +77,31 @@
|
|||||||
<h3>Inputs</h3>
|
<h3>Inputs</h3>
|
||||||
<dl class="message-properties">
|
<dl class="message-properties">
|
||||||
<dt>payload
|
<dt>payload
|
||||||
<span class="property-type">json</span>
|
<span class="property-type">object</span>
|
||||||
</dt>
|
</dt>
|
||||||
<dd>Gateway <code>sensor_ht</code> and <code>weather.v1</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code></dd>
|
<dd>
|
||||||
|
When the message contains a <code>sid</code> field, the node will filter the input and output only if the <code>sid</code> is the device's sid.<br>
|
||||||
|
<hr>
|
||||||
|
If the message doesn't contain a <code>sid</code> field, the node will be used to inject <code>sid</code> and <code>gateway</code> fields in the incoming <code>msg</code>.<br>
|
||||||
|
<hr>
|
||||||
|
Input Gateway node produces message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code>.
|
||||||
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<h3>Outputs</h3>
|
<h3>Outputs</h3>
|
||||||
<ol class="node-ports">
|
<ol class="node-ports">
|
||||||
<dl class="message-properties">
|
<dl class="message-properties">
|
||||||
<dt>payload <span class="property-type">object</span></dt>
|
<dt>payload <span class="property-type">object</span></dt>
|
||||||
<dd>Data from gateway, see below.</dd>
|
<dd>Data from gateway when used as a filter (see below).</dd>
|
||||||
|
<dt>sid <span class="property-type">string</span></dt>
|
||||||
|
<dd>Device SID.</dd>
|
||||||
|
<dt>gateway <span class="property-type">object</span></dt>
|
||||||
|
<dd>The <code>xiaomi-configurator</code> object where the device is registred.</dd>
|
||||||
</dl>
|
</dl>
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<h4>Details</h4>
|
<h4>Details</h4>
|
||||||
<p>The incoming message is processed if the <code>sid</code> matches the configured value for this device.</p>
|
<p>The incoming message is processed if the input <code>sid</code> matches the configured value for this device.</p>
|
||||||
<p>Sample payload from Aqara (which brings pressure):</p>
|
<p>Sample payload from Aqara (which brings pressure):</p>
|
||||||
<p><pre>{
|
<p><pre>{
|
||||||
cmd: "read_ack"
|
cmd: "read_ack"
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
const miDevicesUtils = require('../src/utils');
|
const miDevicesUtils = require('../src/utils');
|
||||||
|
|
||||||
module.exports = (RED) => {
|
module.exports = (RED) => {
|
||||||
|
// sensor_ht, weather.v1
|
||||||
|
|
||||||
function XiaomiHtNode(config) {
|
function XiaomiHtNode(config) {
|
||||||
RED.nodes.createNode(this, config);
|
RED.nodes.createNode(this, config);
|
||||||
this.gateway = RED.nodes.getNode(config.gateway);
|
this.gateway = RED.nodes.getNode(config.gateway);
|
||||||
|
|||||||
@@ -77,21 +77,31 @@
|
|||||||
<h3>Inputs</h3>
|
<h3>Inputs</h3>
|
||||||
<dl class="message-properties">
|
<dl class="message-properties">
|
||||||
<dt>payload
|
<dt>payload
|
||||||
<span class="property-type">json</span>
|
<span class="property-type">object</span>
|
||||||
</dt>
|
</dt>
|
||||||
<dd>Gateway <code>magnet</code> and <code>sensor_magnet.aq2</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code></dd>
|
<dd>
|
||||||
|
When the message contains a <code>sid</code> field, the node will filter the input and output only if the <code>sid</code> is the device's sid.<br>
|
||||||
|
<hr>
|
||||||
|
If the message doesn't contain a <code>sid</code> field, the node will be used to inject <code>sid</code> and <code>gateway</code> fields in the incoming <code>msg</code>.<br>
|
||||||
|
<hr>
|
||||||
|
Input Gateway node produces message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code>.
|
||||||
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<h3>Outputs</h3>
|
<h3>Outputs</h3>
|
||||||
<ol class="node-ports">
|
<ol class="node-ports">
|
||||||
<dl class="message-properties">
|
<dl class="message-properties">
|
||||||
<dt>payload <span class="property-type">object</span></dt>
|
<dt>payload <span class="property-type">object</span></dt>
|
||||||
<dd>Data from gateway, see below.</dd>
|
<dd>Data from gateway when used as a filter (see below).</dd>
|
||||||
|
<dt>sid <span class="property-type">string</span></dt>
|
||||||
|
<dd>Device SID.</dd>
|
||||||
|
<dt>gateway <span class="property-type">object</span></dt>
|
||||||
|
<dd>The <code>xiaomi-configurator</code> object where the device is registred.</dd>
|
||||||
</dl>
|
</dl>
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<h3>Details</h3>
|
<h4>Details</h4>
|
||||||
<p>The incoming message is processed if the <code>sid</code> matches the configured value for this device.</p>
|
<p>The incoming message is processed if the input <code>sid</code> matches the configured value for this device.</p>
|
||||||
<p>Sample message:</p>
|
<p>Sample message:</p>
|
||||||
<p><pre>{
|
<p><pre>{
|
||||||
cmd: "read_ack"
|
cmd: "read_ack"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const miDevicesUtils = require('../src/utils');
|
const miDevicesUtils = require('../src/utils');
|
||||||
|
|
||||||
module.exports = (RED) => {
|
module.exports = (RED) => {
|
||||||
|
// magnet, sensor_magnet.aq2
|
||||||
function XiaomiMagnetNode(config) {
|
function XiaomiMagnetNode(config) {
|
||||||
miDevicesUtils.defaultNode(RED, config, this);
|
miDevicesUtils.defaultNode(RED, config, this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,21 +80,31 @@
|
|||||||
<h3>Inputs</h3>
|
<h3>Inputs</h3>
|
||||||
<dl class="message-properties">
|
<dl class="message-properties">
|
||||||
<dt>payload
|
<dt>payload
|
||||||
<span class="property-type">json</span>
|
<span class="property-type">object</span>
|
||||||
</dt>
|
</dt>
|
||||||
<dd>Gateway <code>motion</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code></dd>
|
<dd>
|
||||||
|
When the message contains a <code>sid</code> field, the node will filter the input and output only if the <code>sid</code> is the device's sid.<br>
|
||||||
|
<hr>
|
||||||
|
If the message doesn't contain a <code>sid</code> field, the node will be used to inject <code>sid</code> and <code>gateway</code> fields in the incoming <code>msg</code>.<br>
|
||||||
|
<hr>
|
||||||
|
Input Gateway node produces message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code>.
|
||||||
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<h3>Outputs</h3>
|
<h3>Outputs</h3>
|
||||||
<ol class="node-ports">
|
<ol class="node-ports">
|
||||||
<dl class="message-properties">
|
<dl class="message-properties">
|
||||||
<dt>payload <span class="property-type">object</span></dt>
|
<dt>payload <span class="property-type">object</span></dt>
|
||||||
<dd>Data from gateway, see below.</dd>
|
<dd>Data from gateway when used as a filter (see below).</dd>
|
||||||
|
<dt>sid <span class="property-type">string</span></dt>
|
||||||
|
<dd>Device SID.</dd>
|
||||||
|
<dt>gateway <span class="property-type">object</span></dt>
|
||||||
|
<dd>The <code>xiaomi-configurator</code> object where the device is registred.</dd>
|
||||||
</dl>
|
</dl>
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<h4>Details</h4>
|
<h4>Details</h4>
|
||||||
<p>The incoming message is processed if the <code>sid</code> matches the configured value for this device.</p>
|
<p>The incoming message is processed if the input <code>sid</code> matches the configured value for this device.</p>
|
||||||
<p>Sample message:</p>
|
<p>Sample message:</p>
|
||||||
<p><pre>{
|
<p><pre>{
|
||||||
cmd: "read_ack"
|
cmd: "read_ack"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const miDevicesUtils = require('../src/utils');
|
const miDevicesUtils = require('../src/utils');
|
||||||
|
|
||||||
module.exports = (RED) => {
|
module.exports = (RED) => {
|
||||||
|
// motion
|
||||||
function XiaomiMotionNode(config) {
|
function XiaomiMotionNode(config) {
|
||||||
miDevicesUtils.defaultNode(RED, config, this);
|
miDevicesUtils.defaultNode(RED, config, this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,22 +20,37 @@
|
|||||||
oneditprepare: function() {
|
oneditprepare: function() {
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
// Get the config node id from the select box:
|
if(node.sid) {
|
||||||
var configNodeID = $('#node-input-gateway').val();
|
$('#node-input-sid').val(node.sid);
|
||||||
// Get the config node using the ID:
|
}
|
||||||
var configNode = RED.nodes.node(configNodeID);
|
|
||||||
|
|
||||||
$("#node-input-gateway").change(function () {
|
function changeGateway(model) {
|
||||||
|
var configNodeID = $('#node-input-gateway').val();
|
||||||
});
|
if (configNodeID) {
|
||||||
|
var configNode = RED.nodes.node(configNodeID);
|
||||||
for (key in configNode.deviceList) {
|
if(configNode) {
|
||||||
var device = configNode.deviceList[key];
|
$('#node-input-sid').empty();
|
||||||
if (device.model === "plug") {
|
for (key in configNode.deviceList) {
|
||||||
$('#node-input-sid').append('<option value="' + device.sid + '">' + device.desc + '</option>');
|
var device = configNode.deviceList[key];
|
||||||
|
if (device.model === model) {
|
||||||
|
$('#node-input-sid').append('<option value="' + device.sid + '">' + device.desc + '</option>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(node.sid) {
|
||||||
|
$('#node-input-sid option[value="' + node.sid + '"]').prop('selected', true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$('#node-input-sid').val(node.sid);
|
|
||||||
|
$("#node-input-sid").change(function () {
|
||||||
|
if(!this.name) {
|
||||||
|
$("#node-input-name").val($('#node-input-sid option:selected').text());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$("#node-input-gateway").change(function () {
|
||||||
|
changeGateway("plug");
|
||||||
|
});
|
||||||
},
|
},
|
||||||
oneditsave: function() {
|
oneditsave: function() {
|
||||||
var node = this;
|
var node = this;
|
||||||
@@ -71,7 +86,7 @@
|
|||||||
<dt>payload
|
<dt>payload
|
||||||
<span class="property-type">string | json</span>
|
<span class="property-type">string | json</span>
|
||||||
</dt>
|
</dt>
|
||||||
<dd>Gateway <code>plug</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code>. Or <code>on</code> or <code>off</code>.</dd>
|
<dd>When the node is used as filter, gateway <code>plug</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code>. Or <code>on</code> or <code>off</code>.</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<h3>Outputs</h3>
|
<h3>Outputs</h3>
|
||||||
|
|||||||
@@ -83,21 +83,31 @@
|
|||||||
<h3>Inputs</h3>
|
<h3>Inputs</h3>
|
||||||
<dl class="message-properties">
|
<dl class="message-properties">
|
||||||
<dt>payload
|
<dt>payload
|
||||||
<span class="property-type">json</span>
|
<span class="property-type">object</span>
|
||||||
</dt>
|
</dt>
|
||||||
<dd>Gateway <code>switch</code> and <code>sensor_switch.aq2</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code></dd>
|
<dd>
|
||||||
|
When the message contains a <code>sid</code> field, the node will filter the input and output only if the <code>sid</code> is the device's sid.<br>
|
||||||
|
<hr>
|
||||||
|
If the message doesn't contain a <code>sid</code> field, the node will be used to inject <code>sid</code> and <code>gateway</code> fields in the incoming <code>msg</code>.<br>
|
||||||
|
<hr>
|
||||||
|
Input Gateway node produces message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code>.
|
||||||
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<h3>Outputs</h3>
|
<h3>Outputs</h3>
|
||||||
<ol class="node-ports">
|
<ol class="node-ports">
|
||||||
<dl class="message-properties">
|
<dl class="message-properties">
|
||||||
<dt>payload <span class="property-type">object</span></dt>
|
<dt>payload <span class="property-type">object</span></dt>
|
||||||
<dd>Data from gateway, see below.</dd>
|
<dd>Data from gateway when used as a filter (see below).</dd>
|
||||||
|
<dt>sid <span class="property-type">string</span></dt>
|
||||||
|
<dd>Device SID.</dd>
|
||||||
|
<dt>gateway <span class="property-type">object</span></dt>
|
||||||
|
<dd>The <code>xiaomi-configurator</code> object where the device is registred.</dd>
|
||||||
</dl>
|
</dl>
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<h4>Details</h4>
|
<h4>Details</h4>
|
||||||
<p>The incoming message is processed if the <code>sid</code> matches the configured value for this device.</p>
|
<p>The incoming message is processed if the input <code>sid</code> matches the configured value for this device.</p>
|
||||||
<p>Sample message:</p>
|
<p>Sample message:</p>
|
||||||
<p><pre>{
|
<p><pre>{
|
||||||
cmd: "report"
|
cmd: "report"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const miDevicesUtils = require('../src/utils');
|
const miDevicesUtils = require('../src/utils');
|
||||||
|
|
||||||
module.exports = (RED) => {
|
module.exports = (RED) => {
|
||||||
|
// switch, sensor_switch.aq2
|
||||||
function XiaomiSwitchNode(config) {
|
function XiaomiSwitchNode(config) {
|
||||||
miDevicesUtils.defaultNode(RED, config, this);
|
miDevicesUtils.defaultNode(RED, config, this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,6 @@
|
|||||||
"miio": "0.13.0"
|
"miio": "0.13.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node" : ">=4.4.5"
|
"node": ">=4.4.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user