From 9b0e6603d5a21f27f791a5acc866f5601774de20 Mon Sep 17 00:00:00 2001 From: Roeland Date: Thu, 3 Oct 2024 14:49:17 +0200 Subject: [PATCH] Always add dummy values for all possible values to udp packet --- sma/CHANGELOG.md | 2 +- sma/config.yaml | 2 +- sma/src/emeter.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++ sma/src/mqtt.py | 62 +------------------------------------------ 4 files changed, 70 insertions(+), 63 deletions(-) diff --git a/sma/CHANGELOG.md b/sma/CHANGELOG.md index df33201..1c6c5ce 100644 --- a/sma/CHANGELOG.md +++ b/sma/CHANGELOG.md @@ -1,6 +1,6 @@ -## 0.1.1-rc1 +## 0.1.2-rc1 - Extend package to support tripower inverters diff --git a/sma/config.yaml b/sma/config.yaml index 41e367c..edba3bc 100644 --- a/sma/config.yaml +++ b/sma/config.yaml @@ -1,6 +1,6 @@ name: "SMA Energy Meter emulator" description: "Simulate one or more SMA energy meters based on mqtt messages." -version: "0.1.1-rc1" +version: "0.1.2-rc1" slug: sma url: "https://github.com/Roeland54/SMA-Energy-Meter-emulator" arch: diff --git a/sma/src/emeter.py b/sma/src/emeter.py index fb4702b..1bf4dfd 100644 --- a/sma/src/emeter.py +++ b/sma/src/emeter.py @@ -144,3 +144,70 @@ def initEmeterPacket(self, serNo): pSerNo = self.offsetOf(self.meterPacket, DSRC, self._headerLength) self.storeU32BE(pSerNo, serNo) + + # Add dummy values for measurements to make sure the package always contains these. Solves tripower inverters not recognizing the data as valid. + # Totals + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY, 0) + self.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR, 0) + + #L1 + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L1, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L1, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L1, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L1, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L1, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L1, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_CURRENT_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L1, 0) + + #L2 + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L2, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L2, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L2, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L2, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L2, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L2, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_CURRENT_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L2, 0) + + #L3 + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L3, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L3, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L3, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L3, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L3, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L3, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_CURRENT_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L3, 0) diff --git a/sma/src/mqtt.py b/sma/src/mqtt.py index cedea97..439e156 100644 --- a/sma/src/mqtt.py +++ b/sma/src/mqtt.py @@ -59,67 +59,7 @@ def on_message(client, userdata, msg): packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY, round(data['energyIn'] * 1000 * 3600)) packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER, round(data['powerOut'] *10)) packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY, round(data['energyOut'] * 1000 * 3600)) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY, 0) - packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR, 900) # assume almost perfect power factor of 0.9 for default value - - #L1 - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_CURRENT_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L1, 900) # assume almost perfect power factor of 0.9 for default value - - #L2 - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_CURRENT_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L2, 900) # assume almost perfect power factor of 0.9 for default value - - #L3 - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_CURRENT_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L3, 900) # assume almost perfect power factor of 0.9 for default value - + packet.end() packet_data = packet.getData()[:packet.getLength()]