From 212a8e26dbbbfa74ee306d51f0b20a46f0b264ec Mon Sep 17 00:00:00 2001 From: Jon Ziebell Date: Fri, 17 Nov 2023 17:02:52 -0500 Subject: [PATCH] Added degree days to Thermostat Summary --- js/beestat/style.js | 12 ++ .../card/runtime_thermostat_summary.js | 25 +++- .../chart/runtime_thermostat_summary.js | 125 ++++++++++++++---- 3 files changed, 134 insertions(+), 28 deletions(-) diff --git a/js/beestat/style.js b/js/beestat/style.js index 2ac77b0..9c90f40 100644 --- a/js/beestat/style.js +++ b/js/beestat/style.js @@ -184,6 +184,16 @@ beestat.series.outdoor_temperature = { 'color': beestat.style.color.gray.light }; +beestat.series.heating_degree_days = { + 'name': 'Degree Days', + 'color': beestat.style.color.red.dark +}; + +beestat.series.cooling_degree_days = { + 'name': 'Degree Days', + 'color': beestat.style.color.lightblue.dark +}; + beestat.series.indoor_humidity = { 'name': 'Indoor Humidity', 'color': beestat.style.color.bluegreen.base @@ -218,6 +228,8 @@ beestat.series.sum_economizer = beestat.series.economizer; beestat.series.sum_ventilator = beestat.series.ventilator; beestat.series.avg_indoor_temperature = beestat.series.indoor_temperature; beestat.series.avg_outdoor_temperature = beestat.series.outdoor_temperature; +beestat.series.sum_heating_degree_days = beestat.series.heating_degree_days; +beestat.series.sum_cooling_degree_days = beestat.series.cooling_degree_days; beestat.series.avg_indoor_humidity = beestat.series.indoor_humidity; beestat.series.avg_outdoor_humidity = beestat.series.outdoor_humidity; diff --git a/js/component/card/runtime_thermostat_summary.js b/js/component/card/runtime_thermostat_summary.js index 4498251..cf075b1 100755 --- a/js/component/card/runtime_thermostat_summary.js +++ b/js/component/card/runtime_thermostat_summary.js @@ -164,6 +164,8 @@ beestat.component.card.runtime_thermostat_summary.prototype.get_data_ = function 'min_outdoor_temperature', 'max_outdoor_temperature', 'extreme_outdoor_temperature', + 'sum_heating_degree_days', + 'sum_cooling_degree_days', 'avg_indoor_temperature', 'avg_indoor_humidity' ].forEach(function(series_code) { @@ -279,7 +281,7 @@ beestat.component.card.runtime_thermostat_summary.prototype.get_data_ = function data.series[key].push(value); - var this_active = key.includes('temperature') ? true : (value > 0); + var this_active = key.includes('temperature') ? true : (value !== 0); data.metadata.series[key].active = data.metadata.series[key].active || this_active; } } @@ -342,6 +344,8 @@ beestat.component.card.runtime_thermostat_summary.prototype.get_buckets_group_ = 'avg_outdoor_humidity': [], 'min_outdoor_temperature': [], 'max_outdoor_temperature': [], + 'sum_heating_degree_days': [], + 'sum_cooling_degree_days': [], 'avg_indoor_temperature': [], 'avg_indoor_humidity': [] }; @@ -394,6 +398,21 @@ beestat.component.card.runtime_thermostat_summary.prototype.get_bucket_key_ = fu * @return {object} The combined buckets. */ beestat.component.card.runtime_thermostat_summary.prototype.get_buckets_combined_ = function(buckets) { + // Basically just excludes degree_days. + const keys_to_convert_from_seconds_to_hours = [ + 'sum_compressor_cool_1', + 'sum_compressor_cool_2', + 'sum_compressor_heat_1', + 'sum_compressor_heat_2', + 'sum_auxiliary_heat_1', + 'sum_auxiliary_heat_2', + 'sum_fan', + 'sum_humidifier', + 'sum_dehumidifier', + 'sum_ventilator', + 'sum_economizer' + ]; + for (var bucket_key in buckets) { var bucket = buckets[bucket_key]; @@ -440,7 +459,9 @@ beestat.component.card.runtime_thermostat_summary.prototype.get_buckets_combined */ // Convert seconds to hours. - bucket[key] /= 3600; + if (keys_to_convert_from_seconds_to_hours.includes(key) === true) { + bucket[key] /= 3600; + } break; } } diff --git a/js/component/chart/runtime_thermostat_summary.js b/js/component/chart/runtime_thermostat_summary.js index dfa6a37..18dbd00 100755 --- a/js/component/chart/runtime_thermostat_summary.js +++ b/js/component/chart/runtime_thermostat_summary.js @@ -95,19 +95,30 @@ beestat.component.chart.runtime_thermostat_summary.prototype.get_options_series_ } }); - if (self.data_.metadata.series.avg_outdoor_temperature.active === true) { + if ( + self.data_.metadata.series.avg_outdoor_temperature.active === true || + self.data_.metadata.series.extreme_outdoor_temperature.active === true + ) { series.push({ 'name': 'avg_outdoor_temperature', + 'id': 'avg_outdoor_temperature', 'data': this.data_.series.avg_outdoor_temperature, 'color': beestat.series.avg_outdoor_temperature.color, 'yAxis': 1, 'type': 'spline', 'dashStyle': 'ShortDash', - 'lineWidth': 1 - }); - } + 'lineWidth': 1, + 'events': { + 'legendItemClick': function() { + const outdoor_temperature_visible = this.visible; + + if (outdoor_temperature_visible === false) { + this.chart.get('sum_heating_degree_days').setVisible(false); + } + } + } + }); - if (self.data_.metadata.series.extreme_outdoor_temperature.active === true) { series.push({ 'name': 'extreme_outdoor_temperature', 'data': this.data_.series.extreme_outdoor_temperature, @@ -116,6 +127,41 @@ beestat.component.chart.runtime_thermostat_summary.prototype.get_options_series_ 'yAxis': 1, 'fillOpacity': 0.2, 'lineWidth': 0, + 'linkedTo': 'avg_outdoor_temperature' + }); + } + + if ( + self.data_.metadata.series.sum_heating_degree_days.active === true || + self.data_.metadata.series.sum_cooling_degree_days.active === true + ) { + series.push({ + 'name': 'sum_heating_degree_days', + 'id': 'sum_heating_degree_days', + 'data': this.data_.series.sum_heating_degree_days, + 'color': beestat.series.sum_heating_degree_days.color, + 'yAxis': 2, + 'type': 'spline', + 'lineWidth': 2, + 'visible': false, + 'events': { + 'legendItemClick': function() { + const degree_days_visible = this.visible; + + if (degree_days_visible === false) { + this.chart.get('avg_outdoor_temperature').setVisible(false); + } + } + } + }); + series.push({ + 'name': 'sum_cooling_degree_days', + 'data': this.data_.series.sum_cooling_degree_days, + 'color': beestat.series.sum_cooling_degree_days.color, + 'yAxis': 2, + 'type': 'spline', + 'lineWidth': 2, + 'linkedTo': 'sum_heating_degree_days', 'visible': false }); } @@ -190,6 +236,24 @@ beestat.component.chart.runtime_thermostat_summary.prototype.get_options_yAxis_ return this.value + beestat.setting('units.temperature'); } } + }, + { + 'alignTicks': false, + 'gridLineColor': null, + 'gridLineDashStyle': 'longdash', + 'opposite': true, + 'allowDecimals': false, + 'title': { + 'text': '' + }, + 'labels': { + 'style': { + 'color': beestat.style.color.gray.base + }, + 'formatter': function() { + return this.value.toLocaleString(); + } + } } ]; }; @@ -226,27 +290,7 @@ beestat.component.chart.runtime_thermostat_summary.prototype.get_options_tooltip var color; switch (point.series.name) { case 'extreme_outdoor_temperature': - label = beestat.series.extreme_outdoor_temperature.name; - color = point.series.color; - if ( - values.min_outdoor_temperature !== undefined && - values.max_outdoor_temperature !== undefined - ) { - value = beestat.temperature({ - 'temperature': values.min_outdoor_temperature, - 'input_temperature_unit': beestat.setting('units.temperature'), - 'units': true, - 'round': 0 - }); - value += ' to '; - value += beestat.temperature({ - 'temperature': values.max_outdoor_temperature, - 'input_temperature_unit': beestat.setting('units.temperature'), - 'units': true, - 'round': 0 - }); - } - break; + return; case 'avg_outdoor_temperature': label = beestat.series.avg_outdoor_temperature.name; color = point.series.color; @@ -256,6 +300,35 @@ beestat.component.chart.runtime_thermostat_summary.prototype.get_options_tooltip 'units': true, 'round': 0 }); + + value += ' ('; + + value += beestat.temperature({ + 'temperature': values.min_outdoor_temperature, + 'input_temperature_unit': beestat.setting('units.temperature'), + 'units': true, + 'round': 0 + }); + value += ' to '; + value += beestat.temperature({ + 'temperature': values.max_outdoor_temperature, + 'input_temperature_unit': beestat.setting('units.temperature'), + 'units': true, + 'round': 0 + }); + + value += ')'; + + break; + case 'sum_heating_degree_days': + label = beestat.series.sum_heating_degree_days.name; + color = point.series.color; + value = Math.round(values.sum_heating_degree_days).toLocaleString(); + break; + case 'sum_cooling_degree_days': + label = beestat.series.sum_cooling_degree_days.name; + color = point.series.color; + value = Math.round(values.sum_cooling_degree_days).toLocaleString(); break; default: label = beestat.series[point.series.name].name;