Отсечка по температуре выхода бойлера

This commit is contained in:
ftc
2025-12-07 15:09:14 +03:00
parent 0de50dcecc
commit bfbb6519f8
+20
View File
@@ -21,8 +21,11 @@ CONFIG_FILE = "config.json"
# will turn on boiler after this amount of opened contour time
# (this is to make sure valve has time for opening)
BOILER_TURN_ON_AFTER = 90
# will turn off boiler if it's exhaust temperature is too high
BOILER_EXHAUST_LIMIT = 50
contours = []
boiler_exhaust_t = 0
config: Dict[str, Any] = {}
# MQTT client
@@ -72,17 +75,23 @@ def on_connect(client, userdata, flags, rc):
for k in contours:
client.subscribe(k.sensor_topic)
logger.info(f"Subscribed to: {k.sensor_topic}")
# and boiler exhaust topic
client.subscribe(config.get('boiler_exhaust_t'))
else:
logger.error(f"Connection failed with code: {rc}")
def on_message(client, userdata, msg):
"""MQTT message callback - store temperature values"""
global contours, boiler_exhaust_t
try:
for k in contours:
if (k.sensor_topic == msg.topic):
temperature = float(msg.payload.decode('utf-8'))
k.update(temperature)
logger.debug(f"Updated {k.sensor_topic}: {temperature}°C")
if msg.topic == config.get('boiler_exhaust_t'):
boiler_exhaust_t = float(msg.payload.decode('utf-8'))
logger.debug(f"Updated boiler exhaust: {boiler_exhaust_t}°C")
except ValueError:
logger.error(f"Invalid temperature value: {msg.payload}")
except Exception as e:
@@ -94,6 +103,17 @@ any_opened = False
def check_temperatures():
"""Check temperatures against target and control GPIO"""
global any_opened_start, any_opened
# check boiler exhaust, turn off if too big
if (boiler_exhaust_t > BOILER_EXHAUST_LIMIT):
logger.error("Boiler exhaust overheat")
# will open all contours (to force coolant circulation)
# and turn off the boiler of course
for c in contours:
# valves are normally-opened, so 0 means "open"
mqtt_client.publish(c.out_topic, "0", retain=True)
mqtt_client.publish(boiler_control, "0", retain=True)
return
#
sum_t = 0
count_t = 0
for c in contours: