@uksa007
absorption_v: "55.2"
rebulk_offset: "3.0"
I did the tests below with a battery at +/- 53.1V
I set the offset to 3V to match the condition of the box marked "A".
Under these conditions when booting the ESP32 the charging status should be on Bulk but we remain stuck on Wait.
Why ?
First, during boot, JK-BMS information is not immediately available.
Even if the BMS allows charging, the condition
!id(charging_switch).state) is true and the code framed with the number 1 is executed.
The 'charge_status' variable is changed to 'Disabled'.
Then the code framed with the number 2 is executed and 'charge_status' is changed to 'Wait'.
Then we will remain stuck in this 'Wait' state until the battery voltage is below 55.2 - 2.5 (offset) = 52.7V (3.29V / cell which can last a long time).
A battery charging with 30A or more can be well above 52.7V with an SoC less than 50%.
V1.13.3 original script
Modified script
To correct this problem I tried not to modify the original script too much.
1) I changed the
initial value of 'charge_status' to
'Init' for the procedure added in point 2.
2) I added the code framed in pink (1), it just allows you to wait a little in order to receive the information coming from the JK-BMS sensors which are not available directly just after boot.
3) Modified the value of the variable in box (2)
In the original script, in HA if we force the charge with the 'Charging manually (top bal)' switch then deactivate it we stay on 'Wait', for me it's OK if the goal is to wait and not to resume normal operation immediately.
But then it was impossible to return to normal 'bulk' mode.
To correct this problem I modified the 'Wait' value in box (2) to 'Startup' which allows normal charging to be activated via an OFF/ON of the 'Charging enabled' switch.
Below you can see two videos of the behavior before and after.
A reset of the ESP32 is done before the start of each video.
1) First video with the original code, we get stuck on Wait
drive.google.com
2) Second video with the modified code, it works ;-)
drive.google.com
That said, I think this part of the code could probably be improved further.
Here is the new code.
C++:
uint8_t can_mesg[7];
if (id(charge_status) == "Init") {
id(charge_status) = "Startup";
ESP_LOGI("main", "Wait for JK-BMS data...");
} else if ((!id(charging_switch).state) | (!id(inverter_charging).state)) {
id(charge_status) = "Disabled";
} else if (id(inverter_chg_on).state) {
id(charge_status) = "Bulk Manually";
} else if ((id(charging_switch).state) & (id(inverter_charging).state) & (id(charge_status) == "Disabled")) {
id(charge_status) = "Startup";
} else if ((!id(inverter_chg_on).state) & (id(charge_status) == "Bulk Manually")) {
id(charge_status) = "Wait";
} else if (id(total_voltage).state <= (id(charging_voltage).state - ${rebulk_offset})) { // Bulk Charge eg 53.6v 10%
if (id(absorption_script).is_running()) id(absorption_script).stop();
id(charge_status) = "Bulk";
} else if ((id(total_voltage).state > (id(charging_voltage).state - ${rebulk_offset})) & (id(total_voltage).state < (id(charging_voltage).state - 0.05))) { // If in startup rebulk
if (id(charge_status) == "Startup") {
id(charge_status) = "Bulk"; // If in startup, 10% low rebulk
}
} else if (id(total_voltage).state >= (id(charging_voltage).state - 0.05)) { // 10 % from top start absorption timer
if (id(charge_status) == "Bulk") {
id(charge_status) = "Absorption";
if (!id(absorption_script).is_running()) id(absorption_script).execute();
}
} else {
id(charge_status) = "Wait";
}