node-red-contrib-xiaomi-smart-devices
Version:
Xiaomi Home Automation for NodeRed
124 lines (114 loc) • 3.88 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('xiaomi-wall-switch', {
category: 'xiaomi',
color: 'rgb(192, 222, 237)',
defaults: {
gateway: {value: "", type: "xiaomi-gateway-config"},
name: {value: ""},
sid: {value: "", required: true},
key: {value: "", required: true},
model: {value: "", required: true},
allow_input: {value: false}
},
inputs: 1,
outputs: 1,
paletteLabel: "wall-switch",
icon: "wall-switch.png",
label: function () {
this.inputs = this.allow_input ? 1 : 0;
return this.name || "Xiaomi Wall Switch";
},
oneditprepare: function () {
let node = this;
$('#node-input-model').change(function () {
node.allow_input = $(this).find('option:selected').data('inputs');
});
}
});
</script>
<script type="text/x-red" data-template-name="xiaomi-wall-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> SID</label>
<input type="text" id="node-input-sid" placeholder="SID"></input>
</div>
<div class="form-row">
<label for="node-input-key"><i class="icon-tag"></i> Device</label>
<input type="text" id="node-input-key" placeholder="Device Key/Name"></text>
</div>
<div class="form-row">
<label for="node-input-model"><i class="icon-tag"></i> Type</label>
<select id="node-input-model" style="width:70%;">
<option value="wired_single_button" data-inputs="1">Wired: Single-Button</option>
<option value="wired_double_button" data-inputs="1">Wired: Double-Buttons</option>
<option value="wireless_single_button" data-inputs="0">Wireless Single-Button</option>
<option value="wireless_double_button" data-inputs="0">Wireless: Double-Buttons</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="xiaomi-wall-switch">
<p>The Xiaomi Wall Switch node</p>
<h3>Details</h3>
<p>The incoming json message is parsed the <code>sid</code> matches the configured value for this device.</p>
<h4>Supported types</h4>
<ul>
<li>Wired: Single-Button</li>
<li>Wired: Double-Buttons</li>
<li>Wireless Single-Button</li>
<li>Wireless Double-Button</li>
</ul>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>payload.channel_0 <span class="property-type">string</span></dt>
<dd>
<code>on</code> - if you want to turn on<br/>
<code>off</code> - turn off<br/>
<code>switch</code> - change state on -> off, off -> on<br/>
</dd>
<dt>payload.channel_1 <span class="property-type">string</span></dt>
<dd>
<code>on</code> - if you want to turn on<br/>
<code>off</code> - turn off<br/>
<code>switch</code> - change state on -> off, off -> on<br/>
</dd>
</dl>
<h3>Outputs</h3>
<p>Passes the complete json object received from the node to the output</p>
<p>Sample message of Wired Single-Button:</p>
<p><pre>
{
"fromip":"192.168.0.110:4321",
"ip":"192.168.0.110",
"port":4321,
"payload":{
"channel_0":"on",
"time":1556987229523,
"sid":"158d000128f9dd",
"model":"ctrl_ln1"
}
}</pre>
</p>
<p>Sample message of Wireless Double-Buttons:</p>
<p>
<pre>
{
"fromip":"192.168.0.110:4321",
"ip":"192.168.0.110",
"port":4321,
"payload":{
"channel_1":"click",
"time":1556987769175,
"sid":"158d000242275f",
"model":"86sw2"
}
}
</pre>
</p>
</script>