2
0

feat(devices): add some aqara devices

Added Aqara temperature/humidity, switch and window magnet
This commit is contained in:
Pierre CLEMENT
2017-12-31 20:09:56 +01:00
parent 47c9a58b54
commit 59a79f0cc1
6 changed files with 33 additions and 14 deletions

View File

@@ -8,12 +8,13 @@
sid: {value: "", required: true},
temperature: {value: "{{temperature}}"},
humidity: {value: "{{humidity}}"},
pressure: {value: "{{pressure}}"},
divide: {value: true},
output: {value: "0"}
},
inputs: 1,
outputs: 2,
outputLabels: ["Temperature","Humidity"],
outputs: 3,
outputLabels: ["Temperature","Humidity","Pressure"],
paletteLabel: "sensor HT",
icon: "thermometer-icon.png",
label: function () {
@@ -86,6 +87,10 @@
<label for="node-input-humidity"><i class="fa fa-mixcloud"></i> Humidity</label>
<input type="text" id="node-input-humidity"/>
</div>
<div class="form-row node-input-msg">
<label for="node-input-pressure"><i class="fa fa-mixcloud"></i> Pressure</label>
<input type="text" id="node-input-pressure"/>
</div>
<div class="form-row node-input-msg">
<label>&nbsp;</label>
<i></i>&nbsp;&nbsp;<input type="checkbox" id="node-input-divide" style="display: inline-block; width: auto; vertical-align: top;">
@@ -101,7 +106,7 @@
<dt>payload
<span class="property-type">json</span>
</dt>
<dd>Gateway <code>sensor_ht</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code></dd>
<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>
</dl>
<h3>Outputs</h3>
@@ -121,7 +126,7 @@
</ol>
<h3>Details</h3>
<p>The incoming json message is parsed if the type model is <code>sensor_ht</code> and
<p>The incoming json message is parsed if the type model is <code>sensor_ht</code> or <code>weather.v1</code> and
the <code>sid</code> matches the configured value for this device.</p>
<p>Three output types are supported:
<ul>
@@ -156,7 +161,8 @@
data: "{
"voltage":3005,
"temperature":"2325",
"humidity":"5699"
"humidity":"5699",
"pressure":"98126"
}"
}</pre></p>

View File

@@ -22,7 +22,7 @@ module.exports = function(RED) {
var payload = msg.payload;
node.log("Received message from: " + payload.model + " sid: " + payload.sid + " payload: " + payload.data);
if (payload.sid == node.sid && payload.model == "sensor_ht") {
if (payload.sid == node.sid && ["sensor_ht", "weather.v1"].indexOf(payload.model) >= 0) {
var data = JSON.parse(payload.data)
if (data.voltage) {
@@ -41,6 +41,7 @@ module.exports = function(RED) {
} else if (node.output == "1") {
var temp = null;
var humidity = null;
var pressure = null;
if (data.temperature) {
temp = {"payload": data.temperature};
@@ -49,10 +50,15 @@ module.exports = function(RED) {
if (data.humidity) {
humidity = {"payload": data.humidity};
}
node.send([temp, humidity]);
if (data.pressure) {
pressure = {"payload": data.pressure};
}
node.send([temp, humidity, pressure]);
} else if (node.output == "2") {
var temp = null;
var humidity = null;
var pressure = null;
if (data.temperature) {
if (this.divide) {
@@ -67,7 +73,14 @@ module.exports = function(RED) {
}
humidity = {"payload": mustache.render(node.humidity, data)}
}
node.send([temp, humidity]);
if (data.pressure) {
if (this.divide) {
data.pressure = String(data.pressure / 1000);
}
pressure = {"payload": mustache.render(node.pressure, data)}
}
node.send([temp, humidity, pressure]);
}
}
});

View File

@@ -92,7 +92,7 @@
<dt>payload
<span class="property-type">json</span>
</dt>
<dd>Gateway <code>magnet</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code></dd>
<dd>Gateway <code>magnet</code> and <code>sensor_magnet.aq2</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code></dd>
</dl>
<h3>Outputs</h3>
@@ -106,7 +106,7 @@
</ol>
<h3>Details</h3>
<p>The incoming json message is parsed if the type model is <code>magnet</code> and
<p>The incoming json message is parsed if the type model is <code>magnet</code> or <code>sensor_magnet.aq2</code> and
the <code>sid</code> matches the configured value for this device.</p>
<p>Three output types are supported:
<ul>

View File

@@ -21,7 +21,7 @@ module.exports = function(RED) {
// var payload = JSON.parse(msg);
var payload = msg.payload;
if (payload.sid == node.sid && payload.model == "magnet") {
if (payload.sid == node.sid && ["magnet", "sensor_magnet.aq2"].indexOf(payload.model) >= 0) {
var data = JSON.parse(payload.data)
// if (data.status && data.status == "open") {

View File

@@ -95,7 +95,7 @@
<dt>payload
<span class="property-type">json</span>
</dt>
<dd>Gateway <code>switch</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code></dd>
<dd>Gateway <code>switch</code> and <code>sensor_switch.aq2</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code></dd>
</dl>
<h3>Outputs</h3>
@@ -115,7 +115,7 @@
</ol>
<h3>Details</h3>
<p>The incoming json message is parsed if the type model is <code>switch</code> and
<p>The incoming json message is parsed if the type model is <code>switch</code> or <code>sensor_switch.aq2</code> and
the <code>sid</code> matches the configured value for this device.</p>
<p>Three output types are supported:
<ul>

View File

@@ -19,7 +19,7 @@ module.exports = function(RED) {
// var payload = JSON.parse(msg);
var payload = msg.payload;
if (payload.sid == node.sid && payload.model == "switch") {
if (payload.sid == node.sid && ["switch", "sensor_switch.aq2"].indexOf(payload.model) >= 0) {
var data = JSON.parse(payload.data)
if (data.voltage) {