AlphaEss: calculate currents from powers#3173
Conversation
LKuemmel
left a comment
There was a problem hiding this comment.
Bitte in einem Kommentar festhalten, warum die Ströme entfernt wurden.
There was a problem hiding this comment.
Pull request overview
Adjusts AlphaESS counter phase-current reporting to avoid model-/firmware-dependent current scaling issues by deriving a per-phase scaling factor from the relationship between reported current, voltage, and per-phase power.
Changes:
- Reworks AlphaESS counter update logic to rescale phase currents using per-phase power readings.
- Introduces
scale_currents()helper to choose an appropriate scaling factor per phase. - Removes PeakFilter usage from the AlphaESS counter component.
Comments suppressed due to low confidence (1)
packages/modules/devices/alpha_ess/alpha_ess/counter.py:36
- The
PeakFilterwas removed from the counter component (import, initialization, andcheck_values(power, imported, exported)call). This also removes plausibility checks for power peaks and sudden imported/exported counter jumps, which can lead to storing implausible values (or losing warnings that other components still emit). If the intention is only to rescale phase currents, keepPeakFilterand continue calling it after readingpower/imported/exported.
def initialize(self) -> None:
self.__tcp_client: modbus.ModbusTcpClient_ = self.kwargs['tcp_client']
self.__device_config: AlphaEssConfiguration = self.kwargs['device_config']
self.__modbus_id: int = self.kwargs['modbus_id']
self.store = get_counter_value_store(self.component_config.id)
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))
def update(self):
time.sleep(0.1)
if self.__device_config.source == 0 and self.__device_config.version == 0:
power, exported, imported = self.__tcp_client.read_holding_registers(
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| scaled_currents.append(0) | ||
| else: | ||
| factor = c * 230 / p | ||
| rounded_factor = min(factors, key=lambda z: abs(factor - z)) |
There was a problem hiding this comment.
scale_currents() selects the nearest scaling factor via min(factors, key=...). In exact tie cases (e.g. computed factor exactly midway between 10 and 100), min(...) will pick the earlier entry in factors, which currently biases toward the smaller magnitude and can mis-scale currents by 10×. Consider making the selection deterministic for ties (e.g. prefer the larger magnitude) or switching to threshold-based rounding on abs(factor) so boundary cases don’t produce large errors.
| rounded_factor = min(factors, key=lambda z: abs(factor - z)) | |
| rounded_factor = min(factors, key=lambda z: (abs(factor - z), -abs(z))) |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Der Faktor der Phasenströme wurde wegen Problemen im Lastmanagement (zu niedrige Ströme) angepasst. Die Anpassung führt aber bei anderen Anlagen zu Problemen (zu hohe Ströme).
AlphaEss Anlagen haben unterschiedliche Faktoren für die Ströme einzelner Phasen. Je nach Modell unterscheiden sich die Werte um den Faktor 10.
Eine Unterscheidung nach Firmware oder Modell ist aktuell nicht möglich. Workaround ist die Berechnung der Phasenströme aus der übermittelten Leistung einzelner Phasen.