diff --git a/package.json b/package.json
index 65cee3c..31b48e1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@vvzvlad/node-red-contrib-rn-combined-nodes",
- "version": "0.2.7",
+ "version": "0.2.8",
"description": "",
"main": "index.js",
"keywords": [
diff --git a/thermostat-analyzer.html b/thermostat-analyzer.html
index 9a6242f..fa5d41b 100644
--- a/thermostat-analyzer.html
+++ b/thermostat-analyzer.html
@@ -21,9 +21,16 @@
+
+
+
+
+
+
+
+
-
diff --git a/thermostat-analyzer.js b/thermostat-analyzer.js
index 8461748..bfc06ea 100644
--- a/thermostat-analyzer.js
+++ b/thermostat-analyzer.js
@@ -1,8 +1,8 @@
module.exports = function(RED) {
function thermostat_analyzer(config) {
RED.nodes.createNode(this,config);
- this.room = config.room;
- this.zone = config.zone;
+ this.status_window = config.status_window;
+ this.transitions_window = config.transitions_window;
var node = this;
var context = node.context();
@@ -40,10 +40,14 @@ module.exports = function(RED) {
function analyzer(msg) {
- const status_window = 5 * 60 * 60 * 1000
- const transitions_window = 5 * 60 * 60 * 1000
+ const status_window_h = node.status_window || 5
+ const transitions_window_h = node.transitions_window || 5
const max_temp_diff = 3
+ const status_window_ms = status_window_h * 60 * 60 * 1000
+ const transitions_window_ms = transitions_window_h * 60 * 60 * 1000
+
+
function round_to_two_decimal_places(num) {
return Math.round((num + Number.EPSILON) * 100) / 100
@@ -54,7 +58,7 @@ module.exports = function(RED) {
if (value === null) return
const current_time = new Date().getTime()
status_hist.push({ value, timestamp: current_time })
- status_hist = status_hist.filter(item => current_time - item.timestamp <= status_window)
+ status_hist = status_hist.filter(item => current_time - item.timestamp <= status_window_ms)
let sum = 0
let total_time = 0
for (let i = 1; i < status_hist.length; i++) {
@@ -71,7 +75,7 @@ module.exports = function(RED) {
const current_time = new Date().getTime()
const temp_diff = Math.abs(current_temp - target_temp)
diff_hist.push({ value: temp_diff, timestamp: current_time })
- diff_hist = diff_hist.filter(item => current_time - item.timestamp <= status_window)
+ diff_hist = diff_hist.filter(item => current_time - item.timestamp <= status_window_ms)
let sum = 0
let total_time = 0
for (let i = 1; i < diff_hist.length; i++) {
@@ -91,12 +95,12 @@ module.exports = function(RED) {
if (new_heater_status !== last_heater_status && new_window_state === last_window_state) {
const current_time = new Date().getTime()
transitions.push({ timestamp: current_time })
- transitions = transitions.filter(item => current_time - item.timestamp <= transitions_window)
+ transitions = transitions.filter(item => current_time - item.timestamp <= transitions_window_ms)
context.set('last_heater_status', new_heater_status)
context.set('transitions', transitions)
}
context.set('last_window_state', new_window_state)
- return transitions.length * 8
+ return transitions.length / transitions_window_h * 24
}
const payload = msg.payload