Skip to content

Commit

Permalink
Add day/night temperature difference in heater environment system. #106
Browse files Browse the repository at this point in the history
  • Loading branch information
theyosh committed Mar 3, 2018
1 parent 159c521 commit a5ef905
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 13 deletions.
4 changes: 4 additions & 0 deletions static/js/terrariumpi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion terrariumConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
45 changes: 35 additions & 10 deletions terrariumEnvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,24 @@ 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(',')
if not isinstance(self.heater['sensors'], list):
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())


Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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


Expand Down
6 changes: 6 additions & 0 deletions views/dashboard.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@
</td>
<td class="duration">...</td>
</tr>
<tr>
<td>
<p>{{_('Day/night difference')}}</p>
</td>
<td class="night_difference">...</td>
</tr>
</table>
</div>
<div class="row environment_cooler">
Expand Down
10 changes: 8 additions & 2 deletions views/system_environment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,15 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="heater_settle_timeout">{{_('Heater settle time')}}</label>
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="heater_settle_timeout">{{_('Heating settle time')}}</label>
<div class="col-md-7 col-sm-6 col-xs-10">
<input class="form-control col-md-7 col-xs-12" name="heater_settle_timeout" required="required" type="text" placeholder="{{_('Heater settle time')}}" data-toggle="tooltip" data-placement="right" title="" data-original-title="{{translations.get_translation('environment_field_heater_settle_timeout')}}">
<input class="form-control col-md-7 col-xs-12" name="heater_settle_timeout" required="required" type="text" placeholder="{{_('Heating settle time')}}" data-toggle="tooltip" data-placement="right" title="" data-original-title="{{translations.get_translation('environment_field_heater_settle_timeout')}}">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="heater_night_difference">{{_('Temperature difference during the night')}}</label>
<div class="col-md-7 col-sm-6 col-xs-10">
<input class="form-control col-md-7 col-xs-12" name="heater_night_difference" required="required" type="text" placeholder="{{_('Temperature difference during the night')}}" data-toggle="tooltip" data-placement="right" title="" data-original-title="{{translations.get_translation('environment_field_heater_night_difference')}}">
</div>
</div>
<div class="form-group">
Expand Down

0 comments on commit a5ef905

Please sign in to comment.