From 810456fbe0c7866c4bcb0daf5d7897e689ee9b92 Mon Sep 17 00:00:00 2001 From: "Reinhard Weber (Brandstaedter)" Date: Thu, 21 Sep 2023 09:55:04 +0200 Subject: [PATCH 1/4] Dev (#22) * ensure mqtt message has no empty payload (#21) --- src/solarflow-control.py | 47 +++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/solarflow-control.py b/src/solarflow-control.py index 5457003..bbc49ac 100644 --- a/src/solarflow-control.py +++ b/src/solarflow-control.py @@ -214,28 +214,31 @@ def on_message(client, userdata, msg): #log.info(f'No solarInputPower measurement received for {seconds}s') solarflow_values.pop(0) solarflow_values.append(0) - - if msg.topic == topic_acinput: - on_inverter_update(msg.payload.decode()) - if msg.topic in topics_direct_panel: - on_direct_panel(msg.payload.decode()) - if msg.topic == topic_solarflow_solarinput: - on_solarflow_solarinput(msg.payload.decode()) - if msg.topic == topic_solarflow_electriclevel: - on_solarflow_electriclevel(msg.payload.decode()) - if msg.topic == topic_solarflow_outputpack: - on_solarflow_outputpack(msg.payload.decode()) - if msg.topic == topic_solarflow_packinput: - on_solarflow_packinput(msg.payload.decode()) - if msg.topic == topic_solarflow_outputhome: - on_solarflow_outputhome(msg.payload.decode()) - if "maxTemp" in msg.topic and "batteries" in msg.topic: - on_solarflow_maxtemp(msg.payload.decode()) - if "socLevel" in msg.topic and "batteries" in msg.topic: - sn = msg.topic.split('/')[-2] - on_solarflow_battery_soclevel(sn, msg.payload.decode()) - if msg.topic in topics_house: - on_smartmeter_update(client,msg) + + if msg.payload: + if msg.topic == topic_acinput: + on_inverter_update(msg.payload.decode()) + if msg.topic in topics_direct_panel: + on_direct_panel(msg.payload.decode()) + if msg.topic == topic_solarflow_solarinput: + on_solarflow_solarinput(msg.payload.decode()) + if msg.topic == topic_solarflow_electriclevel: + on_solarflow_electriclevel(msg.payload.decode()) + if msg.topic == topic_solarflow_outputpack: + on_solarflow_outputpack(msg.payload.decode()) + if msg.topic == topic_solarflow_packinput: + on_solarflow_packinput(msg.payload.decode()) + if msg.topic == topic_solarflow_outputhome: + on_solarflow_outputhome(msg.payload.decode()) + if "maxTemp" in msg.topic and "batteries" in msg.topic: + on_solarflow_maxtemp(msg.payload.decode()) + if "socLevel" in msg.topic and "batteries" in msg.topic: + sn = msg.topic.split('/')[-2] + on_solarflow_battery_soclevel(sn, msg.payload.decode()) + if msg.topic in topics_house: + on_smartmeter_update(client,msg) + else: + log.warning(f'Received a MQTT message without payload on topic {msg.topic}') def on_connect(client, userdata, flags, rc): From 185e08924d4cebdd18ac9b763f464e68bf597167 Mon Sep 17 00:00:00 2001 From: Reinhard Weber Date: Thu, 21 Sep 2023 13:23:56 +0200 Subject: [PATCH 2/4] forgot to subscripe topics --- src/solarflow-control.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/solarflow-control.py b/src/solarflow-control.py index bbc49ac..7f46d8f 100644 --- a/src/solarflow-control.py +++ b/src/solarflow-control.py @@ -258,6 +258,9 @@ def connect_mqtt() -> mqtt_client: def subscribe(client: mqtt_client): for th in topics_house: client.subscribe(th) + + for dp in topics_direct_panel: + client.subscribe(dp) client.subscribe(topic_acinput) client.subscribe(topic_solarflow_solarinput) From c52e2c5d30c8fcd4363c105d53d9686a5b7a96cd Mon Sep 17 00:00:00 2001 From: Reinhard Weber Date: Thu, 21 Sep 2023 13:32:04 +0200 Subject: [PATCH 3/4] proper parameters --- src/solarflow-control.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solarflow-control.py b/src/solarflow-control.py index 7f46d8f..3f3185c 100644 --- a/src/solarflow-control.py +++ b/src/solarflow-control.py @@ -152,7 +152,7 @@ def on_inverter_update(msg): inverter_values.pop(0) inverter_values.append(float(msg)) -def on_direct_panel(client,msg): +def on_direct_panel(msg): global direct_panel_values global direct_panel_power payload = json.loads(msg.payload.decode()) From 6079373a1c7678016b8308ff95c01737d63124b7 Mon Sep 17 00:00:00 2001 From: Reinhard Weber Date: Thu, 21 Sep 2023 13:37:29 +0200 Subject: [PATCH 4/4] support multiple panels properly --- src/solarflow-control.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solarflow-control.py b/src/solarflow-control.py index 3f3185c..278d693 100644 --- a/src/solarflow-control.py +++ b/src/solarflow-control.py @@ -219,7 +219,7 @@ def on_message(client, userdata, msg): if msg.topic == topic_acinput: on_inverter_update(msg.payload.decode()) if msg.topic in topics_direct_panel: - on_direct_panel(msg.payload.decode()) + on_direct_panel(msg) if msg.topic == topic_solarflow_solarinput: on_solarflow_solarinput(msg.payload.decode()) if msg.topic == topic_solarflow_electriclevel: