2017-06-25 18:48:17 +02:00
< script type = "text/javascript" >
RED . nodes . registerType ( 'xiaomi-ht' , {
2017-07-02 17:21:47 +02:00
category : 'xiaomi' ,
color : '#3FADB5' ,
2017-06-25 18:48:17 +02:00
defaults : {
2017-06-30 21:32:10 +02:00
gateway : { value : "" , type : "xiaomi-configurator" },
2017-06-25 18:48:17 +02:00
name : { value : "" },
2018-01-03 12:12:45 +01:00
sid : { value : "" , required : true }
2017-06-25 18:48:17 +02:00
},
2017-06-30 19:14:32 +02:00
inputs : 1 ,
2018-01-03 12:12:45 +01:00
outputs : 1 ,
2017-07-02 17:21:47 +02:00
paletteLabel : "sensor HT" ,
2017-06-25 18:48:17 +02:00
icon : "thermometer-icon.png" ,
label : function () {
return this . name || "xiaomi-ht" ;
},
oneditprepare : function () {
2017-06-30 19:14:32 +02:00
var node = this ;
2017-12-31 20:59:38 +01:00
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 ( "sensor_ht" );
});
2017-06-30 19:14:32 +02:00
},
oneditsave : function () {
var node = this ;
node . sid = $ ( "#node-input-sid" ). val ();
2017-06-25 18:48:17 +02:00
}
});
</ script >
< script type = "text/x-red" data-template-name = "xiaomi-ht" >
< 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" >
2017-06-30 19:14:32 +02:00
< label for = "node-input-sid" >< i class = "icon-tag" >< /i> Device</label>
< select id = "node-input-sid" placeholder = "xiaomi gateway" >< /select>
2017-06-25 18:48:17 +02:00
< /div>
</ script >
< script type = "text/x-red" data-help-name = "xiaomi-ht" >
2017-07-03 17:44:05 +02:00
< p > The Xiaomi Humidity & Temperature sensor node < /p>
2017-07-03 22:41:43 +02:00
< h3 > Inputs < /h3>
2017-07-03 17:44:05 +02:00
< dl class = "message-properties" >
2017-07-03 22:41:43 +02:00
< dt > payload
2018-01-05 22:21:50 +01:00
< span class = "property-type" > object < /span>
2017-07-03 22:41:43 +02:00
< /dt>
2018-01-05 22:21:50 +01:00
< 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>
2017-07-03 22:41:43 +02:00
< /dl>
< h3 > Outputs < /h3>
< ol class = "node-ports" >
2018-01-03 12:12:45 +01:00
< dl class = "message-properties" >
< dt > payload < span class = "property-type" > object < /span></dt>
2018-01-05 22:21:50 +01:00
< 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>
2018-01-03 12:12:45 +01:00
< /dl>
2017-07-03 22:41:43 +02:00
< /ol>
2018-01-03 12:12:45 +01:00
< h4 > Details < /h4>
2018-01-05 22:21:50 +01:00
< p > The incoming message is processed if the input < code > sid < /code> matches the configured value for this device.</p>
2018-01-03 12:12:45 +01:00
< p > Sample payload from Aqara ( which brings pressure ) :< /p>
< p >< pre > {
cmd : "read_ack"
model : "weather.v1"
sid : "158d00010b7f1b"
short_id : 8451
data : {
voltage : 3005 ,
temperature : 23.25 ,
humidity : 56.99 ,
pressure : 981.26 ,
batteryLevel : 34
}
} < /pre>
Where < code > humidy < /code> is in percents, <code>pressure</code> in hPa, <code>batteryLevel</code> is a computed percentage of remaining battery.
2017-07-03 22:41:43 +02:00
< /p>
2017-06-25 18:48:17 +02:00
</ script >