Divide values from HT sensors when using templates
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
sid: {value: "", required: true},
|
||||
temperature: {value: "{{temperature}}"},
|
||||
humidity: {value: "{{humidity}}"},
|
||||
divide: {value: true},
|
||||
output: {value: "0"}
|
||||
},
|
||||
inputs: 1,
|
||||
@@ -69,10 +70,6 @@
|
||||
<label for="node-input-sid"><i class="icon-tag"></i> Device</label>
|
||||
<select id="node-input-sid" placeholder="xiaomi gateway"></select>
|
||||
</div>
|
||||
<!--<div class="form-row">-->
|
||||
<!--<label for="node-input-sid"><i class="fa fa-id-badge"></i> Device SID</label>-->
|
||||
<!--<input type="text" id="node-input-sid">-->
|
||||
<!--</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%;">
|
||||
@@ -87,7 +84,12 @@
|
||||
</div>
|
||||
<div class="form-row node-input-msg">
|
||||
<label for="node-input-humidity"><i class="fa fa-mixcloud"></i> Humidity</label>
|
||||
<input type="text" id="node-input-humidity">
|
||||
<input type="text" id="node-input-humidity"/>
|
||||
</div>
|
||||
<div class="form-row node-input-msg">
|
||||
<label> </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>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
@@ -135,7 +137,14 @@
|
||||
<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.
|
||||
Any property from the data section of the full object can be used.</p>
|
||||
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>
|
||||
|
||||
<p>Sample message:</p>
|
||||
<p><pre>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var mustache = require("mustache");
|
||||
var udpInputPortsInUse = {};
|
||||
var dgram = require('dgram');
|
||||
|
||||
function XiaomiHtNode(config) {
|
||||
@@ -11,6 +10,7 @@ module.exports = function(RED) {
|
||||
this.output = config.output;
|
||||
this.temperature = config.temperature;
|
||||
this.humidity = config.humidity;
|
||||
this.divide = config.divide;
|
||||
|
||||
var node = this;
|
||||
|
||||
@@ -55,10 +55,16 @@ module.exports = function(RED) {
|
||||
var humidity = null;
|
||||
|
||||
if (data.temperature) {
|
||||
if (this.divide) {
|
||||
data.temperature = String(data.temperature / 100);
|
||||
}
|
||||
temp = {"payload": mustache.render(node.temperature, data)}
|
||||
}
|
||||
|
||||
if (data.humidity) {
|
||||
if (this.divide) {
|
||||
data.humidity = String(data.humidity / 100);
|
||||
}
|
||||
humidity = {"payload": mustache.render(node.humidity, data)}
|
||||
}
|
||||
node.send([temp, humidity]);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "node-red-contrib-xiaomi-devices",
|
||||
"version": "1.0.12",
|
||||
"version": "1.0.13",
|
||||
"description": "A set of nodes to control some of the popular Xiaomi sensors which are connected to the Xiaomi Gateway.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Reference in New Issue
Block a user