-
Notifications
You must be signed in to change notification settings - Fork 115
AlphaEss: calculate currents from powers #3173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5004d40
dc33f46
82f3e95
ba043c2
b5aad98
6222dc0
0ed49d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -40,36 +40,52 @@ def update(self): | |||||
| 0x6, [modbus.ModbusDataType.INT_32] * 3, unit=self.__modbus_id) | ||||||
| exported *= 10 | ||||||
| imported *= 10 | ||||||
| imported, exported = self.peak_filter.check_values(power, imported, exported) | ||||||
| currents = [val / 230 for val in self.__tcp_client.read_holding_registers( | ||||||
| 0x0000, [ModbusDataType.INT_32]*3, unit=self.__modbus_id)] | ||||||
| counter_state = CounterState( | ||||||
| currents=currents, | ||||||
| imported=imported, | ||||||
| exported=exported, | ||||||
| power=power | ||||||
| ) | ||||||
| else: | ||||||
| power = self.__tcp_client.read_holding_registers(0x0021, ModbusDataType.INT_32, unit=self.__modbus_id) | ||||||
| exported, imported = [ | ||||||
| val * 10 for val in self.__tcp_client.read_holding_registers( | ||||||
| 0x0010, [ModbusDataType.INT_32] * 2, unit=self.__modbus_id | ||||||
| )] | ||||||
| currents = [val / 10 for val in self.__tcp_client.read_holding_registers( | ||||||
| 0x0017, [ModbusDataType.INT_16]*3, unit=self.__modbus_id)] | ||||||
| powers = self.__tcp_client.read_holding_registers( | ||||||
| 0x001b, [ModbusDataType.INT_32]*3, unit=self.__modbus_id) | ||||||
| voltages = self.__tcp_client.read_holding_registers( | ||||||
| 0x0014, [ModbusDataType.UINT_16]*3, unit=self.__modbus_id) | ||||||
| imported, exported = self.peak_filter.check_values(power, imported, exported) | ||||||
| frequency = self.__tcp_client.read_holding_registers( | ||||||
|
benderl marked this conversation as resolved.
|
||||||
| 0x001A, ModbusDataType.UINT_16, unit=self.__modbus_id) / 100 | ||||||
| imported, exported = self.peak_filter.check_values(power, imported, exported) | ||||||
| counter_state = CounterState( | ||||||
| currents=currents, | ||||||
| imported=imported, | ||||||
| exported=exported, | ||||||
| power=power | ||||||
| ) | ||||||
| if 'powers' in locals(): | ||||||
| counter_state.powers = powers | ||||||
| if 'voltages' in locals(): | ||||||
| counter_state.voltages = voltages | ||||||
| if 'frequency' in locals(): | ||||||
| counter_state.frequency = frequency | ||||||
| currents = self.__tcp_client.read_holding_registers( | ||||||
| 0x0017, [ModbusDataType.INT_16]*3, unit=self.__modbus_id) | ||||||
| powers = self.__tcp_client.read_holding_registers( | ||||||
| 0x001b, [ModbusDataType.INT_32]*3, unit=self.__modbus_id) | ||||||
| currents = scale_currents(currents, powers) | ||||||
| counter_state = CounterState( | ||||||
|
benderl marked this conversation as resolved.
|
||||||
| currents=currents, | ||||||
| imported=imported, | ||||||
| exported=exported, | ||||||
| power=power, | ||||||
| powers=powers, | ||||||
| frequency=frequency | ||||||
| ) | ||||||
| self.store.set(counter_state) | ||||||
|
|
||||||
|
|
||||||
| def scale_currents(currents, powers): | ||||||
| factors = [-1000, -100, -10, 10, 100, 1000] | ||||||
| scaled_currents = [] | ||||||
| for c, p in zip(currents, powers): | ||||||
| if p == 0: | ||||||
| scaled_currents.append(0) | ||||||
| else: | ||||||
| factor = c * 230 / p | ||||||
| rounded_factor = min(factors, key=lambda z: abs(factor - z)) | ||||||
|
||||||
| rounded_factor = min(factors, key=lambda z: abs(factor - z)) | |
| rounded_factor = min(factors, key=lambda z: (abs(factor - z), -abs(z))) |
Uh oh!
There was an error while loading. Please reload this page.