From ab7ea0413c464500c5e51d802b3b9030cad14245 Mon Sep 17 00:00:00 2001 From: Harald Rietman Date: Sun, 5 Nov 2017 14:02:58 +0100 Subject: [PATCH] Divide values from HT sensors when using templates --- node-red-contrib-xiaomi-ht/xiaomi-ht.html | 21 +++++++++++++++------ node-red-contrib-xiaomi-ht/xiaomi-ht.js | 8 +++++++- package.json | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/node-red-contrib-xiaomi-ht/xiaomi-ht.html b/node-red-contrib-xiaomi-ht/xiaomi-ht.html index 7f2e563..df197e1 100644 --- a/node-red-contrib-xiaomi-ht/xiaomi-ht.html +++ b/node-red-contrib-xiaomi-ht/xiaomi-ht.html @@ -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 @@ - - - -
+ +
+
+ +    +
@@ -135,7 +137,14 @@

Only passes the string values for temperature on output 1 and humidity on output 2.

Template

Use your own template to pass the values on. The template can contain mustache-style tags. - Any property from the data section of the full object can be used.

+ 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: +
+        {
+            "name":"Temperatuur woonkamer",
+            "characteristic":"CurrentTemperature",
+            "value":{{temperature}}
+        }

Sample message:

diff --git a/node-red-contrib-xiaomi-ht/xiaomi-ht.js b/node-red-contrib-xiaomi-ht/xiaomi-ht.js
index 54ee954..7431e7c 100644
--- a/node-red-contrib-xiaomi-ht/xiaomi-ht.js
+++ b/node-red-contrib-xiaomi-ht/xiaomi-ht.js
@@ -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]);
diff --git a/package.json b/package.json
index afc088e..3496ed6 100644
--- a/package.json
+++ b/package.json
@@ -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",