2
0
Files
node-red-contrib-mi-devices/node-red-contrib-xiaomi-configurator/xiaomi-configurator.html
2018-01-01 03:31:51 +01:00

127 lines
6.2 KiB
HTML

<script type="text/javascript">
RED.nodes.registerType('xiaomi-configurator', {
category: 'config',
defaults: {
name: {value: ""},
ip: {value: ""},
deviceList: {value:[{ sid:"", desc:"", model:"plug"}]},
key: {value: ""}
},
label: function () {
return this.name || "xiaomi-configurator";
},
oneditprepare: function() {
var node = this;
var tw_sensor_ht = {value:"sensor_ht", label:"sensor ht", icon:"icons/node-red-contrib-xiaomi-devices/sensor-ht-tw-icon.png"};
var tw_magnet = {value:"magnet", label:"contact", icon:"icons/node-red-contrib-xiaomi-devices/magnet-tw-icon.png"};
var tw_motion = {value:"motion", label:"motion", icon:"icons/node-red-contrib-xiaomi-devices/motion-tw-icon.png"};
var tw_plug = {value:"plug", label:"plug", icon:"icons/node-red-contrib-xiaomi-devices/plug-tw-icon.png"};
var tw_switch = {value:"switch", label:"switch", icon:"icons/node-red-contrib-xiaomi-devices/switch-tw-icon.png"};
$("#node-config-input-devices").css('min-height','250px').css('min-width','450px').editableList({
addItem: function(container, i, device) {
if (!device.hasOwnProperty('model')) {
device.model = 'sensor_ht';
}
var row = $('<div/>').appendTo(container);
$('<label/>',{for:"node-config-input-sid-"+i, style:"margin-left: 3px; width: 15px;vertical-align:middle"}).appendTo(row);
var sid = $('<input/>',{id:"node-config-input-sid-"+i,type:"text", placeholder:"SID", style:"width:auto;vertical-align:top"}).appendTo(row);
sid.typedInput({
default: 'sensor_ht',
types: [tw_sensor_ht, tw_magnet, tw_motion, tw_plug, tw_switch]
});
$('<label/>',{for:"node-config-input-desc-"+i, style:"margin-left: 7px; width: 20px;vertical-align:middle"}).html('<i class="fa fa-pencil-square-o"></i>').appendTo(row);
var desc = $('<input/>',{id:"node-config-input-desc-"+i, type:"text", placeholder:"description", style:"width:auto;vertical-align:top"}).appendTo(row);
sid.typedInput('value', device.sid);
sid.typedInput('type', device.model);
desc.val(device.desc);
},
resize: function() {
},
removeItem: function(opt) {
},
sortItems: function(rules) {
},
sortable: true,
removable: true
});
for (var i=0;i<this.deviceList.length;i++) {
var device = this.deviceList[i];
$("#node-config-input-devices").editableList('addItem', device);
}
var listHeight = $("#node-config-input-devices").editableList('items').size() * 51 + 50;
$("#node-config-input-devices").editableList('height', listHeight);
},
oneditsave: function() {
var devices = $("#node-config-input-devices").editableList('items');
var node = this;
RED.nodes.eachNode(function(tmpNode) {
if(tmpNode.type.indexOf("xiaomi-gateway") === 0 && tmpNode.gateway == node.id) {
tmpNode.ip = $("#node-config-input-ip").val();
tmpNode.changed = true;
}
});
var devicesArray = [];
devices.each(function(i) {
var deviceElement = $(this);
var sid = deviceElement.find("#node-config-input-sid-"+i).val();
var desc = deviceElement.find("#node-config-input-desc-"+i).val();
var model = deviceElement.find("#node-config-input-sid-"+i).typedInput('type');
var d = {};
d['sid']=sid;
d['desc']=desc;
d['model']=model;
devicesArray.push(d);
});
node.deviceList = devicesArray;
}
});
</script>
<script type="text/x-red" data-template-name="xiaomi-configurator">
<div class="form-row">
<label for="node-config-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-config-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-config-input-ip"><i class="icon-tag"></i> IP address (v4 or v6)</label>
<input type="text" id="node-config-input-ip" placeholder="IP">
</div>
<div class="form-row">
<label for="node-config-input-key"><i class="fa fa-ticket"></i> Key/Password</label>
<input type="text" id="node-config-input-key" placeholder="Key">
</div>
<div class="form-row node-config-input-devices">
<ol id="node-config-input-devices"></ol>
</div>
</script>
<script type="text/x-red" data-help-name="xiaomi-configurator">
<p>Device configuration for Xiaomi nodes.</p>
<h3>Details</h3>
<p>This configuration node is used by the Xiaomi device nodes. Here you can add
devices with their device-id (SID), type and a description.</p>
<p>At the moment the following devices are supported:
<lu>
<li>Humidity & Temperature sensor [sensor ht]</li>
<li>Body motion sensor [motion]</li>
<li>Magnet contact sensor [contact]</li>
<li>Wall socket plug (zigbee) [plug]</li>
<li>Push button [switch]</li>
</lu>
</p>
<p>To be able to receive messages from the Xiaomi gateway, you need to set the gateway
in developer mode. Once in developer mode, the gateway sends JSON messages over the network as
UDP packages. On the internet their are a lot of guides on how to put the gateway in developer mode.</p>
<p>If you want to use the wall sockets, you need to set the key from the gateway. The key can be
retrieved via the Xiaomi Home App when in developer mode. Enter the key here and it is used
together with the token from the gateway's heartbeat message to recalculate the key to switch
the plug. If you do not specify a key, the plug-node can not be used.</p>
</script>