Mercurial > templog
comparison py/fridge.py @ 166:5d5424acfed0
- use the fridge temperature for control too, keep it in a 6deg band
- ignore params beginning with _
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 18 Feb 2013 23:31:32 +0800 |
parents | bf2a17873ba1 |
children | bfc3213edee4 |
comparison
equal
deleted
inserted
replaced
163:bf2a17873ba1 | 166:5d5424acfed0 |
---|---|
4 import gevent | 4 import gevent |
5 | 5 |
6 class Fridge(gevent.Greenlet): | 6 class Fridge(gevent.Greenlet): |
7 | 7 |
8 OVERSHOOT_MAX_DIV = 1800.0 # 30 mins | 8 OVERSHOOT_MAX_DIV = 1800.0 # 30 mins |
9 FRIDGE_AIR_MIN_RANGE = 4 # ºC | 9 FRIDGE_AIR_MIN_RANGE = 3 # ºC |
10 FRIDGE_AIR_MAX_RANGE = 4 | 10 FRIDGE_AIR_MAX_RANGE = 3 |
11 | 11 |
12 def __init__(self, server): | 12 def __init__(self, server): |
13 gevent.Greenlet.__init__(self) | 13 gevent.Greenlet.__init__(self) |
14 self.server = server | 14 self.server = server |
15 self.setup_gpio() | 15 self.setup_gpio() |
63 params = self.server.params | 63 params = self.server.params |
64 | 64 |
65 fridge_min = params.fridge_setpoint - self.FRIDGE_AIR_MIN_RANGE | 65 fridge_min = params.fridge_setpoint - self.FRIDGE_AIR_MIN_RANGE |
66 fridge_max = params.fridge_setpoint + self.FRIDGE_AIR_MAX_RANGE | 66 fridge_max = params.fridge_setpoint + self.FRIDGE_AIR_MAX_RANGE |
67 | 67 |
68 wort_min = params.fridge_setpoint | |
68 wort_max = params.fridge_setpoint + params.fridge_difference | 69 wort_max = params.fridge_setpoint + params.fridge_difference |
69 | 70 |
70 off_time = self.server.now() - self.fridge_off_clock | 71 off_time = self.server.now() - self.fridge_off_clock |
71 | 72 |
72 if off_time < config.FRIDGE_DELAY: | 73 if off_time < config.FRIDGE_DELAY: |
101 overshoot = params.overshoot_factor \ | 102 overshoot = params.overshoot_factor \ |
102 * min(self.OVERSHOOT_MAX_DIV, on_time) \ | 103 * min(self.OVERSHOOT_MAX_DIV, on_time) \ |
103 / self.OVERSHOOT_MAX_DIV | 104 / self.OVERSHOOT_MAX_DIV |
104 D("on_time %(on_time)f, overshoot %(overshoot)f" % locals()) | 105 D("on_time %(on_time)f, overshoot %(overshoot)f" % locals()) |
105 | 106 |
106 if wort is not None: | 107 if wort is not None and (wort - overshoot) < params.fridge_setpoint: |
107 if (wort - overshoot) < params.fridge_setpoint: | 108 L("wort has cooled enough, %(wort)f" % locals() ) |
108 L("wort has cooled enough") | |
109 turn_off = True | 109 turn_off = True |
110 else: | 110 elif fridge is not None and fridge < fridge_min: |
111 # wort sensor is broken | 111 W("fridge off fallback, fridge %(fridge)f, min %(fridge_min)f" % locals()) |
112 if fridge is not None and fridge < fridge_min: | |
113 W("fridge off fallback") | |
114 turn_off = True | 112 turn_off = True |
115 | 113 |
116 if turn_off: | 114 if turn_off: |
117 L("Turning fridge off") | 115 L("Turning fridge off") |
118 self.off() | 116 self.off() |
119 self.fridge_off_clock = self.server.now() | 117 self.fridge_off_clock = self.server.now() |
120 | 118 |
121 else: | 119 else: |
122 # fridge is off | 120 # fridge is off |
123 turn_on = False | 121 turn_on = False |
124 if wort is not None: | 122 if wort is not None and wort >= wort_max: |
125 if wort >= wort_max: | |
126 L("Wort is too hot %f, max %f" % (wort, wort_max)) | 123 L("Wort is too hot %f, max %f" % (wort, wort_max)) |
127 turn_on = True | 124 turn_on = True |
128 else: | 125 elif fridge is not None and fridge >= fridge_max: |
129 # wort sensor is broken | 126 W("frdge on fallback, fridge %(fridge)f, max %(fridge_max)f" % locals()) |
130 if fridge is not None and fridge >= fridge_max: | |
131 W("frdge on fallback") | |
132 turn_on = True | 127 turn_on = True |
133 | 128 |
134 if turn_on: | 129 if turn_on: |
135 L("Turning fridge on") | 130 L("Turning fridge on") |
136 self.on() | 131 self.on() |