2
0
Files
node-red-contrib-mi-devices/node-red-contrib-xiaomi-motion/xiaomi-motion.html
Pierre CLEMENT 5c27c9ff6e fix(config): update device list on getway change
Also set the device name as name by default
2017-12-31 20:59:38 +01:00

161 lines
5.8 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script type="text/javascript">
RED.nodes.registerType('xiaomi-motion', {
category: 'xiaomi',
color: '#3FADB5',
defaults: {
gateway: {value:"", type:"xiaomi-configurator"},
name: {value: ""},
sid: {value: "", required: true},
motionmsg: {value: ""},
nomotionmsg: {value: ""},
output: {value: "0"}
},
inputs: 1,
outputs: 2,
outputLabels: ["Status"],
paletteLabel: "motion",
icon: "motion-icon.png",
label: function () {
return this.name || "xiaomi-motion";
},
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("magnet");
});
$("#node-input-output").change(function () {
if ($(this).val() == "2") {
$(".node-input-msg").show();
} else {
$(".node-input-msg").hide();
}
});
},
oneditsave: function() {
var node = this;
node.sid = $("#node-input-sid").val();
}
});
</script>
<script type="text/x-red" data-template-name="xiaomi-motion">
<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-motionmsg"><i class="fa fa-rss"></i> Motion msg</label>
<input type="text" id="node-input-motionmsg">
</div>
<div class="form-row node-input-msg">
<label for="node-input-nomotionmsg"><i class="fa fa-circle"></i> No motion msg</label>
<input type="text" id="node-input-nomotionmsg">
</div>
</script>
<script type="text/x-red" data-help-name="xiaomi-motion">
<p>The Xiaomi body motion sensor node</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>payload
<span class="property-type">json</span>
</dt>
<dd>Gateway <code>motion</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code></dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Motion output
<dl class="message-properties">
<dt>payload <span class="property-type">string | json</span></dt>
<dd>raw data, value or template.</dd>
</dl>
</li>
<li>Duration output
<dl class="message-properties">
<dt>payload <span class="property-type">json</span></dt>
<dd>raw data</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>The incoming json message is parsed if the type model is <code>motion</code> and
the <code>sid</code> matches the configured value for this device.</p>
<p>Three output types are supported for output 1:
<ul>
<li>Full data</li>
<li>Just values</li>
<li>Template</li>
</ul>
</p>
<h4>Full data</h4>
<p>Passes the complete json object received from the gateway. Use this if you need the raw data.</p>
<h4>Just values</h4>
<p>Only passes the values <code>motion</code> or <code>no_motion</code>. In case of <code>no_motion</code> also the duration object is passed on output 2.</p>
<h4>Template</h4>
<p>Use your own template to pass the values on. The template can contain <a href="http://mustache.github.io/mustache.5.html">mustache-style</a> tags.
Any property from the data section of the full object can be used.</p>
<p>Sample message:</p>
<p><pre>
{
cmd: "read_ack"
model: "motion"
sid: "158d00015ef56c"
short_id: 21672
data: "{
"voltage":3035,
"status":"motion"
}"
}</pre></p>
</script>