From a926f0fdd34e9588454d453125f6e5ce1e32e010 Mon Sep 17 00:00:00 2001 From: janjaapko Date: Sat, 15 Feb 2025 12:17:27 +0100 Subject: [PATCH 1/7] add exception for missing value in modbus --- plugin.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index 9b2aa91..af1263d 100644 --- a/plugin.py +++ b/plugin.py @@ -9,7 +9,7 @@ # """ - + @@ -349,7 +349,11 @@ def onHeartbeat(self): Domoticz.Debug("-> looking up...") lookup_table = unit[Column.LOOKUP] - to_lookup = int(inverter_values[unit[Column.MODBUSNAME]]) + try: + to_lookup = int(inverter_values[unit[Column.MODBUSNAME]]) + except KeyError as e: + to_lookup = -1 + Domoticz.Error("missing data in modbus: "+str(e)) if to_lookup >= 0 and to_lookup < len(lookup_table): value = lookup_table[to_lookup] @@ -452,11 +456,13 @@ def contactInverter(self): Domoticz.Log("Connection Exception when trying to contact: {}:{} Device Address: {}".format(Parameters["Address"], Parameters["Port"], Parameters["Mode3"])) Domoticz.Log("Retrying to communicate with inverter after: {}".format(self.retryafter)) + return else: if inverter_values: Domoticz.Log("Connection established with: {}:{} Device Address: {}".format(Parameters["Address"], Parameters["Port"], Parameters["Mode3"])) + Domoticz.Debug("inverter_values = '" +format(inverter_values)+"'") inverter_type = solaredge_modbus.sunspecDID(inverter_values["c_sunspec_did"]) Domoticz.Log("Inverter type: {}".format(inverter_type)) @@ -523,6 +529,7 @@ def contactInverter(self): else: Domoticz.Log("Connection established with: {}:{} Device Address: {}. BUT... inverter returned no information".format(Parameters["Address"], Parameters["Port"], Parameters["Mode3"])) Domoticz.Log("Retrying to communicate with inverter after: {}".format(self.retryafter)) + Domoticz.Debug("inverter_values = '" +format(inverter_values)+"'") else: Domoticz.Log("Retrying to communicate with inverter after: {}".format(self.retryafter)) From 91de62c75d23a303f09ecf4723337eec77e87f9f Mon Sep 17 00:00:00 2001 From: janjaapko Date: Sat, 15 Feb 2025 13:28:56 +0100 Subject: [PATCH 2/7] handle additional exception --- plugin.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index af1263d..f4ca6fe 100644 --- a/plugin.py +++ b/plugin.py @@ -353,7 +353,7 @@ def onHeartbeat(self): to_lookup = int(inverter_values[unit[Column.MODBUSNAME]]) except KeyError as e: to_lookup = -1 - Domoticz.Error("missing data in modbus: "+str(e)) + Domoticz.Error("missing data in modbus inverter_values: "+str(e)) if to_lookup >= 0 and to_lookup < len(lookup_table): value = lookup_table[to_lookup] @@ -384,7 +384,11 @@ def onHeartbeat(self): else: Domoticz.Debug("-> copying...") - value = inverter_values[unit[Column.MODBUSNAME]] + try: + value = inverter_values[unit[Column.MODBUSNAME]] + except KeyError as e: + value = "Key not found in inverter_values table: {}".format(inverter_values) + Domoticz.Error("missing data in modbus inverter_values: "+str(e)) Domoticz.Debug("value = {}".format(value)) From 8652abacd33657cd7bda4af19613f2949283bc0c Mon Sep 17 00:00:00 2001 From: janjaapko Date: Sat, 15 Feb 2025 14:38:50 +0100 Subject: [PATCH 3/7] handle another additional exception --- plugin.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plugin.py b/plugin.py index f4ca6fe..296fc7a 100644 --- a/plugin.py +++ b/plugin.py @@ -365,12 +365,16 @@ def onHeartbeat(self): elif unit[Column.MATH] and Parameters["Mode4"] == "math_enabled": Domoticz.Debug("-> calculating...") m = unit[Column.MATH] - if unit[Column.MODBUSSCALE]: - m.update(inverter_values[unit[Column.MODBUSNAME]], inverter_values[unit[Column.MODBUSSCALE]]) - else: - m.update(inverter_values[unit[Column.MODBUSNAME]]) + try: + if unit[Column.MODBUSSCALE]: + m.update(inverter_values[unit[Column.MODBUSNAME]], inverter_values[unit[Column.MODBUSSCALE]]) + else: + m.update(inverter_values[unit[Column.MODBUSNAME]]) - value = m.get() + value = m.get() + except KeyError as e: + value = "Key not found in inverter_values table: {}".format(inverter_values) + Domoticz.Error("missing data in modbus inverter_values: "+str(e)) # When there is no math object then just store the latest value. # Some values from the inverter need to be scaled before they can be stored. From fd33e7f79bcbeacb27918b365f64f7146d6a5ccd Mon Sep 17 00:00:00 2001 From: janjaapko Date: Sat, 15 Feb 2025 16:37:25 +0100 Subject: [PATCH 4/7] skip loop on no data --- plugin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin.py b/plugin.py index 296fc7a..21f4b66 100644 --- a/plugin.py +++ b/plugin.py @@ -354,6 +354,7 @@ def onHeartbeat(self): except KeyError as e: to_lookup = -1 Domoticz.Error("missing data in modbus inverter_values: "+str(e)) + continue #data is missing, no point to continue for this device if to_lookup >= 0 and to_lookup < len(lookup_table): value = lookup_table[to_lookup] From 9e0aa0272942c9e9ae07f693b261ef4ab9c24b69 Mon Sep 17 00:00:00 2001 From: janjaapko Date: Tue, 18 Feb 2025 08:48:06 +0100 Subject: [PATCH 5/7] skip more loops on no data --- plugin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index 21f4b66..b6568c4 100644 --- a/plugin.py +++ b/plugin.py @@ -376,7 +376,8 @@ def onHeartbeat(self): except KeyError as e: value = "Key not found in inverter_values table: {}".format(inverter_values) Domoticz.Error("missing data in modbus inverter_values: "+str(e)) - + continue + # When there is no math object then just store the latest value. # Some values from the inverter need to be scaled before they can be stored. @@ -394,6 +395,7 @@ def onHeartbeat(self): except KeyError as e: value = "Key not found in inverter_values table: {}".format(inverter_values) Domoticz.Error("missing data in modbus inverter_values: "+str(e)) + continue Domoticz.Debug("value = {}".format(value)) From dae6a1e6990a7232edf161a974bdef88c4663bf0 Mon Sep 17 00:00:00 2001 From: janjaapko Date: Tue, 18 Feb 2025 17:16:29 +0100 Subject: [PATCH 6/7] ad one more loop --- plugin.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index b6568c4..bec50a0 100644 --- a/plugin.py +++ b/plugin.py @@ -317,7 +317,7 @@ def onHeartbeat(self): inverter_values = self.inverter.read_all() except ConnectionException: inverter_values = None - Domoticz.Debug("ConnectionException") + Domoticz.Error("ConnectionException") else: if inverter_values: @@ -384,7 +384,11 @@ def onHeartbeat(self): elif unit[Column.MODBUSSCALE]: Domoticz.Debug("-> scaling...") # we need to do some calculation here - value = inverter_values[unit[Column.MODBUSNAME]] * (10 ** inverter_values[unit[Column.MODBUSSCALE]]) + try: + value = inverter_values[unit[Column.MODBUSNAME]] * (10 ** inverter_values[unit[Column.MODBUSSCALE]]) + except KeyError as e: + Domoticz.Error("missing data in modbus inverter_values: "+str(e)) + continue # Some values require no action but storing in Domoticz. From 2e34784462b78f8a7c06fb31edbae4109ab5ce37 Mon Sep 17 00:00:00 2001 From: janjaapko Date: Thu, 20 Feb 2025 21:06:06 +0100 Subject: [PATCH 7/7] return iso continue --- plugin.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin.py b/plugin.py index bec50a0..dc24f0f 100644 --- a/plugin.py +++ b/plugin.py @@ -354,7 +354,7 @@ def onHeartbeat(self): except KeyError as e: to_lookup = -1 Domoticz.Error("missing data in modbus inverter_values: "+str(e)) - continue #data is missing, no point to continue for this device + return #data is missing, no point to continue for this device if to_lookup >= 0 and to_lookup < len(lookup_table): value = lookup_table[to_lookup] @@ -376,7 +376,7 @@ def onHeartbeat(self): except KeyError as e: value = "Key not found in inverter_values table: {}".format(inverter_values) Domoticz.Error("missing data in modbus inverter_values: "+str(e)) - continue + return # When there is no math object then just store the latest value. # Some values from the inverter need to be scaled before they can be stored. @@ -388,7 +388,7 @@ def onHeartbeat(self): value = inverter_values[unit[Column.MODBUSNAME]] * (10 ** inverter_values[unit[Column.MODBUSSCALE]]) except KeyError as e: Domoticz.Error("missing data in modbus inverter_values: "+str(e)) - continue + return # Some values require no action but storing in Domoticz. @@ -399,7 +399,7 @@ def onHeartbeat(self): except KeyError as e: value = "Key not found in inverter_values table: {}".format(inverter_values) Domoticz.Error("missing data in modbus inverter_values: "+str(e)) - continue + return Domoticz.Debug("value = {}".format(value))