2017-06-30 21:32:10 +02:00
< script type = "text/javascript" >
RED . nodes . registerType ( 'xiaomi-plug' , {
2017-07-02 17:21:47 +02:00
category : 'xiaomi' ,
color : '#3FADB5' ,
2017-06-30 21:32:10 +02:00
defaults : {
gateway : { value : "" , type : "xiaomi-configurator" },
name : { value : "" },
sid : { value : "" , required : true },
onmsg : { value : "" },
offmsg : { value : "" },
output : { value : "0" }
},
inputs : 1 ,
2018-01-03 12:12:45 +01:00
outputs : 1 ,
2017-07-02 17:21:47 +02:00
paletteLabel : "plug (zigbee)" ,
2017-06-30 21:32:10 +02:00
icon : "outlet-icon.png" ,
label : function () {
return this . name || "xiaomi-plug" ;
},
oneditprepare : function () {
var node = this ;
2018-01-05 22:21:50 +01:00
if ( node . sid ) {
$ ( '#node-input-sid' ). val ( node . sid );
}
2017-06-30 21:32:10 +02:00
2018-01-05 22:21:50 +01:00
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 );
}
}
2017-06-30 21:32:10 +02:00
}
}
2018-01-05 22:21:50 +01:00
$ ( "#node-input-sid" ). change ( function () {
if ( ! this . name ) {
$ ( "#node-input-name" ). val ( $ ( '#node-input-sid option:selected' ). text ());
}
});
$ ( "#node-input-gateway" ). change ( function () {
changeGateway ( "plug" );
});
2017-06-30 21:32:10 +02:00
},
oneditsave : function () {
var node = this ;
node . sid = $ ( "#node-input-sid" ). val ();
}
});
</ script >
< script type = "text/x-red" data-template-name = "xiaomi-plug" >
< 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>
</ script >
< script type = "text/x-red" data-help-name = "xiaomi-plug" >
2017-07-03 22:41:43 +02:00
< p > The Xiaomi plug ( zigbee ) node < /p>
2017-07-03 17:44:05 +02:00
< p > This is the plug ( socket ) version which is attached to a Xiaomi gateway . The Wifi version is not yet supported . < /p>
< p > To switch an output you need to specify the key of the gateway in the gateway configuration ; without the key
2017-07-03 22:41:43 +02:00
no output can be switched . To retrieve the gateway key consult the Xiaomi Mi Home App . < /p>
< 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" > string | json < /span>
< /dt>
2018-01-05 22:21:50 +01:00
< dd > When the node is used as filter , gateway < code > plug < /code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code>. Or <code>on</code> or <code>off</code>.</dd>
2017-07-03 22:41:43 +02:00
< /dl>
< h3 > Outputs < /h3>
< ol class = "node-ports" >
< li > Status 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 > Control output
< dl class = "message-properties" >
< dt > payload < span class = "property-type" > json < /span></dt>
< dd > Gateway < code > write_cmd < /code> to switch the output on or off.</dd>
< /dl>
< /li>
< /ol>
2018-01-03 12:12:45 +01:00
< h4 > Details < /h4>
2017-07-03 22:41:43 +02:00
< p > The incoming json message is parsed if the type model is < code > plug < /code> and
the < code > sid < /code> matches the configured value for this device.</p>
< p > On the input you can send the string < code > on < /code> to switch the plug on. To turn it off just send the string <code>off</code></p>
2017-07-03 17:44:05 +02:00
< p > Sample message :< /p>
2018-01-03 12:12:45 +01:00
< p >< pre > {
cmd : "write_ack"
model : "plug"
sid : "158d00012f1fb5"
short_id : 47414
data : {
voltage : 3600 ,
status : "off" ,
inuse : "0" ,
power_consumed : "4000" ,
load_power : "0"
}
} < /pre></p>
2017-06-30 21:32:10 +02:00
</ script >