From a5ef9052e37dc50828d325659e437131f697e949 Mon Sep 17 00:00:00 2001 From: TheYOSH Date: Sat, 3 Mar 2018 13:07:06 +0100 Subject: [PATCH] Add day/night temperature difference in heater environment system. #106 --- static/js/terrariumpi.js | 4 ++++ terrariumConfig.py | 2 +- terrariumEnvironment.py | 45 ++++++++++++++++++++++++++++-------- views/dashboard.tpl | 6 +++++ views/system_environment.tpl | 10 ++++++-- 5 files changed, 54 insertions(+), 13 deletions(-) diff --git a/static/js/terrariumpi.js b/static/js/terrariumpi.js index e76214ae6..83ec16d22 100644 --- a/static/js/terrariumpi.js +++ b/static/js/terrariumpi.js @@ -1532,6 +1532,10 @@ function update_dashboard_environment(name, data) { case 'alarm_max': systempart.find('.' + key).text(formatNumber(value,3) + ' ' + indicator).parent().toggle(data.mode === 'sensor'); break; + + case 'night_difference': + systempart.find('.' + key).text(formatNumber(value,3) + ' ' + indicator).parent().toggle(data.night_difference != 0); + break; } }); systempart.find('table').toggle(data.enabled); diff --git a/terrariumConfig.py b/terrariumConfig.py index 408587d28..8564e1339 100644 --- a/terrariumConfig.py +++ b/terrariumConfig.py @@ -287,7 +287,7 @@ def save_environment(self,data): for environment_part in data: for part in data[environment_part]: # Do not save the following settings - if part in ['enabled','time_table','state','amount','current','temperature','humidity','distance','alarm','type']: + if part in ['enabled','time_table','state','amount','current','temperature','humidity','distance','alarm','type','night_modus']: continue if data[environment_part][part] is None: diff --git a/terrariumEnvironment.py b/terrariumEnvironment.py index ad414be0f..217ed60c1 100644 --- a/terrariumEnvironment.py +++ b/terrariumEnvironment.py @@ -116,15 +116,16 @@ def load_environment(self, data = None): if len(config_data['heater'].keys()) == 0 or not reloading: self.heater = {} - self.heater['mode'] = 'disabled' if 'mode' not in config_data['heater'] else config_data['heater']['mode'] - self.heater['on'] = '00:00' if 'on' not in config_data['heater'] else config_data['heater']['on'] - self.heater['off'] = '00:00' if 'off' not in config_data['heater'] else config_data['heater']['off'] - self.heater['on_duration'] = 60.0 if 'on_duration' not in config_data['heater'] else float(config_data['heater']['on_duration']) - self.heater['off_duration'] = 60.0 if 'off_duration' not in config_data['heater'] else float(config_data['heater']['off_duration']) - self.heater['day_enabled'] = False if 'day_enabled' not in config_data['heater'] else terrariumUtils.is_true(config_data['heater']['day_enabled']) - self.heater['settle_timeout'] = 120.0 if 'settle_timeout' not in config_data['heater'] else float(config_data['heater']['settle_timeout']) - self.heater['power_switches'] = [] if ('power_switches' not in config_data['heater'] or config_data['heater']['power_switches'] in ['',None]) else config_data['heater']['power_switches'] - self.heater['sensors'] = [] if ('sensors' not in config_data['heater'] or config_data['heater']['sensors'] in ['',None]) else config_data['heater']['sensors'] + self.heater['mode'] = 'disabled' if 'mode' not in config_data['heater'] else config_data['heater']['mode'] + self.heater['on'] = '00:00' if 'on' not in config_data['heater'] else config_data['heater']['on'] + self.heater['off'] = '00:00' if 'off' not in config_data['heater'] else config_data['heater']['off'] + self.heater['on_duration'] = 60.0 if 'on_duration' not in config_data['heater'] else float(config_data['heater']['on_duration']) + self.heater['off_duration'] = 60.0 if 'off_duration' not in config_data['heater'] else float(config_data['heater']['off_duration']) + self.heater['day_enabled'] = False if 'day_enabled' not in config_data['heater'] else terrariumUtils.is_true(config_data['heater']['day_enabled']) + self.heater['settle_timeout'] = 120.0 if 'settle_timeout' not in config_data['heater'] else float(config_data['heater']['settle_timeout']) + self.heater['night_difference'] = 0.0 if 'night_difference' not in config_data['heater'] else float(config_data['heater']['night_difference']) + self.heater['power_switches'] = [] if ('power_switches' not in config_data['heater'] or config_data['heater']['power_switches'] in ['',None]) else config_data['heater']['power_switches'] + self.heater['sensors'] = [] if ('sensors' not in config_data['heater'] or config_data['heater']['sensors'] in ['',None]) else config_data['heater']['sensors'] if not isinstance(self.heater['power_switches'], list): self.heater['power_switches'] = self.heater['power_switches'].split(',') @@ -132,6 +133,7 @@ def load_environment(self, data = None): self.heater['sensors'] = self.heater['sensors'].split(',') self.heater['enabled'] = 'disabled' != self.heater['mode'] + self.heater['night_modus'] = False self.heater['lastaction'] = int(time.time()) @@ -385,7 +387,24 @@ def __engine_loop(self): toggle_on = None extra_logging_message = '' logger.debug('Environment heater is enabled.') - logger.debug('Environment heater is based on: %s' % self.heater['mode']) + logger.debug('Environment heater is based on: %s.' % self.heater['mode']) + + if self.heater['night_difference'] != 0.0 and self.heater['night_modus'] != self.is_night(): + logger.info('Changing heater to %s modus. Changing the min and max alarm %s by %s degrees.' % ( + ('night' if self.is_night() else 'day'), + ('up' if self.is_night() else 'down'), + self.heater['night_difference'])) + # Change temperatures when switching from day to night and vise versa + for sensorid in self.heater['sensors']: + if self.is_night(): + self.sensors[sensorid].set_alarm_min(self.sensors[sensorid].get_alarm_min() + self.heater['night_difference']) + self.sensors[sensorid].set_alarm_max(self.sensors[sensorid].get_alarm_max() + self.heater['night_difference']) + else: + self.sensors[sensorid].set_alarm_min(self.sensors[sensorid].get_alarm_min() - self.heater['night_difference']) + self.sensors[sensorid].set_alarm_max(self.sensors[sensorid].get_alarm_max() - self.heater['night_difference']) + + self.heater['night_modus'] = self.is_night() + if 'sensor' == self.heater['mode']: # Only heat when the lights are off. Or when explicit enabled during the day. if self.heater['day_enabled'] or self.is_light_off(): @@ -727,6 +746,12 @@ def get_average(self,sensors_filter = []): #average[averagetype]['indicator'] = self.__unit_type(averagetype) return average + + def is_day(self): + return (self.light['enabled'] and self.is_light_on()) or self.weather.is_day() + + def is_night(self): + return not self.is_day() # End system functions diff --git a/views/dashboard.tpl b/views/dashboard.tpl index 2ed8b0293..4e193b1da 100644 --- a/views/dashboard.tpl +++ b/views/dashboard.tpl @@ -235,6 +235,12 @@ ... + + +

{{_('Day/night difference')}}

+ + ... +
diff --git a/views/system_environment.tpl b/views/system_environment.tpl index e6d291ce1..53f5da0b5 100644 --- a/views/system_environment.tpl +++ b/views/system_environment.tpl @@ -330,9 +330,15 @@
- +
- + +
+
+
+ +
+