Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
fix packet init
Browse files Browse the repository at this point in the history
  • Loading branch information
Roeland authored and Roeland committed Oct 3, 2024
1 parent 9b0e660 commit a5f5b55
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 69 deletions.
2 changes: 1 addition & 1 deletion sma/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- https://developers.home-assistant.io/docs/add-ons/presentation#keeping-a-changelog -->

## 0.1.2-rc1
## 0.1.2-rc2

- Extend package to support tripower inverters

Expand Down
2 changes: 1 addition & 1 deletion sma/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "SMA Energy Meter emulator"
description: "Simulate one or more SMA energy meters based on mqtt messages."
version: "0.1.2-rc1"
version: "0.1.2-rc2"
slug: sma
url: "https://github.com/Roeland54/SMA-Energy-Meter-emulator"
arch:
Expand Down
135 changes: 68 additions & 67 deletions sma/src/emeter.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,74 @@ def begin(self, timeStampMs):
self.storeU32BE(self._pMeterTime, timeStampMs)
self._length = self.INITIAL_PAYLOAD_LENGTH

# 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)


def addMeasurementValue(self, id, value):
self._pPacketPos = self.storeU32BE(self._pPacketPos, id)
self._pPacketPos = self.storeU32BE(self._pPacketPos, value)
Expand Down Expand Up @@ -144,70 +212,3 @@ 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)

0 comments on commit a5f5b55

Please sign in to comment.