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 : "" },
2017-06-30 19:14:32 +02:00
sid : { value : "" , required : true },
2017-06-25 18:48:17 +02:00
temperature : { value : "{{temperature}}" },
humidity : { value : "{{humidity}}" },
2017-12-31 20:09:56 +01:00
pressure : { value : "{{pressure}}" },
2017-11-05 14:02:58 +01:00
divide : { value : true },
2017-06-25 18:48:17 +02:00
output : { value : "0" }
},
2017-06-30 19:14:32 +02:00
inputs : 1 ,
2017-12-31 20:09:56 +01:00
outputs : 3 ,
outputLabels : [ "Temperature" , "Humidity" , "Pressure" ],
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
2017-06-25 18:48:17 +02:00
$ ( "#node-input-output" ). change ( function () {
if ( $ ( this ). val () == "2" ) {
$ ( ".node-input-msg" ). show ();
} else {
$ ( ".node-input-msg" ). hide ();
}
});
$ ( ".node-input-msg" ). hide ();
$ ( "#node-input-output" ). val ( node . output );
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>
< 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-temperature" >< i class = "fa fa-thermometer-three-quarters" >< /i> Temperature</label>
< input type = "text" id = "node-input-temperature" >
< /div>
< div class = "form-row node-input-msg" >
< label for = "node-input-humidity" >< i class = "fa fa-mixcloud" >< /i> Humidity</label>
2017-11-05 14:02:58 +01:00
< input type = "text" id = "node-input-humidity" />
< /div>
2017-12-31 20:09:56 +01:00
< div class = "form-row node-input-msg" >
2017-12-31 20:59:38 +01:00
< label for = "node-input-pressure" >< i class = "fa fa-tachometer" >< /i> Pressure</label>
2017-12-31 20:09:56 +01:00
< input type = "text" id = "node-input-pressure" />
< /div>
2017-11-05 14:02:58 +01:00
< div class = "form-row node-input-msg" >
< label >& nbsp ; < /label>
< i >< /i> <input type="checkbox" id="node-input-divide" style="display: inline-block; width: auto; vertical-align: top;">
< label for = "node-input-divide" style = "width: 70%;" > Divide values by 100 < /label>
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
< span class = "property-type" > json < /span>
< /dt>
2017-12-31 20:09:56 +01:00
< dd > Gateway < code > sensor_ht < /code> and <code>weather.v1</code> 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" >
< li > Temperature 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 > Humidity output
< dl class = "message-properties" >
< dt > payload < span class = "property-type" > string | json < /span></dt>
< dd > raw data , value or template . < /dd>
< /dl>
< /li>
< /ol>
< h3 > Details < /h3>
2017-12-31 20:09:56 +01:00
< p > The incoming json message is parsed if the type model is < code > sensor_ht < /code> or <code>weather.v1</code> and
2017-07-03 22:41:43 +02:00
the < code > sid < /code> matches the configured value for this device.</p>
< p > Three output types are supported :
2017-07-03 17:44:05 +02:00
< ul >
< li > Full data < /li>
< li > Just values < /li>
< li > Template < /li>
< /ul>
2017-07-03 22:41:43 +02:00
< /p>
< h4 > Full data < /h4>
< p > Passes the complete json object received from the gateway on output 1. Use this if you need the raw data . < /p>
< h4 > Just values < /h4>
< p > Only passes the string values for temperature on output 1 and humidity 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.
2017-11-05 14:02:58 +01:00
Any property from the data section of the full object can be used . As the HT sensor is sending data in thousends , you can check this box to have it in hundreds .
Here an template example to send the temperature to homebridge - mqtt :
< pre >
{
"name" : "Temperatuur woonkamer" ,
"characteristic" : "CurrentTemperature" ,
"value" : {{ temperature }}
} < /pre></p>
2017-07-03 22:41:43 +02:00
2017-07-03 17:44:05 +02:00
< p > Sample message :< /p>
< p >< pre >
{
cmd : "read_ack"
model : "sensor_ht"
sid : "158d00010b7f1b"
short_id : 8451
data : "{
" voltage ":3005,
" temperature ":" 2325 ",
2017-12-31 20:09:56 +01:00
" humidity ":" 5699 ",
" pressure ":" 98126 "
2017-07-03 17:44:05 +02:00
}"
} < /pre></p>
2017-06-25 18:48:17 +02:00
</ script >