mattes-seins
This commit is contained in:
BIN
node-red-contrib-xiaomi-smoke/icons/org_smoke-icon.png
Normal file
BIN
node-red-contrib-xiaomi-smoke/icons/org_smoke-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
BIN
node-red-contrib-xiaomi-smoke/icons/smoke-icon.png
Normal file
BIN
node-red-contrib-xiaomi-smoke/icons/smoke-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
131
node-red-contrib-xiaomi-smoke/xiaomi-smoke.html
Normal file
131
node-red-contrib-xiaomi-smoke/xiaomi-smoke.html
Normal file
@@ -0,0 +1,131 @@
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('xiaomi-smoke', {
|
||||
category: 'xiaomi',
|
||||
color: '#3FADB5',
|
||||
defaults: {
|
||||
gateway: {value:"", type:"xiaomi-configurator"},
|
||||
name: {value: ""},
|
||||
sid: {value: "", required: true},
|
||||
smokemsg: {value: ""},
|
||||
nosmokemsg: {value: ""},
|
||||
output: {value: "0"}
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 1,
|
||||
paletteLabel: "smoke",
|
||||
icon: "smoke-icon.png",
|
||||
label: function () {
|
||||
return this.name || "xiaomi-smoke";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var node = this;
|
||||
|
||||
if(node.sid) {
|
||||
$('#node-input-sid').val(node.sid);
|
||||
}
|
||||
|
||||
function changeGateway(model) {
|
||||
var configNodeID = $('#node-input-gateway').val();
|
||||
if (configNodeID) {
|
||||
var configNode = RED.nodes.node(configNodeID);
|
||||
if(configNode) {
|
||||
$('#node-input-sid').empty();
|
||||
for (key in configNode.deviceList) {
|
||||
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").change(function () {
|
||||
if(!this.name) {
|
||||
$("#node-input-name").val($('#node-input-sid option:selected').text());
|
||||
}
|
||||
});
|
||||
$("#node-input-gateway").change(function () {
|
||||
changeGateway("smoke");
|
||||
});
|
||||
},
|
||||
oneditsave: function() {
|
||||
var node = this;
|
||||
node.sid = $("#node-input-sid").val();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="xiaomi-smoke">
|
||||
<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>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="xiaomi-smoke">
|
||||
<p>The Xiaomi smoke sensor node</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>payload
|
||||
<span class="property-type">object</span>
|
||||
</dt>
|
||||
<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>
|
||||
|
||||
<h3>Outputs</h3>
|
||||
<ol class="node-ports">
|
||||
<dl class="message-properties">
|
||||
<dt>payload <span class="property-type">object</span></dt>
|
||||
<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>
|
||||
</ol>
|
||||
|
||||
<h4>Details</h4>
|
||||
<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><pre>{
|
||||
cmd: "report"
|
||||
model: "smoke"
|
||||
sid: "158d00015ef56c"
|
||||
short_id: 21672
|
||||
data: {
|
||||
density: "0"
|
||||
}
|
||||
}</pre>
|
||||
<p><pre>{
|
||||
cmd: "heartbeat"
|
||||
model: "smoke"
|
||||
sid: "158d00015ef56c"
|
||||
short_id: 21672
|
||||
data: {
|
||||
voltage: 3035,
|
||||
alarm: "0",
|
||||
batteryLevel: 45
|
||||
}
|
||||
}</pre>
|
||||
Where <code>batteryLevel</code> is a computed percentage of remaining battery.
|
||||
</p>
|
||||
</script>
|
||||
9
node-red-contrib-xiaomi-smoke/xiaomi-smoke.js
Normal file
9
node-red-contrib-xiaomi-smoke/xiaomi-smoke.js
Normal file
@@ -0,0 +1,9 @@
|
||||
const miDevicesUtils = require('../src/utils');
|
||||
|
||||
module.exports = (RED) => {
|
||||
// smoke
|
||||
function XiaomiSmokeNode(config) {
|
||||
miDevicesUtils.defaultNode(RED, config, this);
|
||||
}
|
||||
RED.nodes.registerType("xiaomi-smoke", XiaomiSmokeNode);
|
||||
};
|
||||
Reference in New Issue
Block a user