Skip to content
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

Decode status flags #21

Merged
merged 4 commits into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 61 additions & 8 deletions esp32-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,37 @@ modbus_controller:

binary_sensor:
# 11 Status/Fault flag 2 byte R uint16 Hex See ^3
# Bit 8: Status: Charging enabled/disabled
# Bit 8: Status: Charging operation
- platform: modbus_controller
modbus_controller_id: bms0
name: "${name} charging operation"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you describe the meaning of this binary sensor in a few words? I would like to try to improve the naming of these 4 status sensors to be more explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm doing some experiments with the PACE BMS to elucidate the behavior, it's new to me.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright! Let me know as soon you know the differences between the flags.

Copy link
Contributor Author

@ThHanika ThHanika Dec 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, now it's clear:
The Mosfet CHG and DCHG flags turn the MOSFETs on or off depending on the state of the battery protection and allow the battery to be charged or discharged.

The other flags are operating flags and signal the actual operating status of charging or discharging. A corresponding current must also flow for this. The battery charging process flag also enables balancing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK some additional experience with PACE BMS:
If over voltage protection is reached, the SOC is set to 100% and the remaining capacity is set to design capacity.
After arrive of overvoltage protection release voltage, the specified protection flag is cleared, but not Bit16!
As long as the protection-flag bitset is not equal 0, the balancing works also (Bit16 is on).
Bit16 is cleared, if the Mosfet-switch get state enabled.

address: 11
register_type: holding
bitmask: 0x0100

# Bit 9: Status: Discharging operation
- platform: modbus_controller
modbus_controller_id: bms0
name: "${name} discharging operation"
address: 11
register_type: holding
bitmask: 0x0200

# Bit 10: Status: Charging enabled/disabled
- platform: modbus_controller
modbus_controller_id: bms0
name: "${name} charging"
address: 11
register_type: holding
bitmask: 0x0080
bitmask: 0x0400

# Bit 9: Status: Discharging enabled/disabled
# Bit 11: Status: Discharging enabled/disabled
- platform: modbus_controller
modbus_controller_id: bms0
name: "${name} discharging"
address: 11
register_type: holding
bitmask: 0x0100
bitmask: 0x0800

sensor:
# 0 Current 2 byte R int16 10mA (Positive: chargingm Negative: discharging)
Expand Down Expand Up @@ -224,15 +240,15 @@ sensor:
# 11 Status/Fault flag 2 byte R uint16 Hex See ^3
- platform: modbus_controller
modbus_controller_id: bms0
name: "${name} errors bitmask"
name: "${name} fault status bitmask"
address: 11
register_type: holding
value_type: U_WORD
unit_of_measurement: ""
state_class: measurement
accuracy_decimals: 0

# 12 Balance status 2 byte R uint16 Hex
# 12 Balance status-bits per cell (1-16) 2 byte R uint16 Hex
- platform: modbus_controller
modbus_controller_id: bms0
name: "${name} balancer status"
Expand Down Expand Up @@ -1555,10 +1571,10 @@ text_sensor:
}
return values;

# 11 Status/Fault flag 2 byte R uint16 Hex See ^3
# 11 Fault flag 2 byte R uint16 Hex See ^3
- platform: modbus_controller
modbus_controller_id: bms0
name: "${name} errors"
name: "${name} faults"
address: 11
register_type: holding
register_count: 1
Expand Down Expand Up @@ -1592,6 +1608,43 @@ text_sensor:
}
return values;

# 11 Status flag 2 byte R uint16 Hex See ^3
- platform: modbus_controller
modbus_controller_id: bms0
name: "${name} status"
address: 11
register_type: holding
register_count: 1
response_size: 2
raw_encode: HEXBYTES
lambda: |-
static const uint8_t STATUS_SIZE = 8;
static const char *const STATUS[STATUS_SIZE] = {
"CHG",
"DCHG",
"MOSFET_CHG",
"MOSFET_DCHG",
"LIMIT_CHG",
"Reserve (Bit 13)",
"Charger inversed",
"HEAT",
};
std::string values = "";

uint16_t mask = modbus_controller::word_from_hex_str(x, 0);
if (mask) {
for (int i = 8; i < (STATUS_SIZE+8); i++) {
if (mask & (1 << i)) {
values.append(STATUS[i-8]);
values.append(";");
}
}
if (!values.empty()) {
values.pop_back();
}
}
return values;

# 150 Version information 20 byte R uint16 ASCII
- platform: modbus_controller
modbus_controller_id: bms0
Expand Down
Loading