YamBMS: Auto CCL smooths max cell voltage, minimum 1 A (#329)

Near the top of charge the Auto CCL curve is steep (about 3.5 A per mV
at 3.46 V/cell). The max cell voltage arrives only every 10-15 s in
1 mV steps and moves a few mV with the charge current. Each new reading
moved the target by 10-20 A. Cuts are applied at once and increases
ramp up, so the requested CCL swung between about 8 A and 45 A every
20-40 s.

- Smooth the max cell voltage used for the curve with a time-based
  moving average (auto_ccl_max_cell_v_tau, default 30 s, '0' disables).
- Safety guard: a raw reading more than auto_ccl_max_cell_v_guard
  (default 5 mV) above the average is used instead (minus the guard),
  so real voltage rises still cut the current at once.
- Add auto_ccl_min_current (default 1 A): Auto CCL never requests less,
  also above the end of its curve or with an invalid float/OVP setting.
  Other limits can still request 0 A.
This commit is contained in:
Sebastian authored and Sleeper85 committed 2026-11-08 23:08:33 +01:00
1 parent 4a23cb6b47
commit 14dd332412
1 file changed
+30 -2
+30 -2
View File
@@ -1,5 +1,5 @@
# Updated : 2026.06.27
# Version : 1.3.3
# Updated : 2026.10.04
# Version : 1.3.4
# GitHub : https://github.com/Sleeper85/esphome-yambms
# YamBMS ( Yet another multi-BMS Merging Solution )
@@ -37,6 +37,17 @@ substitutions:
# A setting above 1 will reduce current at a slow rate after the float voltage is reached, then increase as a cell approaches the BMS "cell_voltage_overvoltage_protection" value.
# A factor below 1 will reduce current at a fast rate after the float voltage is reached, then slow as a cell approaches the BMS "cell_voltage_overvoltage_protection" value.
charge_a_factor_curve_shape: '1.8'
# Max cell voltage smoothing. Near the top of charge the curve is steep (several A per mV),
# so 1-3 mV of jitter in the BMS readings makes the CCL saw up and down.
# Time constant (s) of the moving average used for the curve. '0' disables the smoothing.
auto_ccl_max_cell_v_tau: '30'
# Safety guard: when a raw reading is more than this (V) above the average,
# the raw reading minus this margin is used, so real voltage rises still cut at once.
auto_ccl_max_cell_v_guard: '0.005'
# Lowest charge current (A) Auto CCL may request, also at or above the end of its curve.
# Keeps the charger from seeing a 0 A request from this function. '0' allows 0 A.
# Other limits (Auto EOC, Current Taper, charging not allowed, ...) can still request less.
auto_ccl_min_current: '1'
switch:
- platform: template
@@ -84,6 +95,20 @@ interval:
return;
}
// Smooth the max cell voltage (time-based EMA), keep raw rises above the guard
static float max_cell_v_avg = NAN;
static uint32_t last_run_ms = 0;
const uint32_t now = millis();
const float tau = ${auto_ccl_max_cell_v_tau};
if (isnan(max_cell_v_avg) || tau <= 0.0f) {
max_cell_v_avg = max_cell_v;
} else {
const float dt = (now - last_run_ms) / 1000.0f;
max_cell_v_avg += (max_cell_v - max_cell_v_avg) * std::min(1.0f, dt / tau);
}
last_run_ms = now;
max_cell_v = std::max(max_cell_v_avg, max_cell_v - (float) ${auto_ccl_max_cell_v_guard});
float cell_bulk_v = (bulk_v / cell_count);
float cell_float_v = (float_v / cell_count);
float cell_high_v = ((cell_ovp_v + cell_bulk_v) / 2.0f);
@@ -108,6 +133,9 @@ interval:
delta = max(0.0f, (-curve + 2.0f) * max_current) - max_current;
}
}
// Never reduce below the minimum current (and never raise above max_current)
const float min_current = ${auto_ccl_min_current};
delta = std::min(0.0f, std::max(delta, min_current - max_current));
}
// If switch is off, delta stays 0.0f.
// Smoothly ramp from the old negative value back to 0 if required