Compare commits

...
12 Commits
3 changed files with 47 additions and 28 deletions
+8 -8
View File
@@ -6,33 +6,33 @@
"contours": [ "contours": [
{ {
"sensor": "/devices/workroom_weather/controls/t", "sensor": "/devices/workroom_weather/controls/t",
"control": "/devices/wb-gpio/controls/EXT1_R3A6" "control": "/devices/wb-gpio/controls/EXT1_R3A6/on"
}, },
{ {
"sensor": "/devices/bathroom_weather/controls/t", "sensor": "/devices/bathroom_weather/controls/t",
"control": "/devices/wb-gpio/controls/EXT1_R3A5" "control": "/devices/wb-gpio/controls/EXT1_R3A5/on"
}, },
{ {
"sensor": "/devices/entrance_weather/controls/t", "sensor": "/devices/entrance_weather/controls/t",
"control": "/devices/wb-gpio/controls/EXT1_R3A1" "control": "/devices/wb-gpio/controls/EXT1_R3A1/on"
}, },
{ {
"sensor": "/devices/corridor_weather/controls/t", "sensor": "/devices/corridor_weather/controls/t",
"control": "/devices/wb-gpio/controls/EXT1_R3A2" "control": "/devices/wb-gpio/controls/EXT1_R3A2/on"
}, },
{ {
"sensor": "/devices/techroom_weather/controls/t", "sensor": "/devices/techroom_weather/controls/t",
"control": "/devices/wb-gpio/controls/EXT1_R3A4" "control": "/devices/wb-gpio/controls/EXT1_R3A4/on"
}, },
{ {
"sensor": "/devices/kitchen_weather/controls/t", "sensor": "/devices/kitchen_weather/controls/t",
"control": "/devices/wb-gpio/controls/EXT1_R3A3" "control": "/devices/wb-gpio/controls/EXT1_R3A3/on"
} }
], ],
"target_temperature": 21.0, "target_temperature": 21.0,
"hysteresis": 0.5, "hysteresis": 0.5,
"boiler_exhaust_t": "/devices/wb-w1/controls/28-000000860adf", "boiler_exhaust_t": "/devices/wb-w1/controls/28-000000860adf",
"pump_control": "/devices/wb-gpio/controls/EXT1_R3A8", "pump_control": "/devices/wb-gpio/controls/EXT1_R3A8/on",
"boiler_control": "/devices/wb-gpio/controls/EXT1_R3A7" "boiler_control": "/devices/wb-gpio/controls/EXT1_R3A7/on"
} }
+6 -3
View File
@@ -25,12 +25,15 @@ class Contour:
return self.current_value return self.current_value
return None return None
def check_state(self, state_value): def check_state(self, state_value, force = False):
if self.state == state_value: if self.state == state_value:
return return False
if (self.state is None) or (time.time() - self.state_change_time > self.CHANGE_FREQ): if (self.state is None) or (time.time() - self.state_change_time > self.CHANGE_FREQ) or force:
self.state = state_value self.state = state_value
self.state_change_time = time.time()
self.logger.info("Contour " + self.sensor_topic + " changed state to " + str(self.state)) self.logger.info("Contour " + self.sensor_topic + " changed state to " + str(self.state))
return True
return False
def update_target(self, target_value): def update_target(self, target_value):
self.target_value = target_value self.target_value = target_value
Regular → Executable
+33 -17
View File
@@ -105,10 +105,13 @@ def on_message(client, userdata, msg):
any_opened_start = 0 any_opened_start = 0
any_opened = False any_opened = False
boiler_out = 0
pump_out = 0
def check_temperatures(): def check_temperatures():
"""Check temperatures against target and control GPIO""" """Check temperatures against target and control GPIO"""
global any_opened_start, any_opened global any_opened_start, any_opened, boiler_out, pump_out
# check boiler exhaust, turn off if too big # check boiler exhaust, turn off if too big
if (boiler_exhaust_t > BOILER_EXHAUST_LIMIT): if (boiler_exhaust_t > BOILER_EXHAUST_LIMIT):
logger.error("Boiler exhaust overheat") logger.error("Boiler exhaust overheat")
@@ -116,9 +119,9 @@ def check_temperatures():
# turn on the pump # turn on the pump
# and turn off the boiler of course # and turn off the boiler of course
for c in contours: for c in contours:
mqtt_client.publish(c.out_topic, "1", retain=True) c.check_state(True, True)
mqtt_client.publish(boiler_control, "0", retain=True) boiler_out = 0
mqtt_client.publish(pump_control, "1", retain=True) pump_out = 1
return return
# #
sum_t = 0 sum_t = 0
@@ -132,9 +135,10 @@ def check_temperatures():
if count_t == 0: if count_t == 0:
logger.error("No temperatures available, switch to full-on mode") logger.error("No temperatures available, switch to full-on mode")
for c in contours: for c in contours:
mqtt_client.publish(c.out_topic, "1", retain=True) c.check_state(True, True)
# turn on boiler # turn on boiler
mqtt_client.publish(boiler_control, "1", retain=True) boiler_out = 1
pump_out = 1
return return
for c in contours: for c in contours:
@@ -143,20 +147,18 @@ def check_temperatures():
# sensor is offline # sensor is offline
if contour_t is None: if contour_t is None:
contour_t = sum_t / count_t contour_t = sum_t / count_t
logger.info("Contour " + c.sensor_topic + " has no data from sensor, using others' average")
target_t = target_temp target_t = target_temp
if not c.target_value is None: if not c.target_value is None:
target_t = c.target_value target_t = c.target_value
if contour_t < target_t - hysteresis: if contour_t < target_t - hysteresis:
# should turn on contour # should turn on contour
c.check_state(True) if c.check_state(True):
logger.info("target: " + str(target_t) + " current: " + str(contour_t) + " hyst: " + str(hysteresis))
if contour_t > target_t + hysteresis: if contour_t > target_t + hysteresis:
# should turn off contour # should turn off contour
c.check_state(False) if c.check_state(False):
if c.state: logger.info("target: " + str(target_t) + " current: " + str(contour_t) + " hyst: " + str(hysteresis))
# 0 means "closed"
mqtt_client.publish(c.out_topic, "1", retain=True)
else:
mqtt_client.publish(c.out_topic, "0", retain=True)
if any_opened: if any_opened:
any_opened = False any_opened = False
@@ -171,17 +173,31 @@ def check_temperatures():
logger.debug("Any opened: " + str(any_opened) + " aos " + str(any_opened_start) + " time " + str(time.time())) logger.debug("Any opened: " + str(any_opened) + " aos " + str(any_opened_start) + " time " + str(time.time()))
if any_opened and time.time() - any_opened_start > BOILER_TURN_ON_AFTER: if any_opened and time.time() - any_opened_start > BOILER_TURN_ON_AFTER:
mqtt_client.publish(boiler_control, "1", retain=True) logger.info("Starting up pump and boiler, contours should be opened now")
mqtt_client.publish(pump_control, "1", retain=True) boiler_out = 1
pump_out = 1
else: else:
mqtt_client.publish(boiler_control, "0", retain=True) logger.info("All contours are considered closed, shutting down boiler and pump")
mqtt_client.publish(pump_control, "0", retain=True) boiler_out = 0
pump_out = 0
def issue_commands():
for c in contours:
if c.state:
# 0 means "opened"
mqtt_client.publish(c.out_topic, 0, retain=True)
else:
mqtt_client.publish(c.out_topic, 1, retain=True)
mqtt_client.publish(boiler_control, boiler_out, retain=True)
mqtt_client.publish(pump_control, pump_out, retain=True)
def main_cycle(): def main_cycle():
"""Main 5-second cycle""" """Main 5-second cycle"""
while True: while True:
try: try:
check_temperatures() check_temperatures()
issue_commands()
except Exception as e: except Exception as e:
logger.error(f"Error in main cycle: {e}") logger.error(f"Error in main cycle: {e}")
# Wait 5 seconds # Wait 5 seconds