Files
esphome-yambms/packages/bms/bms_demo_charge_simulation.yaml
Sleeper85 9dd22fa56b Inferred equalizing for BMS that do not report a balancing flag
Some BMS balance their cells but never expose a balancing flag, so
`bms_equalizing` stays false and the core cannot tell a pack that is still
balancing from one that has finished. This is not cosmetic : while
equalizing is true, yambms_core.yaml stops the Cut-Off timer and lets the
charge run to the EOC timer instead of terminating early.

bms_options_fake_equalizing.yaml infers that flag from the pack itself. No
absolute cell voltage is hardcoded : the anchor is bulk_voltage / cell
count, the same derivation as cell_bulk_v in yambms_core.yaml, so it
follows `yambms_battery_chemistry`, the cell count and the configured bulk
voltage automatically.

  START when BOTH are true
    max cell >= cell_bulk_v                     the pack is at the setpoint
    AND (max - min) >= trigger voltage          its own balancing threshold

  STOP when EITHER is true
    max cell <  cell_bulk_v - hysteresis        the pack dropped off the setpoint
    OR (max - min) <  trigger - delta hyst.     the spread closed back below it

Only two deltas and one offset are configurable, and none of the three
depends on the chemistry - LFP, Li-ion and LTO all want the same few tens
of mV. The absolute anchor they hang off comes from the core, for free.

The delta condition is what keeps this honest : a pack that reaches the
setpoint perfectly balanced has nothing to equalize, so it reports false
and the Cut-Off timer does its job. A plain voltage comparison would report
balancing forever and terminate every charge on the EOC timer.

It extends bms<id>_bms_equalizing, the raw BMS flag, and not the combined
bms<id>_equalizing sensor. bms_base_balancer.yaml is therefore neither
modified nor duplicated, and keeps giving an external balancer priority
whenever one is online : the inference only applies when no balancer
reports for this pack.

This commit only adds the package. Nothing includes it yet, so no existing
configuration changes behaviour. Candidates sharing the same case are
Seplos V3, Seplos V1/V2, EG4 LL V2 and JK RS485 DISPLAY, whose
bms_equalizing is a hardcoded `return false;`.
2026-11-08 23:08:33 +01:00

149 lines
6.9 KiB
YAML

# Updated : 2026.08.29
# Version : 1.1.4
# GitHub : https://github.com/Sleeper85/esphome-yambms
# YamBMS ( Yet another multi-BMS Merging Solution )
# This YAML is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
# +--------------------------------------------------------------------------------+
# | Import this package into your main YAML to activate the simulation
# +--------------------------------------------------------------------------------+
#
# - path: packages/bms/bms_demo_charge_simulation.yaml # Battery charge from 95 to 100%
# vars:
# bms_id: '1'
# - path: packages/bms/bms_demo_charge_simulation.yaml # Battery charge from 95 to 100%
# vars:
# bms_id: '2'
# - path: packages/bms/bms_demo_charge_simulation.yaml # Battery charge from 95 to 100%
# vars:
# bms_id: '3'
#
# +--------------------------------------------------------------------------------+
substitutions:
battery_capacity: '280'
min_temperature: '4.8'
max_temperature: '5.0'
delta_cell_voltage: '0.005'
# Spread held during the two balancing steps. Must stay above this BMS's
# `bms_balance_trigger_voltage` for the inferred equalizing flag to assert.
delta_cell_voltage_balancing: '0.020'
switch:
# DEMO switch
- platform: template
id: bms${bms_id}_switch_demo_charge_simulation
device_id: bms_${bms_id}
name: "DEMO charge simulation"
restore_mode: RESTORE_DEFAULT_ON
optimistic: true
on_state:
- lambda: |-
if (id(bms${bms_id}_switch_demo_charge_simulation).state)
id(bms${bms_id}_online_status_switch).turn_on();
interval:
- interval: ${yambms_update_interval}
then:
- lambda: |-
// Vars
float cell_count = id(yambms${yambms_id}_cell_count).state;
float requested_cvl = id(yambms${yambms_id}_requested_charge_voltage).state;
const int step_sec = 10; // step duration in seconds
static int seconds = 0;
// Simulation reset
if (id(bms${bms_id}_switch_demo_charge_simulation).state == false ||
id(bms${bms_id}_online_status).state == false)
seconds = 0; // New Cycle
// Exit condition
if (id(yambms${yambms_id}_var_initialized) == false) return;
if (id(bms${bms_id}_online_status).state == false) return;
if (id(bms${bms_id}_switch_demo_charge_simulation).state == false) return;
// YamBMS Setup
id(yambms${yambms_id}_bulk_voltage).publish_state(3.45 * cell_count);
id(yambms${yambms_id}_float_voltage).publish_state(3.35 * cell_count);
// BMS Setup
id(bms${bms_id}_battery_capacity).publish_state(${battery_capacity});
id(bms${bms_id}_min_temperature).publish_state(${min_temperature});
id(bms${bms_id}_max_temperature).publish_state(${max_temperature});
// +---------------------------------------------------------------
// | Start of the simulation
// +---------------------------------------------------------------
seconds++;
// Cycle reset after 5min
if (seconds > 60 * 5) {
seconds = 1;
}
if (seconds <= 1 * step_sec) {
// Step 1 : 95% (10sec)
id(yambms${yambms_id}_var_charge_status) = "Bulk";
id(bms${bms_id}_state_of_charge).publish_state(95);
id(bms${bms_id}_current).publish_state(20);
id(bms${bms_id}_min_cell_voltage).publish_state(requested_cvl / cell_count - 0.1 - ${delta_cell_voltage});
id(bms${bms_id}_max_cell_voltage).publish_state(requested_cvl / cell_count - 0.1);
}
else if (seconds <= 2 * step_sec) {
// Step 2 : 96% (10sec)
id(bms${bms_id}_state_of_charge).publish_state(96);
id(bms${bms_id}_current).publish_state(15);
id(bms${bms_id}_min_cell_voltage).publish_state(requested_cvl / cell_count - 0.05 - ${delta_cell_voltage});
id(bms${bms_id}_max_cell_voltage).publish_state(requested_cvl / cell_count - 0.05);
}
else if (seconds <= 3 * step_sec) {
// Step 3 : 97% (10sec)
id(bms${bms_id}_state_of_charge).publish_state(97);
id(bms${bms_id}_current).publish_state(10);
id(bms${bms_id}_min_cell_voltage).publish_state(requested_cvl / cell_count - ${delta_cell_voltage});
id(bms${bms_id}_max_cell_voltage).publish_state(requested_cvl / cell_count);
}
else if (seconds <= 4 * step_sec) {
// Step 4 : 98% (10sec)
id(bms${bms_id}_state_of_charge).publish_state(98);
id(bms${bms_id}_current).publish_state(5);
id(bms${bms_id}_min_cell_voltage).publish_state(requested_cvl / cell_count + 0.01 - ${delta_cell_voltage_balancing});
id(bms${bms_id}_max_cell_voltage).publish_state(requested_cvl / cell_count + 0.01); // equalizing
}
else if (seconds <= 5 * step_sec) { // Entering Cut-off phase...
// Step 5 : 99% (10sec)
id(bms${bms_id}_state_of_charge).publish_state(99);
id(bms${bms_id}_current).publish_state(3.5);
id(bms${bms_id}_min_cell_voltage).publish_state(requested_cvl / cell_count + 0.005 - ${delta_cell_voltage_balancing});
id(bms${bms_id}_max_cell_voltage).publish_state(requested_cvl / cell_count + 0.005); // equalizing
}
else if (seconds <= 15 * step_sec) { // End of Cut-off phase...
// Step 6 : 100% (1min 10sec)
id(bms${bms_id}_state_of_charge).publish_state(100);
id(bms${bms_id}_current).publish_state(2.5);
id(bms${bms_id}_min_cell_voltage).publish_state(requested_cvl / cell_count - ${delta_cell_voltage});
id(bms${bms_id}_max_cell_voltage).publish_state(requested_cvl / cell_count);
}
else if (id(yambms${yambms_id}_var_charge_status) == "Float") {
// Step 7 : Float
id(bms${bms_id}_state_of_charge).publish_state(100);
id(bms${bms_id}_current).publish_state(0);
id(bms${bms_id}_min_cell_voltage).publish_state(requested_cvl / cell_count - ${delta_cell_voltage});
id(bms${bms_id}_max_cell_voltage).publish_state(requested_cvl / cell_count);
}
else seconds = 0; // New Cycle