6 Commits

Author SHA1 Message Date
dbdd24822e fix
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-11-07 22:15:20 +01:00
78a68f9009 fix
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-11-07 22:10:39 +01:00
fbb9aa6665 fix
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-11-07 22:05:13 +01:00
51995fc489 status text output
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-11-07 20:02:03 +01:00
e6b4733a60 overwrite window added
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-11-07 19:22:41 +01:00
62ce6f1b9c logging adjusted
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-11-07 14:30:53 +01:00
3 changed files with 35 additions and 16 deletions

View File

@ -10,6 +10,7 @@ data:
MQTT_BOX_TOPIC_PREFIXES: | MQTT_BOX_TOPIC_PREFIXES: |
{ {
"high_temp": "heating/config/high_temp/", "high_temp": "heating/config/high_temp/",
"overwrite_window": "heating/overwrite_window/",
"cmd": "heating/command/" "cmd": "heating/command/"
} }
MQTT_CENTRAL_TOPICS: | MQTT_CENTRAL_TOPICS: |
@ -19,13 +20,14 @@ data:
"status": "heating/system/status" "status": "heating/system/status"
} }
MQTT_STATUS_TOPIC: "heating/status" MQTT_STATUS_TOPIC: "heating/status"
MQTT_CONTEXT_TOPIC_PREFIX: "heating/context/"
OFF_TEMPERATURE: "5.0" OFF_TEMPERATURE: "5.0"
LOW_TEMPERATURE: "15.0" LOW_TEMPERATURE: "15.0"
DEFAULT_HIGH_TEMPERATURE: "21.0" DEFAULT_HIGH_TEMPERATURE: "21.0"
MAINTENANCE_TEMPERATURE: "30.0" MAINTENANCE_TEMPERATURE: "30.0"
BOXES: | BOXES: |
{ {
"box1": { "patty": {
"label": "patty", "label": "patty",
"windows": [ "windows": [
{ "topic": "homegear/instance1/plain/18/1/STATE", "label": "Garten rechts" }, { "topic": "homegear/instance1/plain/18/1/STATE", "label": "Garten rechts" },
@ -33,7 +35,7 @@ data:
], ],
"output_topic": "heating/homegear/instance1/set/39/1/SET_TEMPERATURE" "output_topic": "heating/homegear/instance1/set/39/1/SET_TEMPERATURE"
}, },
"box2": { "kueche": {
"label": "kueche", "label": "kueche",
"windows": [ "windows": [
{ "topic": "homegear/instance1/plain/37/1/STATE", "label": "Garten Fenster" }, { "topic": "homegear/instance1/plain/37/1/STATE", "label": "Garten Fenster" },
@ -43,27 +45,27 @@ data:
], ],
"output_topic": "heating/homegear/instance1/set/40/1/SET_TEMPERATURE" "output_topic": "heating/homegear/instance1/set/40/1/SET_TEMPERATURE"
}, },
"box3": { "bad_oben": {
"label": "bad_oben", "label": "bad_oben",
"windows": [ "windows": [
], ],
"output_topic": "heating/homegear/instance1/set/41/1/SET_TEMPERATURE" "output_topic": "heating/homegear/instance1/set/41/1/SET_TEMPERATURE"
}, },
"box4": { "schlafzimmer": {
"label": "schlafzimmer", "label": "schlafzimmer",
"windows": [ "windows": [
{ "topic": "homegear/instance1/plain/52/1/STATE", "label": "Strasse" } { "topic": "homegear/instance1/plain/52/1/STATE", "label": "Strasse" }
], ],
"output_topic": "heating/homegear/instance1/set/42/1/SET_TEMPERATURE" "output_topic": "heating/homegear/instance1/set/42/1/SET_TEMPERATURE"
}, },
"box5": { "wolfgang": {
"label": "wolfgang", "label": "wolfgang",
"windows": [ "windows": [
{ "topic": "homegear/instance1/plain/24/1/STATE", "label": "Garten" } { "topic": "homegear/instance1/plain/24/1/STATE", "label": "Garten" }
], ],
"output_topic": "heating/homegear/instance1/set/43/1/SET_TEMPERATURE" "output_topic": "heating/homegear/instance1/set/43/1/SET_TEMPERATURE"
}, },
"box6": { "esszimmer": {
"label": "esszimmer", "label": "esszimmer",
"windows": [ "windows": [
{ "topic": "homegear/instance1/plain/26/1/STATE", "label": "Strasse rechts" }, { "topic": "homegear/instance1/plain/26/1/STATE", "label": "Strasse rechts" },
@ -71,7 +73,7 @@ data:
], ],
"output_topic": "heating/homegear/instance1/set/45/1/SET_TEMPERATURE" "output_topic": "heating/homegear/instance1/set/45/1/SET_TEMPERATURE"
}, },
"box7": { "wohnzimmer": {
"label": "wohnzimmer", "label": "wohnzimmer",
"windows": [ "windows": [
{ "topic": "homegear/instance1/plain/28/1/STATE", "label": "Garten rechts" }, { "topic": "homegear/instance1/plain/28/1/STATE", "label": "Garten rechts" },
@ -79,7 +81,7 @@ data:
], ],
"output_topic": "heating/homegear/instance1/set/46/1/SET_TEMPERATURE" "output_topic": "heating/homegear/instance1/set/46/1/SET_TEMPERATURE"
}, },
"box8": { "bad_unten": {
"label": "bad_unten", "label": "bad_unten",
"windows": [ "windows": [
{ "topic": "homegear/instance1/plain/44/1/STATE", "label": "Strasse" } { "topic": "homegear/instance1/plain/44/1/STATE", "label": "Strasse" }

View File

@ -19,6 +19,7 @@ LOW_TEMPERATURE = os.getenv("LOW_TEMPERATURE", "15.0")
DEFAULT_HIGH_TEMPERATURE = os.getenv("DEFAULT_HIGH_TEMPERATURE", "21.0") DEFAULT_HIGH_TEMPERATURE = os.getenv("DEFAULT_HIGH_TEMPERATURE", "21.0")
MAINTENANCE_TEMPERATURE = os.getenv("MAINTENANCE_TEMPERATURE", "30.0") MAINTENANCE_TEMPERATURE = os.getenv("MAINTENANCE_TEMPERATURE", "30.0")
STATUS_TOPIC = os.getenv("MQTT_STATUS_TOPIC") STATUS_TOPIC = os.getenv("MQTT_STATUS_TOPIC")
CONTEXT_TOPIC_PREFIX = os.getenv("MQTT_CONTEXT_TOPIC_PREFIX")
# Check if required environment variables are set # Check if required environment variables are set
missing_vars = [] missing_vars = []
@ -32,6 +33,8 @@ if not CENTRAL_TOPICS_CONFIG:
missing_vars.append('MQTT_CENTRAL_TOPICS') missing_vars.append('MQTT_CENTRAL_TOPICS')
if not STATUS_TOPIC: if not STATUS_TOPIC:
missing_vars.append('MQTT_STATUS_TOPIC') missing_vars.append('MQTT_STATUS_TOPIC')
if not CONTEXT_TOPIC_PREFIX:
missing_vars.append('MQTT_CONTEXT_TOPIC_PREFIX')
if missing_vars: if missing_vars:
logger.error(f"Error: The following environment variables are not set: {', '.join(missing_vars)}") logger.error(f"Error: The following environment variables are not set: {', '.join(missing_vars)}")
@ -46,6 +49,7 @@ context['low_temperature'] = LOW_TEMPERATURE
context['default_high_temperature'] = DEFAULT_HIGH_TEMPERATURE context['default_high_temperature'] = DEFAULT_HIGH_TEMPERATURE
context['maintenance_temperature'] = MAINTENANCE_TEMPERATURE context['maintenance_temperature'] = MAINTENANCE_TEMPERATURE
context['status_topic'] = STATUS_TOPIC context['status_topic'] = STATUS_TOPIC
context['context_topic_prefix'] = CONTEXT_TOPIC_PREFIX
# Load box configurations from JSON # Load box configurations from JSON
try: try:
@ -66,7 +70,7 @@ try:
box_topic_prefixes = json.loads(BOX_TOPIC_PREFIXES_CONFIG) box_topic_prefixes = json.loads(BOX_TOPIC_PREFIXES_CONFIG)
# Validation: Check if the required keys are present # Validation: Check if the required keys are present
required_keys = {'high_temp', 'cmd'} required_keys = {'high_temp', 'cmd', 'overwrite_window'}
missing_keys = required_keys - box_topic_prefixes.keys() missing_keys = required_keys - box_topic_prefixes.keys()
if missing_keys: if missing_keys:

View File

@ -1,4 +1,5 @@
from loguru import logger from loguru import logger
import json
# context # context
@ -20,6 +21,7 @@ def prepare_context(box_name, context):
local_context['general_off'] = False local_context['general_off'] = False
local_context['maintenance_mode'] = False local_context['maintenance_mode'] = False
local_context['overwrite_window'] = False
local_context['window_state'] = {} local_context['window_state'] = {}
for w in context['boxes'][box_name]['windows']: for w in context['boxes'][box_name]['windows']:
@ -35,8 +37,8 @@ def process_message(box_name, topic_key, payload, context):
try: try:
box = context['boxes'][box_name] box = context['boxes'][box_name]
local_context = box['context'] local_context = box['context']
logger.info(f"Local context before: {local_context}") logger.info(f"[{box_name}] Local context before: {local_context}")
logger.info(f"[{box_name}, {box['label']}] Processing message for '{topic_key}': {payload}") logger.info(f"[{box_name}] Processing message for '{topic_key}': {payload}")
match topic_key.split('/'): match topic_key.split('/'):
case [ primary_key, sub_key ] if primary_key == 'window': case [ primary_key, sub_key ] if primary_key == 'window':
@ -45,6 +47,8 @@ def process_message(box_name, topic_key, payload, context):
result = process_high_temp(box_name, context, local_context, payload) result = process_high_temp(box_name, context, local_context, payload)
case [ primary_key ] if primary_key == 'cmd': case [ primary_key ] if primary_key == 'cmd':
result = process_cmd(box_name, context, local_context, payload) result = process_cmd(box_name, context, local_context, payload)
case [ primary_key ] if primary_key == 'overwrite_window':
result = process_overwrite_window(box_name, context, local_context, payload)
case [ primary_key ] if primary_key == 'general_off': case [ primary_key ] if primary_key == 'general_off':
result = process_general_off(box_name, context, local_context, payload) result = process_general_off(box_name, context, local_context, payload)
case [ primary_key ] if primary_key == 'maintenance_mode': case [ primary_key ] if primary_key == 'maintenance_mode':
@ -60,7 +64,10 @@ def process_message(box_name, topic_key, payload, context):
context['client'].publish(publish_topic, result_message) context['client'].publish(publish_topic, result_message)
logger.info(f"[{box_name}] Result published on '{publish_topic}': {status} {result_message}") logger.info(f"[{box_name}] Result published on '{publish_topic}': {status} {result_message}")
logger.info(f"Local context after: {local_context}") context_topic = f"{context['context_topic_prefix']}{box['label']}"
context['client'].publish(context_topic, json.dumps(local_context))
logger.info(f"[{box_name}] Local context after: {local_context}")
except Exception as e: except Exception as e:
logger.error(f"[{box_name}] Error processing '{topic_key}': {e}") logger.error(f"[{box_name}] Error processing '{topic_key}': {e}")
@ -74,10 +81,11 @@ def _calculate_output_temperature(local_context):
local_context['output_temperature'] = local_context['off_temperature'] local_context['output_temperature'] = local_context['off_temperature']
return return
# an open window shuts off the heating # an open window shuts off the heating
for w in local_context['window_state'].values(): if not local_context['overwrite_window']:
if w == 'open': for w in local_context['window_state'].values():
local_context['output_temperature'] = local_context['off_temperature'] if w == 'open':
return local_context['output_temperature'] = local_context['off_temperature']
return
# finally evaluate the mode # finally evaluate the mode
if local_context['mode'] == 'off': if local_context['mode'] == 'off':
local_context['output_temperature'] = local_context['off_temperature'] local_context['output_temperature'] = local_context['off_temperature']
@ -113,6 +121,11 @@ def process_cmd(box_name, context, local_context, payload):
logger.error(f"Invalid cmd for {box_name} received: {payload}") logger.error(f"Invalid cmd for {box_name} received: {payload}")
return (local_context['output_temperature'], False) return (local_context['output_temperature'], False)
def process_overwrite_window(box_name, context, local_context, payload):
local_context['overwrite_window'] = (payload.lower() in ('true'))
_calculate_output_temperature(local_context)
return (local_context['output_temperature'], False)
def process_high_temp(box_name, context, local_context, payload): def process_high_temp(box_name, context, local_context, payload):
local_context['high_temperature'] = payload local_context['high_temperature'] = payload
_calculate_output_temperature(local_context) _calculate_output_temperature(local_context)