3 Commits

Author SHA1 Message Date
ee0efb6c19 converters
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-11-12 12:01:13 +01:00
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
3 changed files with 57 additions and 38 deletions

View File

@ -20,7 +20,7 @@ data:
"status": "heating/system/status" "status": "heating/system/status"
} }
MQTT_STATUS_TOPIC: "heating/status" MQTT_STATUS_TOPIC: "heating/status"
MQTT_STATUSTEXT_TOPIC_PREFIX: "heating/statustext/" 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"
@ -30,63 +30,71 @@ data:
"patty": { "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", "converter": "max" },
{ "topic": "homegear/instance1/plain/22/1/STATE", "label": "Garten links" } { "topic": "homegear/instance1/plain/22/1/STATE", "label": "Garten links", "converter": "max" }
], ],
"output_topic": "heating/homegear/instance1/set/39/1/SET_TEMPERATURE" "output_topic": "heating/homegear/instance1/set/39/1/SET_TEMPERATURE",
"output_converter": "max"
}, },
"kueche": { "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", "converter": "max" },
{ "topic": "homegear/instance1/plain/36/1/STATE", "label": "Garten Tuer" }, { "topic": "homegear/instance1/plain/36/1/STATE", "label": "Garten Tuer", "converter": "max" },
{ "topic": "homegear/instance1/plain/38/1/STATE", "label": "Strasse rechts" }, { "topic": "homegear/instance1/plain/38/1/STATE", "label": "Strasse rechts", "converter": "max" },
{ "topic": "homegear/instance1/plain/13/1/STATE", "label": "Strasse links" } { "topic": "homegear/instance1/plain/13/1/STATE", "label": "Strasse links", "converter": "max" }
], ],
"output_topic": "heating/homegear/instance1/set/40/1/SET_TEMPERATURE" "output_topic": "heating/homegear/instance1/set/40/1/SET_TEMPERATURE",
"output_converter": "max"
}, },
"bad_oben": { "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",
"output_converter": "max"
}, },
"schlafzimmer": { "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", "converter": "max" }
], ],
"output_topic": "heating/homegear/instance1/set/42/1/SET_TEMPERATURE" "output_topic": "heating/homegear/instance1/set/42/1/SET_TEMPERATURE",
"output_converter": "max"
}, },
"wolfgang": { "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", "converter": "max" }
], ],
"output_topic": "heating/homegear/instance1/set/43/1/SET_TEMPERATURE" "output_topic": "heating/homegear/instance1/set/43/1/SET_TEMPERATURE",
"output_converter": "max"
}, },
"esszimmer": { "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", "converter": "max" },
{ "topic": "homegear/instance1/plain/27/1/STATE", "label": "Strasse links" } { "topic": "homegear/instance1/plain/27/1/STATE", "label": "Strasse links", "converter": "max" }
], ],
"output_topic": "heating/homegear/instance1/set/45/1/SET_TEMPERATURE" "output_topic": "heating/homegear/instance1/set/45/1/SET_TEMPERATURE",
"output_converter": "max"
}, },
"wohnzimmer": { "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", "converter": "max" },
{ "topic": "homegear/instance1/plain/29/1/STATE", "label": "Garten links" } { "topic": "homegear/instance1/plain/29/1/STATE", "label": "Garten links", "converter": "max" }
], ],
"output_topic": "heating/homegear/instance1/set/46/1/SET_TEMPERATURE" "output_topic": "heating/homegear/instance1/set/46/1/SET_TEMPERATURE",
"output_converter": "max"
}, },
"bad_unten": { "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", "converter": "max" }
], ],
"output_topic": "heating/homegear/instance1/set/48/1/SET_TEMPERATURE" "output_topic": "heating/homegear/instance1/set/48/1/SET_TEMPERATURE",
"output_converter": "max"
} }
} }

View File

@ -19,7 +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")
STATUSTEXT_TOPIC_PREFIX = os.getenv("MQTT_STATUSTEXT_TOPIC_PREFIX") 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 = []
@ -33,8 +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 STATUSTEXT_TOPIC_PREFIX: if not CONTEXT_TOPIC_PREFIX:
missing_vars.append('MQTT_STATUSTEXT_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)}")
@ -49,7 +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['statustext_topic_prefix'] = STATUSTEXT_TOPIC_PREFIX context['context_topic_prefix'] = CONTEXT_TOPIC_PREFIX
# Load box configurations from JSON # Load box configurations from JSON
try: try:

View File

@ -1,6 +1,17 @@
from loguru import logger from loguru import logger
import json
CONVERTERS = {
"target_temperature_output": {
"max": lambda x: x["output_temperature"],
},
"window_contact_input": {
"max": lambda x: 'closed' if (x.lower() in ('false', 'close', 'closed')) else 'open'
}
}
# context # context
# boxes: structure of boxes # boxes: structure of boxes
# client: MQTT client # client: MQTT client
@ -58,13 +69,13 @@ def process_message(box_name, topic_key, payload, context):
raise Error(f"Unexcepted topic_key: {topic_key}, {payload}") raise Error(f"Unexcepted topic_key: {topic_key}, {payload}")
if result: if result:
(result_message, status) = result result_message = CONVERTERS["target_temperature_output"][box["output_converter"]](local_context)
publish_topic = box["output_topic"] if not status else context['status_topic'] publish_topic = box["output_topic"]
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}': {result_message}")
statustext_topic = f"{context['statustext_topic_prefix']}{box['label']}" context_topic = f"{context['context_topic_prefix']}{box['label']}"
context['client'].publish(statustext_topic, f"{local_context}") context['client'].publish(context_topic, json.dumps(local_context))
logger.info(f"[{box_name}] Local context after: {local_context}") logger.info(f"[{box_name}] Local context after: {local_context}")
except Exception as e: except Exception as e:
@ -100,17 +111,17 @@ def _calculate_output_temperature(local_context):
return return
def process_status(box_name, context, local_context, payload): def process_status(box_name, context, local_context, payload):
return (f"{local_context}", True) return False
def process_general_off(box_name, context, local_context, payload): def process_general_off(box_name, context, local_context, payload):
local_context['general_off'] = (payload.lower() in ('true')) local_context['general_off'] = (payload.lower() in ('true'))
_calculate_output_temperature(local_context) _calculate_output_temperature(local_context)
return (local_context['output_temperature'], False) return True
def process_maintenance_mode(box_name, context, local_context, payload): def process_maintenance_mode(box_name, context, local_context, payload):
local_context['maintenance_mode'] = (payload.lower() in ('true')) local_context['maintenance_mode'] = (payload.lower() in ('true'))
_calculate_output_temperature(local_context) _calculate_output_temperature(local_context)
return (local_context['output_temperature'], False) return True
def process_cmd(box_name, context, local_context, payload): def process_cmd(box_name, context, local_context, payload):
if payload.lower() in ('high', 'low', 'off'): if payload.lower() in ('high', 'low', 'off'):
@ -118,20 +129,20 @@ def process_cmd(box_name, context, local_context, payload):
_calculate_output_temperature(local_context) _calculate_output_temperature(local_context)
else: else:
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 True
def process_overwrite_window(box_name, context, local_context, payload): def process_overwrite_window(box_name, context, local_context, payload):
local_context['overwrite_window'] = (payload.lower() in ('true')) local_context['overwrite_window'] = (payload.lower() in ('true'))
_calculate_output_temperature(local_context) _calculate_output_temperature(local_context)
return (local_context['output_temperature'], False) return True
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)
return (local_context['output_temperature'], False) return True
def process_window(box_name, context, local_context, sub_key, payload): def process_window(box_name, context, local_context, sub_key, payload):
local_context['window_state'][sub_key] = 'closed' if (payload.lower() in ('false', 'close', 'closed')) else 'open' local_context['window_state'][sub_key] = 'closed' if (payload.lower() in ('false', 'close', 'closed')) else 'open'
_calculate_output_temperature(local_context) _calculate_output_temperature(local_context)
return (local_context['output_temperature'], False) return True