Skip to content

Commit

Permalink
Merge pull request #3 from bbr111/dev
Browse files Browse the repository at this point in the history
reorder example, add tower state_string
  • Loading branch information
bbr111 authored Nov 17, 2024
2 parents 9ec603f + f6c5d2a commit c0b4244
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 48 deletions.
37 changes: 37 additions & 0 deletions bydhvs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ def __init__(self, ip_address: str, port: int = 8080) -> None:
'switch_pass': bytes.fromhex("01100100000306444542554700176f"),
# Request 16
'switch_to_box_2': bytes.fromhex("01100550000204000281000853"),
'switch_to_box_3': bytes.fromhex("01100550000204000381005993"),
# BMU
'EVT_MSG_0_0': bytes.fromhex("011005a000020400008100A6D7"),
# BMS tower 1
'EVT_MSG_0_1': bytes.fromhex("011005a000020400018100f717"),
# BMS tower 2
'EVT_MSG_0_2': bytes.fromhex("011005a0000204000281000717"),
# BMS tower 3
'EVT_MSG_0_3': bytes.fromhex("011005a00002040003810056D7"),
}

self.my_errors = [
Expand All @@ -153,6 +162,25 @@ def __init__(self, ip_address: str, port: int = 8080) -> None:
"Low temperature during discharging (cells)",
]

self.stat_tower = [
"Battery Over Voltage", # Bit 0
"Battery Under Voltage", # Bit 1
"Cells OverVoltage", # Bit 2
"Cells UnderVoltage", # Bit 3
"Cells Imbalance", # Bit 4
"Charging High Temperature(Cells)", # Bit 5
"Charging Low Temperature(Cells)", # Bit 6
"DisCharging High Temperature(Cells)", # Bit 7
"DisCharging Low Temperature(Cells)", # Bit 8
"Charging OverCurrent(Cells)", # Bit 9
"DisCharging OverCurrent(Cells)", # Bit 10
"Charging OverCurrent(Hardware)", # Bit 11
"Short Circuit", # Bit 12
"Inversly Connection", # Bit 13
"Interlock switch Abnormal", # Bit 14
"AirSwitch Abnormal" # Bit 15
]

self.my_inverters = [
"Fronius HV", # 0
"Goodwe HV", # 1
Expand Down Expand Up @@ -404,6 +432,15 @@ def parse_packet5(self, data: bytes, tower_number=0) -> None:
)
tower['soh'] = round(self.buf2int16_si(data, 55), 1)
tower['state'] = f"{data[59]}{data[60]}"
# tower['state_string'] = self.stat_tower[tower['state']]

tower['state_string'] = "; ".join(
[
err
for i, err in enumerate(self.stat_tower)
if int(tower['state']) & (1 << i)
]
) or "No Error"

# Cell voltages (Bytes 101 to 132) for cells 1 to 16
tower['cell_voltages'] = [
Expand Down
98 changes: 50 additions & 48 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,62 +18,64 @@ async def main():

# Print the retrieved data
print("Battery Data:")
print(f"Serial Number: {data['serial_number']}")
print(f"BMU Firmware: {data['bmu_firmware']}")
print(f"BMU Firmware_A: {data['bmu_firmware_a']}")
print(f"BMU Firmware_B: {data['bmu_firmware_b']}")
print(f"BMS Firmware: {data['bms_firmware']}")
print(f"Modules: {data['modules']}")
print(f"ModuleCellCount: {data['module_cell_count']}")
print(f"Serial Number : {data['serial_number']}")
print(f"BMU Firmware : {data['bmu_firmware']}")
print(f"BMU Firmware_A : {data['bmu_firmware_a']}")
print(f"BMU Firmware_B : {data['bmu_firmware_b']}")
print(f"BMS Firmware : {data['bms_firmware']}")
print(f"Modules : {data['modules']}")
print(f"ModuleCellCount : {data['module_cell_count']}")
print(f"ModuleCellTempCount: {data['module_cell_temp_count']}")
print(f"Towers: {data['towers']}")
print(f"Grid Type: {data['grid_type']}")
print(f"SOC: {data['soc']}%")
print(f"Max Voltage: {data['max_voltage']} V")
print(f"Min Voltage: {data['min_voltage']} V")
print(f"SOH: {data['soh']}%")
print(f"Current: {data['current']} A")
print(f"Battery Voltage: {data['battery_voltage']} V")
print(f"Max Temperature: {data['max_temperature']} °C")
print(f"Min Temperature: {data['min_temperature']} °C")
print(f"Towers : {data['towers']}")
print(f"Grid Type : {data['grid_type']}")
print(f"SOC : {data['soc']}%")
print(f"Max Voltage : {data['max_voltage']} V")
print(f"Min Voltage : {data['min_voltage']} V")
print(f"SOH : {data['soh']}%")
print(f"Current : {data['current']} A")
print(f"Battery Voltage : {data['battery_voltage']} V")
print(f"Max Temperature : {data['max_temperature']} °C")
print(f"Min Temperature : {data['min_temperature']} °C")
print(f"Battery Temperature: {data['battery_temperature']} °C")
print(f"Voltage Difference: {data['voltage_difference']} V")
print(f"Power: {data['power']} W")
print(f"Error Number: {data['error_number']}")
print(f"Error String: {data['error_string']}")
print(f"Charge Total: {data['charge_total']} Ah")
print(f"Discharge Total: {data['discharge_total']} Ah")
print(f"ETA: {data['eta']}")
print(f"Battery Type: {data['battery_type']}")
print(f"Inverter Type: {data['inverter_type']}")
print(f"Voltage Difference : {data['voltage_difference']} V")
print(f"Power : {data['power']} W")
print(f"Error Number : {data['error_number']}")
print(f"Error String : {data['error_string']}")
print(f"Charge Total : {data['charge_total']} Ah")
print(f"Discharge Total : {data['discharge_total']} Ah")
print(f"ETA : {data['eta']}")
print(f"Battery Type : {data['battery_type']}")
print(f"Inverter Type : {data['inverter_type']}")
for idx, tower in enumerate(data['tower_attributes']):
print(f"\nTower {idx + 1}:")
print(f""" Max Cell Voltage (mV): {
tower.get('max_cell_voltage_mv')}""")
tower.get('max_cell_voltage_mv')}""")
print(f""" Min Cell Voltage (mV): {
tower.get('min_cell_voltage_mv')}""")
tower.get('min_cell_voltage_mv')}""")
print(f""" Max Cell Voltage Cell: No. {
tower.get('max_cell_voltage_cell')}""")
tower.get('max_cell_voltage_cell')}""")
print(f""" Min Cell Voltage Cell: No. {
tower.get('min_cell_voltage_cell')}""")
print(f" Max Cell Temp: {tower.get('max_cell_temp')}°C")
print(f" Min Cell Temp: {tower.get('min_cell_temp')}°C")
print(f""" Max Cell Temp Cell: No. {
tower.get('max_cell_temp_cell')}""")
print(f""" Min Cell Temp Cell: No. {
tower.get('min_cell_temp_cell')}""")
print(f" Balancing Status: {tower.get('balancing_status')}")
print(f" Balancing Count: {tower.get('balancing_count')}")
print(f" Total Charge: {tower['charge_total']}")
print(f" Discharge Total: {tower.get('discharge_total')}")
print(f" ETA: {tower.get('eta')}")
print(f" Battery Volt: {tower.get('battery_volt')}")
print(f" Output Volt: {tower.get('out_volt')}")
print(f" SOCDiagnosis: {tower.get('hvs_soc_diagnosis')}%")
print(f" State of Health: {tower.get('soh')}%")
print(f" State: {tower.get('state')}")
print(f" Cell Voltages: {tower.get('cell_voltages')}")
print(f" Cell Temperatures: {tower.get('cell_temperatures')}")
tower.get('min_cell_voltage_cell')}""")
print(f" Max Cell Temp : {tower.get('max_cell_temp')}°C")
print(f" Min Cell Temp : {tower.get('min_cell_temp')}°C")
print(f""" Max Cell Temp Cell : No.{
tower.get('max_cell_temp_cell')}""")
print(f""" Min Cell Temp Cell : No.{
tower.get('min_cell_temp_cell')}""")
print(f" Balancing Status : {tower.get('balancing_status')}")
print(f" Balancing Count : {tower.get('balancing_count')}")
print(f" Total Charge : {tower['charge_total']}")
print(f" Discharge Total : {tower.get('discharge_total')}")
print(f" ETA : {tower.get('eta')}")
print(f" Battery Volt : {tower.get('battery_volt')}")
print(f" Output Volt : {tower.get('out_volt')}")
print(f""" SOCDiagnosis : {
tower.get('hvs_soc_diagnosis')}%""")
print(f" State of Health : {tower.get('soh')}%")
print(f" State : {tower.get('state')}")
print(f" State_String : {tower.get('state_string')}")
print(f" Cell Voltages : {tower.get('cell_voltages')}")
print(f" Cell Temperatures : {tower.get('cell_temperatures')}")

except BYDHVSError as e:
print(f"An error occurred: {e}")
Expand Down

0 comments on commit c0b4244

Please sign in to comment.