SergiuToporjinschi / node-red-contrib-heater-controller

Heater controller for node-red dashboard
GNU General Public License v3.0
18 stars 17 forks source link

Add input topic "userTargetValue" #10

Closed Alcantor closed 5 years ago

Alcantor commented 5 years ago

Hello,

First, thank you for you work, I plan to use your widget for my home automation.

I wanted to control the widget with voice command (Alexa), so for my usage an input topic "userTargetValue" would be very welcome.

--- backEndNode.js.ori  2018-12-26 08:52:59.666724165 +0100
+++ backEndNode.js  2018-12-26 09:23:35.210607194 +0100
@@ -4,7 +4,7 @@
         throw 'heater_controller.error.no-group';
     }
     this.node = node;
-    this.allowedTopics = ['currentTemp'];
+    this.allowedTopics = ['currentTemp', 'userTargetValue'];
     this.config = config;
 }
 function override(target, source) {
@@ -108,14 +108,19 @@
     value = parseFloat(value);
     var returnValues = override(existingValues, { [msg.topic]: value });
     context.set("values", returnValues);
-    if ('currentTemp' === msg.topic) {
-        returnValues = recalculateAndTrigger(returnValues, this.config, this.node);
-        context.set("values", returnValues);
-
-        this.node.send({
-            topic: this.config.topic,
-            payload: returnValues
-        });
+    switch (msg.topic) {
+        case 'userTargetValue':
+            returnValues.isUserCustom = true;
+            /* No break, continue with updating values... */
+        case 'currentTemp':
+            returnValues = recalculateAndTrigger(returnValues, this.config, this.node);
+            context.set("values", returnValues);
+
+            this.node.send({
+                topic: this.config.topic,
+                payload: returnValues
+            });
+            break;
     }
     return { msg: returnValues };
 };
@@ -136,4 +141,4 @@
     }
 };
Alcantor commented 5 years ago
--- README.md.ori   2018-12-26 09:45:05.717964567 +0100
+++ README.md   2018-12-26 09:45:23.837786009 +0100
@@ -50,8 +50,8 @@

 This controller accepts one main input which has to have topic as
 "currentTemp" and payload needs to be a float
-The entire control is not functional untill this message is received
-The heater status is recalculated when this message recived, or when the
+The entire control is not functional until this message is received
+The heater status is recalculated when this message received, or when the
 user is changing the target temperature.

 Message example:
@@ -64,6 +64,15 @@

+To set the temperature target value other than through the UI (eg. Voice command), the optional topic "userTargetValue" can be used.
+
+```
+{
+    "topic" : "userTargetValue",
+    "payload" : "20.0"
+}
+```
+
 ## Output

 A message is emited when the status is recalculated (when the user is
SergiuToporjinschi commented 5 years ago

Can you create a fork and ask for a pull request?

Alcantor commented 5 years ago

Ok, done.