- update and telemetry are now gated independently by substitution; var_service and its Update service switch are removed - the uptime text sensor is published by its source instead of polling it, which fixes the 24855d readings that reached the telemetry, and the raw seconds are now sent instead of the formatted string - the MAC address is replaced by a salted SHA-256, derived identically server side so no pairing window is needed
2519 lines
103 KiB
YAML
2519 lines
103 KiB
YAML
# Updated : 2026.08.31
|
||
# Version : 1.8.0
|
||
# 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>.
|
||
|
||
substitutions:
|
||
yambms_version: "1.8.0"
|
||
# YamBMS services
|
||
yambms_update_service: 'true' # Set to false to disable update checks
|
||
yambms_telemetry_service: 'true' # Set to false to disable the sending of telemetry data
|
||
# Cut-Off Charging Logic
|
||
yambms_cutoff_crate: '0.05' # (C-Rate) matches the standard charge termination of most LFP, Li-ion and LTO datasheets and is the right value for the vast majority of installations. Check your cell datasheet before changing it.
|
||
yambms_eoc_min_soc: '95' # (%) minimum SoC (Max 98%) required to allow Cut-Off/EOC
|
||
yambms_current_deadband_crate: '0.005' # (C-Rate) `current` below this = grey zone (sensor noise / PV starvation)
|
||
yambms_cell_hysteresis_v: '0.020' # (V/cell) discharge hysteresis margin
|
||
# Custom CCL/DCL Derating Reason
|
||
yambms_custom_ccl_derating_reason: 'Custom CCL Derating'
|
||
yambms_custom_dcl_derating_reason: 'Custom DCL Derating'
|
||
|
||
globals:
|
||
# BMS
|
||
- id: yambms${yambms_id}_var_bms_models
|
||
type: std::string
|
||
restore_value: no
|
||
initial_value: '""'
|
||
- id: yambms${yambms_id}_var_bms_protocols
|
||
type: std::string
|
||
restore_value: no
|
||
initial_value: '""'
|
||
- id: yambms${yambms_id}_var_bms_counter
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_to_combine_bms_number
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '1'
|
||
- id: yambms${yambms_id}_var_to_combine_bms_counter
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_bms_online_bitmask
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_bms_seen_online_bitmask
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_errors_bitmask_counter
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_errors_bitmask
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_equalizing_counter
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_charging_allowed_counter
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_discharging_allowed_counter
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_bms_blocking_charge_counter
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_bms_blocking_discharge_counter
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_min_voltage_cell
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_max_voltage_cell
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_min_cell_voltage
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '5.0'
|
||
- id: yambms${yambms_id}_var_max_cell_voltage
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_total_max_charge_current
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_total_max_discharge_current
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_total_installed_battery_capacity
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_total_battery_capacity
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_total_battery_capacity_remaining
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_total_charging_cycles
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_min_cell_ovp
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '5.0'
|
||
- id: yambms${yambms_id}_var_max_cell_uvp
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_max_balance_trigger_voltage
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_min_temperature
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '100.0'
|
||
- id: yambms${yambms_id}_var_min_temperature_sensor
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_max_temperature
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '-100.0'
|
||
- id: yambms${yambms_id}_var_max_temperature_sensor
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_bms_total_voltage
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_bms_total_current
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_bms_total_power
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_bms_total_soc
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_bms_total_soh
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
# Shunt
|
||
- id: yambms${yambms_id}_var_shunt_use
|
||
type: bool
|
||
restore_value: no
|
||
initial_value: "false"
|
||
- id: yambms${yambms_id}_var_shunt_counter
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_to_combine_shunt_number
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '1'
|
||
- id: yambms${yambms_id}_var_to_combine_shunt_counter
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_shunt_total_voltage
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_shunt_total_current
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_shunt_total_power
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_shunt_total_soc
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
# YamBMS
|
||
- id: yambms${yambms_id}_var_initialized
|
||
type: bool
|
||
restore_value: no
|
||
initial_value: 'false'
|
||
- id: yambms${yambms_id}_var_service_failures
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_service_round_failed
|
||
type: bool
|
||
restore_value: no
|
||
initial_value: 'false'
|
||
- id: yambms${yambms_id}_var_requested_ccl_init
|
||
type: bool
|
||
restore_value: no
|
||
initial_value: 'false'
|
||
- id: yambms${yambms_id}_var_requested_dcl_init
|
||
type: bool
|
||
restore_value: no
|
||
initial_value: 'false'
|
||
- id: yambms${yambms_id}_var_bms_charging_logic
|
||
type: bool
|
||
restore_value: no
|
||
initial_value: 'false'
|
||
- id: yambms${yambms_id}_var_force_float
|
||
type: bool
|
||
restore_value: no
|
||
initial_value: 'false'
|
||
- id: yambms${yambms_id}_var_charge_status
|
||
type: std::string
|
||
restore_value: no
|
||
initial_value: '"Init"'
|
||
- id: yambms${yambms_id}_var_communication_bus
|
||
type: std::string
|
||
restore_value: no
|
||
- id: yambms${yambms_id}_var_communication_protocol
|
||
type: std::string
|
||
restore_value: no
|
||
- id: yambms${yambms_id}_var_cell_nominal_v
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_cell_min_charge_v
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_cell_max_charge_v
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_cell_max_discharge_v
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_charge_current_step
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_discharge_current_step
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_auto_ccl_functions_count
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_auto_dcl_functions_count
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_comm_interfaces_count
|
||
type: int
|
||
restore_value: no
|
||
initial_value: '0'
|
||
- id: yambms${yambms_id}_var_auto_cvl
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_auto_ccl
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_auto_ccl_current_taper
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_auto_dcl
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_auto_temperature_ccl
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_auto_temperature_dcl
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_auto_eoc
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_auto_float
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_auto_soc_limit
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_auto_custom_cvl
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_auto_custom_ccl
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_auto_custom_dcl
|
||
type: float
|
||
restore_value: no
|
||
initial_value: '0.0'
|
||
- id: yambms${yambms_id}_var_eoc
|
||
type: bool
|
||
restore_value: no
|
||
initial_value: 'false'
|
||
|
||
- id: yambms${yambms_id}_var_eoc_timestamp
|
||
type: time_t
|
||
restore_value: true
|
||
initial_value: ''
|
||
- id: yambms${yambms_id}_var_rebulk_days_active
|
||
type: bool
|
||
restore_value: no
|
||
initial_value: 'false'
|
||
|
||
esphome:
|
||
# The 'devices' block will merge into the main config's 'esphome' block.
|
||
# The ID and Name are uniquely defined by the vars passed in the main config.
|
||
devices:
|
||
- id: yambms_yambms${yambms_id}
|
||
name: "${yambms_name}"
|
||
|
||
# Execute once
|
||
on_boot:
|
||
- priority: 600
|
||
then:
|
||
- lambda: |-
|
||
// Combiner Stall
|
||
id(yambms${yambms_id}_combiner_stall_reason).publish_state("OK");
|
||
|
||
// Battery chemistry
|
||
// Source : https://batteryuniversity.com/article/bu-216-summary-table-of-lithium-based-batteries
|
||
if (${yambms_battery_chemistry} == 1) // LFP
|
||
{
|
||
// LFP
|
||
id(yambms${yambms_id}_var_cell_nominal_v) = 3.20;
|
||
id(yambms${yambms_id}_var_cell_min_charge_v) = 3.37; // Fully charged at rest
|
||
id(yambms${yambms_id}_var_cell_max_charge_v) = 3.65;
|
||
id(yambms${yambms_id}_var_cell_max_discharge_v) = 3.00; // Not used
|
||
}
|
||
else if (${yambms_battery_chemistry} == 2) // Li-ion
|
||
{
|
||
// Li-ion
|
||
id(yambms${yambms_id}_var_cell_nominal_v) = 3.60;
|
||
id(yambms${yambms_id}_var_cell_min_charge_v) = 3.90;
|
||
id(yambms${yambms_id}_var_cell_max_charge_v) = 4.20;
|
||
id(yambms${yambms_id}_var_cell_max_discharge_v) = 3.20; // Not used
|
||
}
|
||
else if (${yambms_battery_chemistry} == 3) // LTO
|
||
{
|
||
// LTO
|
||
id(yambms${yambms_id}_var_cell_nominal_v) = 2.40;
|
||
id(yambms${yambms_id}_var_cell_min_charge_v) = 2.55; // Fully charged at rest
|
||
id(yambms${yambms_id}_var_cell_max_charge_v) = 2.85;
|
||
id(yambms${yambms_id}_var_cell_max_discharge_v) = 2.00; // Not used
|
||
}
|
||
int cell_count = ${yambms_cell_count};
|
||
// Bulk V.
|
||
id(yambms${yambms_id}_bulk_voltage).traits.set_min_value(round(cell_count * id(yambms${yambms_id}_var_cell_min_charge_v) * 10) / 10);
|
||
id(yambms${yambms_id}_bulk_voltage).traits.set_max_value(round(cell_count * id(yambms${yambms_id}_var_cell_max_charge_v) * 10) / 10);
|
||
// Float V.
|
||
id(yambms${yambms_id}_float_voltage).traits.set_min_value(round(cell_count * id(yambms${yambms_id}_var_cell_nominal_v) * 10) / 10);
|
||
id(yambms${yambms_id}_float_voltage).traits.set_max_value(round(cell_count * id(yambms${yambms_id}_var_cell_max_charge_v) * 10) / 10);
|
||
// Rebulk V.
|
||
id(yambms${yambms_id}_rebulk_voltage).traits.set_min_value(round(cell_count * id(yambms${yambms_id}_var_cell_nominal_v) * 10) / 10);
|
||
id(yambms${yambms_id}_rebulk_voltage).traits.set_max_value(round(cell_count * id(yambms${yambms_id}_var_cell_min_charge_v) * 10) / 10);
|
||
|
||
|
||
|
||
# YamBMS core lambda
|
||
interval:
|
||
- interval: ${yambms_update_interval}
|
||
then:
|
||
- lambda: |-
|
||
// +-----------------------------------------------+
|
||
// | Combiner stall detector |
|
||
// +-----------------------------------------------+
|
||
// The STEP 1 combiners (bms_combine.yaml / shunt_combine.yaml) increment
|
||
// var_to_combine_bms_number / var_to_combine_shunt_number unconditionally
|
||
// once their own id is reached, regardless of can_be_combined. A chain is
|
||
// therefore complete once its number has gone one past the number of
|
||
// declared devices. A chain that stays incomplete for several rounds is
|
||
// blocked on an id no device answers to - almost always a gap in
|
||
// bms_id/shunt_id numbering (see Design_decisions.md).
|
||
// Note : do NOT compare the number with its value on the previous round.
|
||
// This lambda samples it before the STEP 2 reset below, so in a healthy
|
||
// setup both chains are already complete here and the sampled value is the
|
||
// same on every round - which a "no progression" test reads as a stall.
|
||
static const int combiner_stall_threshold = 5;
|
||
|
||
static int combiner_bms_incomplete_streak = 0;
|
||
static bool combiner_bms_stalled = false;
|
||
|
||
static int combiner_shunt_incomplete_streak = 0;
|
||
static bool combiner_shunt_stalled = false;
|
||
|
||
int cur_bms_number = id(yambms${yambms_id}_var_to_combine_bms_number);
|
||
int cur_shunt_number = id(yambms${yambms_id}_var_to_combine_shunt_number);
|
||
bool stall_state_changed = false;
|
||
|
||
// BMS combiner chain (complete when the number is past the last declared BMS)
|
||
if (cur_bms_number > id(yambms${yambms_id}_var_bms_counter))
|
||
{
|
||
combiner_bms_incomplete_streak = 0;
|
||
|
||
if (combiner_bms_stalled)
|
||
{
|
||
combiner_bms_stalled = false;
|
||
stall_state_changed = true;
|
||
}
|
||
}
|
||
else if (++combiner_bms_incomplete_streak == combiner_stall_threshold)
|
||
{
|
||
combiner_bms_stalled = true;
|
||
stall_state_changed = true;
|
||
ESP_LOGD("yambms_debug", "Combiner stalled at BMS id %d of %d declared - check that bms_id values start at 1 and are contiguous.",
|
||
cur_bms_number, id(yambms${yambms_id}_var_bms_counter));
|
||
}
|
||
|
||
// Shunt combiner chain (complete when the number is past the last declared Shunt)
|
||
if (cur_shunt_number > id(yambms${yambms_id}_var_shunt_counter))
|
||
{
|
||
combiner_shunt_incomplete_streak = 0;
|
||
|
||
if (combiner_shunt_stalled)
|
||
{
|
||
combiner_shunt_stalled = false;
|
||
stall_state_changed = true;
|
||
}
|
||
}
|
||
else if (++combiner_shunt_incomplete_streak == combiner_stall_threshold)
|
||
{
|
||
combiner_shunt_stalled = true;
|
||
stall_state_changed = true;
|
||
ESP_LOGD("yambms_debug", "Combiner stalled at Shunt id %d of %d declared - check that shunt_id values start at 1 and are contiguous.",
|
||
cur_shunt_number, id(yambms${yambms_id}_var_shunt_counter));
|
||
}
|
||
|
||
// Diagnostic entity : publish only on a state transition, not every tick
|
||
if (stall_state_changed)
|
||
{
|
||
std::string stall_msg = "";
|
||
if (combiner_bms_stalled)
|
||
{
|
||
stall_msg += "Combiner stalled at BMS id " + std::to_string(cur_bms_number) +
|
||
" of " + std::to_string(id(yambms${yambms_id}_var_bms_counter)) +
|
||
" declared - check that bms_id values start at 1 and are contiguous.";
|
||
}
|
||
if (combiner_shunt_stalled)
|
||
{
|
||
if (!stall_msg.empty()) stall_msg += " | ";
|
||
stall_msg += "Combiner stalled at Shunt id " + std::to_string(cur_shunt_number) +
|
||
" of " + std::to_string(id(yambms${yambms_id}_var_shunt_counter)) +
|
||
" declared - check that shunt_id values start at 1 and are contiguous.";
|
||
}
|
||
if (stall_msg.empty()) stall_msg = "OK";
|
||
|
||
id(yambms${yambms_id}_combiner_stall_reason).publish_state(stall_msg);
|
||
}
|
||
|
||
// +-----------------------------------------------+
|
||
// | STEP 2 - YamBMS combiner |
|
||
// +-----------------------------------------------+
|
||
// If all device have communicated their informations
|
||
int device_counter = (id(yambms${yambms_id}_var_bms_counter) + id(yambms${yambms_id}_var_shunt_counter));
|
||
int processed_device_counter = (id(yambms${yambms_id}_var_to_combine_bms_number) + id(yambms${yambms_id}_var_to_combine_shunt_number));
|
||
if ((device_counter + 2) == processed_device_counter)
|
||
{
|
||
ESP_LOGD("yambms_debug", "===> STEP 2 : Entering YamBMS combiner... <===");
|
||
|
||
// No combined BMS > YamBMS need to be re-initialized
|
||
if (id(yambms${yambms_id}_var_to_combine_bms_counter) == 0)
|
||
{
|
||
id(yambms${yambms_id}_var_initialized) = false;
|
||
id(yambms${yambms_id}_var_requested_ccl_init) = false;
|
||
id(yambms${yambms_id}_var_requested_dcl_init) = false;
|
||
}
|
||
|
||
// +-----------------------------------------------+
|
||
// | YamBMS Errors bitmask (16bit) |
|
||
// +-----------------------------------------------+
|
||
|
||
// Alarm
|
||
// Alarm - all BMS are in alarm ?
|
||
if (id(yambms${yambms_id}_var_errors_bitmask_counter) == id(yambms${yambms_id}_var_bms_counter))
|
||
id(yambms${yambms_id}_errors_bitmask_alarm).publish_state(id(yambms${yambms_id}_var_errors_bitmask));
|
||
|
||
// At least one BMS is not in alarm
|
||
else id(yambms${yambms_id}_errors_bitmask_alarm).publish_state(0);
|
||
|
||
// Warning
|
||
id(yambms${yambms_id}_errors_bitmask_warning).publish_state(id(yambms${yambms_id}_var_errors_bitmask));
|
||
|
||
// BMS in alarms count
|
||
id(yambms${yambms_id}_errors_bitmask_counter).publish_state(id(yambms${yambms_id}_var_errors_bitmask_counter));
|
||
|
||
// +-----------------------------------------------+
|
||
// | YamBMS sensors |
|
||
// +-----------------------------------------------+
|
||
|
||
// Vars init
|
||
float total_voltage = NAN;
|
||
float current = NAN;
|
||
float power = NAN;
|
||
float battery_charging_power = NAN;
|
||
float battery_discharging_power = NAN;
|
||
float soc = NAN;
|
||
float soh = NAN;
|
||
float charging_cycles = NAN;
|
||
float battery_capacity = NAN;
|
||
float capacity_remaining = NAN;
|
||
float max_charge_current = NAN;
|
||
float max_discharge_current = NAN;
|
||
float balance_trigger_voltage = NAN;
|
||
float min_cell_v = NAN;
|
||
float min_v_cell = NAN;
|
||
float max_cell_v = NAN;
|
||
float max_v_cell = NAN;
|
||
float delta_cell_v = NAN;
|
||
float min_cell_ovp = NAN;
|
||
float max_cell_uvp = NAN;
|
||
float min_temp = NAN;
|
||
float min_temp_sensor = NAN;
|
||
float max_temp = NAN;
|
||
float max_temp_sensor = NAN;
|
||
|
||
// +-----------------------------------------------+
|
||
// | At least one BMS can be combined |
|
||
// +-----------------------------------------------+
|
||
if (id(yambms${yambms_id}_var_to_combine_bms_counter) > 0)
|
||
{
|
||
// MEAN total_voltage (Shunt/BMS)
|
||
if (id(yambms${yambms_id}_var_shunt_use) == true)
|
||
total_voltage = (id(yambms${yambms_id}_var_shunt_total_voltage) / id(yambms${yambms_id}_var_to_combine_shunt_counter));
|
||
else
|
||
total_voltage = (id(yambms${yambms_id}_var_bms_total_voltage) / id(yambms${yambms_id}_var_to_combine_bms_counter));
|
||
|
||
// TOTAL current (Shunt/BMS)
|
||
if (id(yambms${yambms_id}_var_shunt_use) == true)
|
||
current = id(yambms${yambms_id}_var_shunt_total_current);
|
||
else
|
||
current = id(yambms${yambms_id}_var_bms_total_current);
|
||
|
||
// TOTAL power (Shunt/BMS)
|
||
if (id(yambms${yambms_id}_var_shunt_use) == true)
|
||
power = round(id(yambms${yambms_id}_var_shunt_total_power));
|
||
else
|
||
power = round(id(yambms${yambms_id}_var_bms_total_power));
|
||
|
||
// battery_charging_power
|
||
if (power > 0)
|
||
battery_charging_power = power;
|
||
|
||
// battery_discharging_power
|
||
else
|
||
battery_discharging_power = power * -1; // Must be positive energy
|
||
|
||
// MEAN Battery SOC (Shunt/BMS)
|
||
if (id(yambms${yambms_id}_var_shunt_use) == true)
|
||
soc = round(id(yambms${yambms_id}_var_shunt_total_soc) / id(yambms${yambms_id}_var_to_combine_shunt_counter));
|
||
else if (id(yambms${yambms_id}_var_total_battery_capacity) > 0)
|
||
soc = round(id(yambms${yambms_id}_var_total_battery_capacity_remaining) / id(yambms${yambms_id}_var_total_battery_capacity) * 100);
|
||
|
||
// SOC manipulation
|
||
if ((soc > 98) && (id(yambms${yambms_id}_var_eoc) == false)) soc = 98; // Useful for some inverters stopping charging when SoC reaches 100%
|
||
|
||
// MEAN Battery SOH
|
||
soh = round(id(yambms${yambms_id}_var_bms_total_soh) / id(yambms${yambms_id}_var_to_combine_bms_counter));
|
||
|
||
// MEAN charging_cycles
|
||
charging_cycles = round(id(yambms${yambms_id}_var_total_charging_cycles) / id(yambms${yambms_id}_var_to_combine_bms_counter));
|
||
|
||
// +-----------------------------------------------+
|
||
// | TOTAL battery_capacity |
|
||
// +-----------------------------------------------+
|
||
battery_capacity = id(yambms${yambms_id}_var_total_battery_capacity);
|
||
|
||
// +-----------------------------------------------+
|
||
// | TOTAL battery_capacity_remaining |
|
||
// +-----------------------------------------------+
|
||
capacity_remaining = id(yambms${yambms_id}_var_total_battery_capacity_remaining);
|
||
|
||
if (id(yambms${yambms_id}_var_shunt_use) == true)
|
||
capacity_remaining = battery_capacity / 100 * soc;
|
||
|
||
// +-----------------------------------------------+
|
||
// | Max charge current |
|
||
// +-----------------------------------------------+
|
||
int cc_step = id(yambms${yambms_id}_var_charge_current_step);
|
||
|
||
ESP_LOGD("yambms_debug", "Entering Max charge current...");
|
||
|
||
// User-defined hard ceiling (slider)
|
||
float max_charge_current_yambms = id(yambms${yambms_id}_max_requested_charge_current).state;
|
||
// BMS protection guard : aggregated OCP values with 10% safety margin
|
||
float max_charge_current_bms = id(yambms${yambms_id}_var_total_max_charge_current) * 0.9;
|
||
// Nominal charge current : total battery capacity x global C-Rate (default 0.5C)
|
||
float max_charge_current_crate = battery_capacity * id(yambms${yambms_id}_max_charge_crate).state;
|
||
|
||
// The max charge current is the lowest of the three values
|
||
max_charge_current = std::min({
|
||
max_charge_current_yambms,
|
||
max_charge_current_bms,
|
||
max_charge_current_crate
|
||
});
|
||
|
||
ESP_LOGD("yambms_debug", "Max charge current YamBMS : %f A", max_charge_current_yambms);
|
||
ESP_LOGD("yambms_debug", "Max charge current BMS : %f A", max_charge_current_bms);
|
||
ESP_LOGD("yambms_debug", "Max charge current C-Rate : %f A", max_charge_current_crate);
|
||
ESP_LOGD("yambms_debug", "Max charge current : %f A", max_charge_current);
|
||
|
||
if (cc_step == 0) id(yambms${yambms_id}_var_charge_current_step) = 1;
|
||
|
||
// +-----------------------------------------------+
|
||
// | Max discharge current |
|
||
// +-----------------------------------------------+
|
||
int dc_step = id(yambms${yambms_id}_var_discharge_current_step);
|
||
|
||
ESP_LOGD("yambms_debug", "Entering Max discharge current...");
|
||
|
||
// User-defined hard ceiling (slider)
|
||
float max_discharge_current_yambms = id(yambms${yambms_id}_max_requested_discharge_current).state;
|
||
// BMS protection guard : aggregated OCP values with 10% safety margin
|
||
float max_discharge_current_bms = id(yambms${yambms_id}_var_total_max_discharge_current) * 0.9;
|
||
// Nominal discharge current : total battery capacity x global C-Rate (default 1C)
|
||
float max_discharge_current_crate = battery_capacity * id(yambms${yambms_id}_max_discharge_crate).state;
|
||
|
||
// The max discharge current is the lowest of the three values
|
||
max_discharge_current = std::min({
|
||
max_discharge_current_yambms,
|
||
max_discharge_current_bms,
|
||
max_discharge_current_crate
|
||
});
|
||
|
||
ESP_LOGD("yambms_debug", "Max discharge current YamBMS : %f A", max_discharge_current_yambms);
|
||
ESP_LOGD("yambms_debug", "Max discharge current BMS : %f A", max_discharge_current_bms);
|
||
ESP_LOGD("yambms_debug", "Max discharge current C-Rate : %f A", max_discharge_current_crate);
|
||
ESP_LOGD("yambms_debug", "Max discharge current : %f A", max_discharge_current);
|
||
|
||
if (dc_step == 0) id(yambms${yambms_id}_var_discharge_current_step) = 1;
|
||
|
||
// +-----------------------------------------------+
|
||
// | MAX balance_trigger_voltage |
|
||
// +-----------------------------------------------+
|
||
balance_trigger_voltage = id(yambms${yambms_id}_var_max_balance_trigger_voltage);
|
||
|
||
// +-----------------------------------------------+
|
||
// | MIN min_cell_voltage |
|
||
// | MIN min_voltage_cell (cell number) |
|
||
// +-----------------------------------------------+
|
||
min_cell_v = id(yambms${yambms_id}_var_min_cell_voltage);
|
||
min_v_cell = id(yambms${yambms_id}_var_min_voltage_cell);
|
||
|
||
// +-----------------------------------------------+
|
||
// | MAX max_cell_voltage |
|
||
// | MAX max_voltage_cell (cell number) |
|
||
// +-----------------------------------------------+
|
||
max_cell_v = id(yambms${yambms_id}_var_max_cell_voltage);
|
||
max_v_cell = id(yambms${yambms_id}_var_max_voltage_cell);
|
||
|
||
// +-----------------------------------------------+
|
||
// | delta_cell_voltage |
|
||
// +-----------------------------------------------+
|
||
delta_cell_v = max_cell_v - min_cell_v;
|
||
|
||
// +-----------------------------------------------+
|
||
// | MIN cell_ovp |
|
||
// +-----------------------------------------------+
|
||
min_cell_ovp = id(yambms${yambms_id}_var_min_cell_ovp);
|
||
|
||
// +-----------------------------------------------+
|
||
// | MAX cell_uvp |
|
||
// +-----------------------------------------------+
|
||
max_cell_uvp = id(yambms${yambms_id}_var_max_cell_uvp);
|
||
|
||
// +-----------------------------------------------+
|
||
// | MIN temperature |
|
||
// | MIN temperature_sensor |
|
||
// +-----------------------------------------------+
|
||
min_temp = id(yambms${yambms_id}_var_min_temperature);
|
||
min_temp_sensor = id(yambms${yambms_id}_var_min_temperature_sensor);
|
||
|
||
// +-----------------------------------------------+
|
||
// | MAX temperature |
|
||
// | MAX temperature_sensor |
|
||
// +-----------------------------------------------+
|
||
max_temp = id(yambms${yambms_id}_var_max_temperature);
|
||
max_temp_sensor = id(yambms${yambms_id}_var_max_temperature_sensor);
|
||
}
|
||
|
||
// Publishing sensors
|
||
id(yambms${yambms_id}_total_voltage).publish_state(total_voltage);
|
||
id(yambms${yambms_id}_current).publish_state(current);
|
||
id(yambms${yambms_id}_power).publish_state(power);
|
||
id(yambms${yambms_id}_battery_charging_power).publish_state(battery_charging_power);
|
||
id(yambms${yambms_id}_battery_discharging_power).publish_state(battery_discharging_power);
|
||
id(yambms${yambms_id}_battery_soc).publish_state(soc);
|
||
id(yambms${yambms_id}_battery_soh).publish_state(soh);
|
||
id(yambms${yambms_id}_charging_cycles).publish_state(charging_cycles);
|
||
id(yambms${yambms_id}_battery_capacity).publish_state(round(battery_capacity));
|
||
id(yambms${yambms_id}_battery_capacity_remaining).publish_state(round(capacity_remaining));
|
||
id(yambms${yambms_id}_max_charge_current).publish_state(round(max_charge_current));
|
||
id(yambms${yambms_id}_max_discharge_current).publish_state(round(max_discharge_current));
|
||
id(yambms${yambms_id}_balance_trigger_voltage).publish_state(balance_trigger_voltage);
|
||
id(yambms${yambms_id}_min_cell_voltage).publish_state(min_cell_v);
|
||
id(yambms${yambms_id}_min_voltage_cell).publish_state(min_v_cell);
|
||
id(yambms${yambms_id}_max_cell_voltage).publish_state(max_cell_v);
|
||
id(yambms${yambms_id}_max_voltage_cell).publish_state(max_v_cell);
|
||
id(yambms${yambms_id}_delta_cell_voltage).publish_state(delta_cell_v);
|
||
id(yambms${yambms_id}_cell_ovp).publish_state(min_cell_ovp);
|
||
id(yambms${yambms_id}_cell_uvp).publish_state(max_cell_uvp);
|
||
id(yambms${yambms_id}_min_temperature).publish_state(min_temp);
|
||
id(yambms${yambms_id}_min_temperature_sensor).publish_state(min_temp_sensor);
|
||
id(yambms${yambms_id}_max_temperature).publish_state(max_temp);
|
||
id(yambms${yambms_id}_max_temperature_sensor).publish_state(max_temp_sensor);
|
||
|
||
// +-----------------------------------------------+
|
||
// | Equalizing state |
|
||
// +-----------------------------------------------+
|
||
if (id(yambms${yambms_id}_var_equalizing_counter) > 0)
|
||
id(yambms${yambms_id}_equalizing).publish_state(true);
|
||
else
|
||
id(yambms${yambms_id}_equalizing).publish_state(false);
|
||
|
||
// +-----------------------------------------------+
|
||
// | Charging allowed |
|
||
// +-----------------------------------------------+
|
||
if (id(yambms${yambms_id}_switch_charging).state && id(yambms${yambms_id}_var_charging_allowed_counter) > 0)
|
||
id(yambms${yambms_id}_charging_allowed).publish_state(true);
|
||
else
|
||
id(yambms${yambms_id}_charging_allowed).publish_state(false);
|
||
|
||
// +-----------------------------------------------+
|
||
// | Discharging allowed |
|
||
// +-----------------------------------------------+
|
||
if (id(yambms${yambms_id}_switch_discharging).state && id(yambms${yambms_id}_var_discharging_allowed_counter) > 0)
|
||
id(yambms${yambms_id}_discharging_allowed).publish_state(true);
|
||
else
|
||
id(yambms${yambms_id}_discharging_allowed).publish_state(false);
|
||
|
||
// +-----------------------------------------------+
|
||
// | BMS count |
|
||
// +-----------------------------------------------+
|
||
// BMS count total
|
||
id(yambms${yambms_id}_bms_count).publish_state(id(yambms${yambms_id}_var_bms_counter));
|
||
// BMS count combined
|
||
id(yambms${yambms_id}_bms_combined).publish_state(id(yambms${yambms_id}_var_to_combine_bms_counter));
|
||
// BMS count blocking charge
|
||
id(yambms${yambms_id}_bms_blocking_charge).publish_state(id(yambms${yambms_id}_var_bms_blocking_charge_counter));
|
||
// BMS count blocking discharge
|
||
id(yambms${yambms_id}_bms_blocking_discharge).publish_state(id(yambms${yambms_id}_var_bms_blocking_discharge_counter));
|
||
|
||
// +-----------------------------------------------+
|
||
// | Shunt count |
|
||
// +-----------------------------------------------+
|
||
// Shunt count total
|
||
id(yambms${yambms_id}_shunt_count).publish_state(id(yambms${yambms_id}_var_shunt_counter));
|
||
// Shunt count combined
|
||
id(yambms${yambms_id}_shunt_combined).publish_state(id(yambms${yambms_id}_var_to_combine_shunt_counter));
|
||
|
||
// +-----------------------------------------------+
|
||
// | Global vars reset |
|
||
// +-----------------------------------------------+
|
||
id(yambms${yambms_id}_var_errors_bitmask) = 0;
|
||
id(yambms${yambms_id}_var_errors_bitmask_counter) = 0;
|
||
id(yambms${yambms_id}_var_bms_total_voltage) = 0.0;
|
||
id(yambms${yambms_id}_var_shunt_total_voltage) = 0.0;
|
||
id(yambms${yambms_id}_var_bms_total_current) = 0.0;
|
||
id(yambms${yambms_id}_var_shunt_total_current) = 0.0;
|
||
id(yambms${yambms_id}_var_bms_total_power) = 0.0;
|
||
id(yambms${yambms_id}_var_shunt_total_power) = 0.0;
|
||
id(yambms${yambms_id}_var_bms_total_soc) = 0.0;
|
||
id(yambms${yambms_id}_var_shunt_total_soc) = 0.0;
|
||
id(yambms${yambms_id}_var_bms_total_soh) = 0.0;
|
||
id(yambms${yambms_id}_var_total_battery_capacity) = 0.0;
|
||
id(yambms${yambms_id}_var_total_battery_capacity_remaining) = 0.0;
|
||
id(yambms${yambms_id}_var_total_max_charge_current) = 0.0;
|
||
id(yambms${yambms_id}_var_total_max_discharge_current) = 0.0;
|
||
id(yambms${yambms_id}_var_total_charging_cycles) = 0.0;
|
||
id(yambms${yambms_id}_var_max_balance_trigger_voltage) = 0.0;
|
||
id(yambms${yambms_id}_var_min_cell_voltage) = 5.0;
|
||
id(yambms${yambms_id}_var_min_voltage_cell) = 0;
|
||
id(yambms${yambms_id}_var_max_cell_voltage) = 0.0;
|
||
id(yambms${yambms_id}_var_max_voltage_cell) = 0;
|
||
id(yambms${yambms_id}_var_min_cell_ovp) = 5.0;
|
||
id(yambms${yambms_id}_var_max_cell_uvp) = 0.0;
|
||
id(yambms${yambms_id}_var_min_temperature) = 100.0;
|
||
id(yambms${yambms_id}_var_min_temperature_sensor) = 0;
|
||
id(yambms${yambms_id}_var_max_temperature) = -100.0;
|
||
id(yambms${yambms_id}_var_max_temperature_sensor) = 0;
|
||
id(yambms${yambms_id}_var_equalizing_counter) = 0;
|
||
id(yambms${yambms_id}_var_charging_allowed_counter) = 0;
|
||
id(yambms${yambms_id}_var_discharging_allowed_counter) = 0;
|
||
id(yambms${yambms_id}_var_bms_blocking_charge_counter) = 0;
|
||
id(yambms${yambms_id}_var_bms_blocking_discharge_counter) = 0;
|
||
|
||
// The devices are once again authorized to communicate their informations
|
||
id(yambms${yambms_id}_var_to_combine_bms_number) = 1;
|
||
id(yambms${yambms_id}_var_to_combine_shunt_number) = 1;
|
||
}
|
||
|
||
// +-----------------------------------------------+
|
||
// | STEP 3 - YamBMS Logic |
|
||
// +-----------------------------------------------+
|
||
if ((id(yambms${yambms_id}_bms_combined).has_state()) &&
|
||
(id(yambms${yambms_id}_total_voltage).has_state()) &&
|
||
(id(yambms${yambms_id}_current).has_state()) &&
|
||
(id(yambms${yambms_id}_power).has_state()) &&
|
||
(id(yambms${yambms_id}_battery_soc).has_state()) &&
|
||
(id(yambms${yambms_id}_battery_soh).has_state()) &&
|
||
(id(yambms${yambms_id}_battery_capacity).has_state()) &&
|
||
(id(yambms${yambms_id}_equalizing).has_state()) &&
|
||
(id(yambms${yambms_id}_max_cell_voltage).has_state()) &&
|
||
(id(yambms${yambms_id}_max_charge_current).has_state()) &&
|
||
(id(yambms${yambms_id}_max_discharge_current).has_state()) &&
|
||
(id(yambms${yambms_id}_cell_ovp).has_state()) &&
|
||
(id(yambms${yambms_id}_cell_uvp).has_state()) &&
|
||
(id(yambms${yambms_id}_cell_count).has_state()) &&
|
||
(id(yambms${yambms_id}_charging_allowed).has_state()) &&
|
||
(id(yambms${yambms_id}_discharging_allowed).has_state()))
|
||
{
|
||
|
||
ESP_LOGD("yambms_debug", "===> STEP 3 : Entering YamBMS logic... <===");
|
||
|
||
// +-----------------------------------------------+
|
||
// | Charging Logic |
|
||
// +-----------------------------------------------+
|
||
// EOC => Float
|
||
if ((id(yambms${yambms_id}_var_charge_status) == "EOC") && (id(yambms${yambms_id}_switch_float).state)) id(yambms${yambms_id}_var_charge_status) = "Float";
|
||
// No Float => EOC
|
||
else if ((id(yambms${yambms_id}_var_charge_status) == "Float") && (!id(yambms${yambms_id}_switch_float).state)) id(yambms${yambms_id}_var_charge_status) = "EOC";
|
||
// Force Float
|
||
else if (id(yambms${yambms_id}_var_force_float) == true) id(yambms${yambms_id}_var_charge_status) = "Float";
|
||
|
||
// +-----------------------------------------------+
|
||
// | Charging allowed (BMS and YamBMS) |
|
||
// +-----------------------------------------------+
|
||
else if ((id(yambms${yambms_id}_charging_allowed).has_state()) && (id(yambms${yambms_id}_charging_allowed).state))
|
||
{
|
||
// Variables
|
||
float cell_bulk_v = (id(yambms${yambms_id}_bulk_voltage).state / id(yambms${yambms_id}_cell_count).state);
|
||
float cell_rebulk_v = (id(yambms${yambms_id}_rebulk_voltage).state / id(yambms${yambms_id}_cell_count).state);
|
||
float max_cell_v = id(yambms${yambms_id}_max_cell_voltage).state;
|
||
|
||
// +-----------------------------------------------+
|
||
// | Rebulk after N days since last full charge |
|
||
// +-----------------------------------------------+
|
||
int rebulk_days = (int)id(yambms${yambms_id}_rebulk_days).state;
|
||
if (rebulk_days == 0) // Function disabled
|
||
{
|
||
id(yambms${yambms_id}_var_rebulk_days_active) = false;
|
||
}
|
||
else if (!id(yambms${yambms_id}_var_rebulk_days_active)) // Function enabled
|
||
{
|
||
if (rebulk_days > 0)
|
||
{
|
||
time_t last_eoc = id(yambms${yambms_id}_var_eoc_timestamp);
|
||
if (last_eoc > 0)
|
||
{
|
||
// Round down to 00:00:00 so rebulk gets enabled early in the day
|
||
struct tm *eoc_tm = localtime(&last_eoc);
|
||
eoc_tm->tm_hour = 0; eoc_tm->tm_min = 0; eoc_tm->tm_sec = 0;
|
||
time_t last_eoc_day = mktime(eoc_tm);
|
||
time_t now = id(my_time).utcnow().timestamp;
|
||
float days_since_eoc = (float)(now - last_eoc_day) / 86400.0f;
|
||
if (days_since_eoc >= rebulk_days)
|
||
{
|
||
id(yambms${yambms_id}_var_rebulk_days_active) = true;
|
||
ESP_LOGD("yambms_debug", "Rebulk after %d days since last full charge: activating rebulk logic", rebulk_days);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// +-----------------------------------------------+
|
||
// | Force Bulk Logic |
|
||
// +-----------------------------------------------+
|
||
if (id(yambms${yambms_id}_switch_force_bulk).state)
|
||
{
|
||
// Stop Force Bulk when entering the Cut-Off phase
|
||
if (id(yambms${yambms_id}_var_charge_status) == "Cut-Off")
|
||
id(yambms${yambms_id}_switch_force_bulk).turn_off();
|
||
// Force Bulk
|
||
else id(yambms${yambms_id}_var_charge_status) = "Bulk";
|
||
}
|
||
|
||
// +-----------------------------------------------+
|
||
// | Rebulk Logic |
|
||
// +-----------------------------------------------+
|
||
// Init / Wait
|
||
else if ((id(yambms${yambms_id}_var_charge_status) == "Init") || (id(yambms${yambms_id}_var_charge_status) == "Wait"))
|
||
id(yambms${yambms_id}_var_charge_status) = "Bulk";
|
||
// Max Cell V. <= 3.3V (default value)
|
||
else if (max_cell_v <= cell_rebulk_v)
|
||
id(yambms${yambms_id}_var_charge_status) = "Bulk";
|
||
// SoC <= 85% (default value)
|
||
else if (id(yambms${yambms_id}_battery_soc).state <= id(yambms${yambms_id}_rebulk_soc).state)
|
||
id(yambms${yambms_id}_var_charge_status) = "Bulk";
|
||
// Rebulk Days >= 14 (default value)
|
||
else if (id(yambms${yambms_id}_var_rebulk_days_active) == true)
|
||
id(yambms${yambms_id}_var_charge_status) = "Bulk";
|
||
// Force Charge requested
|
||
else if (id(yambms${yambms_id}_requested_force_charge).state)
|
||
id(yambms${yambms_id}_var_charge_status) = "Bulk";
|
||
|
||
// +-----------------------------------------------+
|
||
// | Charging Logic (Bulk) |
|
||
// +-----------------------------------------------+
|
||
if ((id(yambms${yambms_id}_var_charge_status) != "EOC") && (id(yambms${yambms_id}_var_charge_status) != "Float"))
|
||
{
|
||
|
||
float cv_min = id(yambms${yambms_id}_var_cell_min_charge_v);
|
||
float cv_max = id(yambms${yambms_id}_var_cell_max_charge_v);
|
||
float current = id(yambms${yambms_id}_current).state;
|
||
float cutoff_resistance = ((cv_max - cv_min) / id(yambms${yambms_id}_battery_capacity).state / ${yambms_cutoff_crate});
|
||
float current_deadband = (id(yambms${yambms_id}_battery_capacity).state * ${yambms_current_deadband_crate});
|
||
|
||
uint32_t ms_now = millis();
|
||
static uint32_t ms_cutoff = ms_now;
|
||
static uint32_t ms_bulk = ms_now;
|
||
|
||
// +-----------------------------------------------+
|
||
// | Cut-Off Charging Logic |
|
||
// +-----------------------------------------------+
|
||
|
||
// Cut-Off Cell Voltage source :
|
||
// "Max Cell Voltage" (default) : conservative, the EOC depends on the highest cell.
|
||
// Protects imbalanced packs but the charge termination voltage varies
|
||
// with the imbalance of the day.
|
||
// "Average Cell Voltage" : the EOC reflects the state of the whole pack, giving a
|
||
// consistent charge termination voltage. The runner cell no longer stops
|
||
// the charge : cell protection MUST be ensured by Auto CVL and/or Auto CCL
|
||
// with BMS OVP as last resort.
|
||
// Note : if the inverter does not respect the CVL, only Auto CCL is effective.
|
||
|
||
float cutoff_cell_v = max_cell_v;
|
||
if (id(yambms${yambms_id}_select_cutoff_cell_voltage).current_option() == "Average Cell Voltage")
|
||
cutoff_cell_v = (id(yambms${yambms_id}_total_voltage).state / id(yambms${yambms_id}_cell_count).state);
|
||
|
||
// Current deadband
|
||
// Current within sensor noise / PV starvation
|
||
if (fabs(current) < current_deadband)
|
||
{
|
||
// "Fully charged at rest" signature
|
||
// cv_min is by definition the resting voltage of a full cell.
|
||
// A near-zero current with cutoff_cell_v above cv_min indicates
|
||
// a full battery, the Cut-Off conditions are considered valid.
|
||
if ((cutoff_cell_v >= cv_min) &&
|
||
(id(yambms${yambms_id}_battery_soc).state >= ${yambms_eoc_min_soc})) // Min. SoC gate
|
||
{
|
||
ms_bulk = ms_now; // Reset millis to not enter the Bulk phase
|
||
}
|
||
|
||
// cutoff_cell_v below cv_min at near-zero current.
|
||
// The battery cannot be full, the Bulk conditions are valid.
|
||
else if (cutoff_cell_v < cv_min)
|
||
{
|
||
ms_cutoff = ms_now; // Reset millis to not enter the Cut-Off phase
|
||
}
|
||
// Grey zone : cutoff_cell_v >= cv_min but SoC below the gate
|
||
// No conclusion can be drawn
|
||
else
|
||
{
|
||
ms_bulk = ms_now; // Reset millis to not enter the Bulk phase
|
||
ms_cutoff = ms_now; // Reset millis to not enter the Cut-Off phase
|
||
}
|
||
}
|
||
|
||
// Charging
|
||
else if (current > 0)
|
||
{
|
||
float cutoff_voltage = (cutoff_cell_v - cutoff_resistance * current);
|
||
|
||
if ((cutoff_voltage >= cv_min) && // Compensated voltage criterion
|
||
(id(yambms${yambms_id}_battery_soc).state >= ${yambms_eoc_min_soc})) // Min. SoC gate
|
||
{
|
||
// Cut-Off phase
|
||
ms_bulk = ms_now; // Reset millis to not enter the Bulk phase
|
||
}
|
||
else
|
||
{
|
||
// Bulk phase
|
||
ms_cutoff = ms_now; // Reset millis to not enter the Cut-Off phase
|
||
}
|
||
}
|
||
|
||
// Discharging
|
||
else if (cutoff_cell_v < (cell_bulk_v - ${yambms_cell_hysteresis_v}))
|
||
{
|
||
ms_cutoff = ms_now; // Reset millis to not enter the Cut-Off phase
|
||
}
|
||
else // Grey zone, no charge_status changes
|
||
{
|
||
ms_bulk = ms_now; // Reset millis to not enter the Bulk phase
|
||
ms_cutoff = ms_now; // Reset millis to not enter the Cut-Off phase
|
||
}
|
||
|
||
// Regarding the transition between Bulk and Cut-Off phase
|
||
// The criteria check must succeed for 10s to ensure that
|
||
// these are not random/erroneous/false readings of the BMS
|
||
|
||
// Bulk phase
|
||
if (ms_now - ms_bulk >= 10000) // 10s
|
||
{
|
||
ESP_LOGD("yambms_debug", "Entering the Bulk phase...");
|
||
// Stop timer
|
||
if (id(yambms${yambms_id}_script_eoc_timer).is_running()) id(yambms${yambms_id}_script_eoc_timer).stop();
|
||
if (id(yambms${yambms_id}_script_cutoff_timer).is_running()) id(yambms${yambms_id}_script_cutoff_timer).stop();
|
||
// Balancing : the BMS is equalizing the cells
|
||
if (id(yambms${yambms_id}_equalizing).state) id(yambms${yambms_id}_var_charge_status) = "Balancing";
|
||
// Bulk
|
||
else id(yambms${yambms_id}_var_charge_status) = "Bulk";
|
||
}
|
||
|
||
// Cut-Off phase
|
||
else if (ms_now - ms_cutoff >= 10000) // 10s
|
||
{
|
||
ESP_LOGD("yambms_debug", "Entering the Cut-Off phase...");
|
||
|
||
// Cut-Off : the end of charging is near
|
||
id(yambms${yambms_id}_var_charge_status) = "Cut-Off";
|
||
|
||
// If the EOC Timer switch is enabled
|
||
if (id(yambms${yambms_id}_switch_eoc_timer).state)
|
||
{
|
||
// Start EOC timer
|
||
// The charging process ends at the latest at the end of this timer (30min by default)
|
||
if (!id(yambms${yambms_id}_script_eoc_timer).is_running())
|
||
id(yambms${yambms_id}_script_eoc_timer).execute();
|
||
}
|
||
// End Of Charge
|
||
// Equalizing
|
||
if (id(yambms${yambms_id}_equalizing).state)
|
||
{
|
||
// Stop cut-off timer
|
||
if (id(yambms${yambms_id}_script_cutoff_timer).is_running())
|
||
id(yambms${yambms_id}_script_cutoff_timer).stop();
|
||
}
|
||
// Not Equalizing => Start cut-off timer
|
||
// If the conditions continue to be respected the charging process will stop in 180s (default value)
|
||
// This duration must exceed the post-burst cell relaxation time (30-120s) to reject transient voltage readings
|
||
else if (!id(yambms${yambms_id}_script_cutoff_timer).is_running())
|
||
id(yambms${yambms_id}_script_cutoff_timer).execute();
|
||
}
|
||
|
||
}
|
||
}
|
||
// Charging not allowed (BMS or YamBMS)
|
||
else if (id(yambms${yambms_id}_var_bms_charging_logic) == true)
|
||
{
|
||
ESP_LOGD("yambms_debug", "Charging not allowed !");
|
||
if (!id(yambms${yambms_id}_switch_charging).state) id(yambms${yambms_id}_var_charge_status) = "Wait";
|
||
}
|
||
else
|
||
{
|
||
ESP_LOGD("yambms_debug", "Charging not allowed !");
|
||
id(yambms${yambms_id}_var_charge_status) = "Wait";
|
||
}
|
||
|
||
// Publishing sensor
|
||
id(yambms${yambms_id}_charging_status).publish_state(id(yambms${yambms_id}_var_charge_status));
|
||
|
||
// +-----------------------------------------------+
|
||
// | Charging Instruction |
|
||
// +-----------------------------------------------+
|
||
std::string charging_instruction;
|
||
// Bulk Charge
|
||
if ((id(yambms${yambms_id}_var_charge_status) != "Init") &&
|
||
(id(yambms${yambms_id}_var_charge_status) != "Wait") &&
|
||
(id(yambms${yambms_id}_var_charge_status) != "EOC") &&
|
||
(id(yambms${yambms_id}_var_charge_status) != "Float"))
|
||
{
|
||
id(yambms${yambms_id}_var_eoc) = false; // SoC 100% can't be sent
|
||
charging_instruction = "Bulk";
|
||
}
|
||
// Float Charge
|
||
else if (id(yambms${yambms_id}_var_charge_status) == "Float")
|
||
{
|
||
charging_instruction = "Float";
|
||
}
|
||
// Init / Wait / EOC
|
||
else charging_instruction = "Stop";
|
||
// Publishing sensor
|
||
id(yambms${yambms_id}_charging_instruction).publish_state(charging_instruction);
|
||
|
||
// +-----------------------------------------------+
|
||
// | Discharging Instruction |
|
||
// +-----------------------------------------------+
|
||
bool discharging_instruction = false;
|
||
if (id(yambms${yambms_id}_discharging_allowed).state)
|
||
discharging_instruction = true;
|
||
if (id(yambms${yambms_id}_total_voltage).state <= id(yambms${yambms_id}_requested_discharge_voltage).state)
|
||
discharging_instruction = false;
|
||
// Publishing sensor
|
||
id(yambms${yambms_id}_discharging_instruction).publish_state(discharging_instruction);
|
||
|
||
// +-----------------------------------------------+
|
||
// | ============> Requested Values <============ |
|
||
// +-----------------------------------------------+
|
||
// Vars init
|
||
float requested_charge_voltage;
|
||
float requested_discharge_voltage;
|
||
float requested_charge_current;
|
||
float requested_discharge_current;
|
||
|
||
// A node with no inverter link declared (CAN/RS485 package not included)
|
||
// leaves the counter at 0. Clamp to 1 to prevent division by 0.
|
||
const int comm_interfaces_count = std::max(1, id(yambms${yambms_id}_var_comm_interfaces_count));
|
||
|
||
// At least one BMS combined
|
||
if (id(yambms${yambms_id}_var_to_combine_bms_counter) > 0)
|
||
{
|
||
// +-----------------------------------------------+
|
||
// | Requested Charge Voltage (CVL) |
|
||
// +-----------------------------------------------+
|
||
// Bulk
|
||
if (charging_instruction == "Bulk")
|
||
requested_charge_voltage = id(yambms${yambms_id}_bulk_voltage).state;
|
||
// Float
|
||
else if (charging_instruction == "Float")
|
||
requested_charge_voltage = id(yambms${yambms_id}_float_voltage).state;
|
||
// Stop : keep at nominal voltage
|
||
else
|
||
requested_charge_voltage = id(yambms${yambms_id}_var_cell_nominal_v) * ${yambms_cell_count};
|
||
|
||
requested_charge_voltage += id(yambms${yambms_id}_charger_offset_v).state +
|
||
id(yambms${yambms_id}_var_auto_cvl) +
|
||
id(yambms${yambms_id}_var_auto_float) +
|
||
id(yambms${yambms_id}_var_auto_custom_cvl);
|
||
|
||
// Publish the sensor
|
||
id(yambms${yambms_id}_requested_charge_voltage).publish_state(requested_charge_voltage);
|
||
|
||
// +-----------------------------------------------+
|
||
// | Requested Discharge Voltage (DVL) |
|
||
// +-----------------------------------------------+
|
||
requested_discharge_voltage = ((id(yambms${yambms_id}_cell_uvp).state + 0.2) * id(yambms${yambms_id}_cell_count).state);
|
||
|
||
// Publish the sensor
|
||
id(yambms${yambms_id}_requested_discharge_voltage).publish_state(requested_discharge_voltage);
|
||
|
||
// +-----------------------------------------------+
|
||
// | Requested Charge Current (CCL) |
|
||
// +-----------------------------------------------+
|
||
int cc_step = id(yambms${yambms_id}_var_charge_current_step);
|
||
if (cc_step == id(yambms${yambms_id}_var_auto_ccl_functions_count) + 1)
|
||
{
|
||
ESP_LOGD("yambms_debug", "Entering Requested CCL...");
|
||
ESP_LOGD("yambms_debug", "Charging instruction : %s", charging_instruction.c_str());
|
||
|
||
// Charging Not Allowed
|
||
requested_charge_current = 0;
|
||
// Charging Allowed
|
||
if ((charging_instruction == "Bulk") || (charging_instruction == "Float"))
|
||
{
|
||
float auto_limit = std::min({
|
||
id(yambms${yambms_id}_var_auto_temperature_ccl),
|
||
id(yambms${yambms_id}_var_auto_ccl),
|
||
id(yambms${yambms_id}_var_auto_ccl_current_taper),
|
||
id(yambms${yambms_id}_var_auto_soc_limit),
|
||
id(yambms${yambms_id}_var_auto_eoc),
|
||
id(yambms${yambms_id}_var_auto_custom_ccl)
|
||
});
|
||
|
||
requested_charge_current = id(yambms${yambms_id}_max_charge_current).state + auto_limit;
|
||
requested_charge_current = round(requested_charge_current / comm_interfaces_count);
|
||
if (requested_charge_current < 0) requested_charge_current = 0;
|
||
}
|
||
|
||
// Publish the sensor
|
||
id(yambms${yambms_id}_requested_charge_current).publish_state(requested_charge_current);
|
||
|
||
// Derating reason update and log
|
||
id(yambms${yambms_id}_ccl_derating_reason).update();
|
||
ESP_LOGD("yambms_debug", "CCL limits : temp=%.1f auto=%.1f taper=%.1f soc=%.1f eoc=%.1f custom=%.1f => CCL=%.1f A",
|
||
id(yambms${yambms_id}_var_auto_temperature_ccl),
|
||
id(yambms${yambms_id}_var_auto_ccl),
|
||
id(yambms${yambms_id}_var_auto_ccl_current_taper),
|
||
id(yambms${yambms_id}_var_auto_soc_limit),
|
||
id(yambms${yambms_id}_var_auto_eoc),
|
||
id(yambms${yambms_id}_var_auto_custom_ccl),
|
||
requested_charge_current);
|
||
|
||
if (id(yambms${yambms_id}_var_charge_status) != "Init")
|
||
id(yambms${yambms_id}_var_requested_ccl_init) = true;
|
||
|
||
id(yambms${yambms_id}_var_charge_current_step) = 1;
|
||
}
|
||
|
||
// +-----------------------------------------------+
|
||
// | Requested Discharge Current (DCL) |
|
||
// +-----------------------------------------------+
|
||
int dc_step = id(yambms${yambms_id}_var_discharge_current_step);
|
||
if (dc_step == id(yambms${yambms_id}_var_auto_dcl_functions_count) + 1)
|
||
{
|
||
ESP_LOGD("yambms_debug", "Entering Requested DCL...");
|
||
// Discharging Not Allowed
|
||
requested_discharge_current = 0;
|
||
// Discharging Allowed
|
||
if (discharging_instruction == true)
|
||
{
|
||
float auto_limit = std::min({
|
||
id(yambms${yambms_id}_var_auto_temperature_dcl),
|
||
id(yambms${yambms_id}_var_auto_dcl),
|
||
id(yambms${yambms_id}_var_auto_custom_dcl)
|
||
});
|
||
|
||
requested_discharge_current = id(yambms${yambms_id}_max_discharge_current).state + auto_limit;
|
||
requested_discharge_current = round(requested_discharge_current / comm_interfaces_count);
|
||
if (requested_discharge_current < 0) requested_discharge_current = 0;
|
||
}
|
||
|
||
// Publish the sensor
|
||
id(yambms${yambms_id}_requested_discharge_current).publish_state(requested_discharge_current);
|
||
|
||
// Derating reason update and log
|
||
id(yambms${yambms_id}_dcl_derating_reason).update();
|
||
ESP_LOGD("yambms_debug", "DCL limits : temp=%.1f auto=%.1f custom=%.1f => DCL=%.1f A",
|
||
id(yambms${yambms_id}_var_auto_temperature_dcl),
|
||
id(yambms${yambms_id}_var_auto_dcl),
|
||
id(yambms${yambms_id}_var_auto_custom_dcl),
|
||
requested_discharge_current);
|
||
|
||
id(yambms${yambms_id}_var_requested_dcl_init) = true;
|
||
|
||
id(yambms${yambms_id}_var_discharge_current_step) = 1;
|
||
}
|
||
}
|
||
// No BMS combined
|
||
else
|
||
{
|
||
// Publishing sensors to NAN
|
||
id(yambms${yambms_id}_requested_charge_voltage).publish_state(NAN);
|
||
id(yambms${yambms_id}_requested_discharge_voltage).publish_state(NAN);
|
||
id(yambms${yambms_id}_requested_charge_current).publish_state(NAN);
|
||
id(yambms${yambms_id}_requested_discharge_current).publish_state(NAN);
|
||
}
|
||
|
||
// +-----------------------------------------------+
|
||
// | End Of STEP 3 : YamBMS initialized ? |
|
||
// | The datas can be communicated to the inverter |
|
||
// +-----------------------------------------------+
|
||
if ((id(yambms${yambms_id}_bms_combined).state > 0) &&
|
||
(id(yambms${yambms_id}_var_charge_status) != "Init") &&
|
||
(id(yambms${yambms_id}_total_voltage).state > 0) &&
|
||
(id(yambms${yambms_id}_min_temperature).state < 100) &&
|
||
(id(yambms${yambms_id}_max_temperature).state > -100) &&
|
||
(id(yambms${yambms_id}_requested_charge_voltage).state > 0) &&
|
||
(id(yambms${yambms_id}_requested_discharge_voltage).state > 0) &&
|
||
(id(yambms${yambms_id}_var_requested_ccl_init) == true) &&
|
||
(id(yambms${yambms_id}_var_requested_dcl_init) == true))
|
||
{
|
||
id(yambms${yambms_id}_var_initialized) = true;
|
||
}
|
||
else id(yambms${yambms_id}_var_initialized) = false; // Communication with the inverter stops.
|
||
}
|
||
|
||
// +-----------------------------------------------+
|
||
// | DEBUG LOGS |
|
||
// +-----------------------------------------------+
|
||
if (id(yambms${yambms_id}_var_initialized) == true) { ESP_LOGD("yambms_debug", "===> YamBMS initialized <=== : true"); }
|
||
else { ESP_LOGD("yambms_debug", "===> YamBMS initialized <=== : false"); }
|
||
if (id(yambms${yambms_id}_total_voltage).has_state()) { ESP_LOGD("yambms_debug", "Battery Voltage : %f V", id(yambms${yambms_id}_total_voltage).state); }
|
||
if (id(yambms${yambms_id}_current).has_state()) { ESP_LOGD("yambms_debug", "Battery Current : %f A", id(yambms${yambms_id}_current).state); }
|
||
if (id(yambms${yambms_id}_power).has_state()) { ESP_LOGD("yambms_debug", "Battery Power : %f W", id(yambms${yambms_id}_power).state); }
|
||
if (id(yambms${yambms_id}_battery_soc).has_state()) { ESP_LOGD("yambms_debug", "Battery SOC : %f %%", id(yambms${yambms_id}_battery_soc).state); }
|
||
if (id(yambms${yambms_id}_battery_soh).has_state()) { ESP_LOGD("yambms_debug", "Battery SOH : %f %%", id(yambms${yambms_id}_battery_soh).state); }
|
||
if (id(yambms${yambms_id}_min_temperature).has_state()) { ESP_LOGD("yambms_debug", "Min temp. : %f °C", id(yambms${yambms_id}_min_temperature).state); }
|
||
if (id(yambms${yambms_id}_max_temperature).has_state()) { ESP_LOGD("yambms_debug", "Max temp. : %f °C", id(yambms${yambms_id}_max_temperature).state); }
|
||
ESP_LOGD("yambms_debug", "Charge Status : %s", id(yambms${yambms_id}_var_charge_status).c_str());
|
||
if (id(yambms${yambms_id}_charging_instruction).has_state()) { ESP_LOGD("yambms_debug", "Charging instruction : %s", id(yambms${yambms_id}_charging_instruction).state.c_str()); }
|
||
if (id(yambms${yambms_id}_discharging_instruction).has_state())
|
||
{
|
||
bool discharging_instruction = id(yambms${yambms_id}_discharging_instruction).state;
|
||
if (discharging_instruction == true) { ESP_LOGD("yambms_debug", "Discharging instruction : true"); }
|
||
else { ESP_LOGD("yambms_debug", "Discharging instruction : false"); }
|
||
}
|
||
if (id(yambms${yambms_id}_requested_charge_voltage).has_state()) { ESP_LOGD("yambms_debug", "Requested CVL : %f V", id(yambms${yambms_id}_requested_charge_voltage).state); }
|
||
if (id(yambms${yambms_id}_requested_discharge_voltage).has_state()) { ESP_LOGD("yambms_debug", "Requested DVL : %f V", id(yambms${yambms_id}_requested_discharge_voltage).state); }
|
||
if (id(yambms${yambms_id}_requested_charge_current).has_state()) { ESP_LOGD("yambms_debug", "Requested CCL : %f A", id(yambms${yambms_id}_requested_charge_current).state); }
|
||
if (id(yambms${yambms_id}_requested_discharge_current).has_state()) { ESP_LOGD("yambms_debug", "Requested DCL : %f A", id(yambms${yambms_id}_requested_discharge_current).state); }
|
||
if (id(yambms${yambms_id}_ccl_derating_reason).has_state()) { ESP_LOGD("yambms_debug", "CCL derating reason : %s", id(yambms${yambms_id}_ccl_derating_reason).state.c_str()); }
|
||
if (id(yambms${yambms_id}_dcl_derating_reason).has_state()) { ESP_LOGD("yambms_debug", "DCL derating reason : %s", id(yambms${yambms_id}_dcl_derating_reason).state.c_str()); }
|
||
|
||
// if (id().has_state()) { ESP_LOGD("yambms_debug", "Text : %f V", id().state); }
|
||
|
||
|
||
|
||
# +--------------------------------------+
|
||
# | scripts |
|
||
# +--------------------------------------+
|
||
script:
|
||
- id: yambms${yambms_id}_script_eoc_timer
|
||
then:
|
||
- delay: ${yambms_eoc_timer}min
|
||
- script.execute: yambms${yambms_id}_script_eoc
|
||
- id: yambms${yambms_id}_script_cutoff_timer
|
||
then:
|
||
- delay: ${yambms_cutoff_timer}s
|
||
- script.execute: yambms${yambms_id}_script_eoc
|
||
- id: yambms${yambms_id}_script_eoc
|
||
then:
|
||
- lambda: |-
|
||
// Stop timer
|
||
if (id(yambms${yambms_id}_script_eoc_timer).is_running()) id(yambms${yambms_id}_script_eoc_timer).stop();
|
||
if (id(yambms${yambms_id}_script_cutoff_timer).is_running()) id(yambms${yambms_id}_script_cutoff_timer).stop();
|
||
// EOC script
|
||
if (id(yambms${yambms_id}_switch_float).state) id(yambms${yambms_id}_var_charge_status) = "Float";
|
||
else id(yambms${yambms_id}_var_charge_status) = "EOC";
|
||
id(yambms${yambms_id}_var_eoc) = true; // SOC 100% can be sent
|
||
id(yambms${yambms_id}_var_eoc_timestamp) = id(my_time).utcnow().timestamp; // Store charge completion timestamp
|
||
id(yambms${yambms_id}_var_rebulk_days_active) = false; // Rebulk after N days logic reset
|
||
|
||
|
||
|
||
# +--------------------------------------+
|
||
# | select |
|
||
# +--------------------------------------+
|
||
select:
|
||
# Cut-Off cell voltage source
|
||
# "Max cell" (default) : conservative, the EOC depends on the highest cell.
|
||
# "Average cell" : consistent charge termination voltage. Recommended for packs
|
||
# with unmatched cells (different IRs), a runner cell, or a BMS that does not
|
||
# report its equalizing status. Requires Auto CVL and/or Auto CCL enabled
|
||
# (the runner cell no longer stops the charge).
|
||
- platform: template
|
||
name: "Cut-Off Cell Voltage"
|
||
id: yambms${yambms_id}_select_cutoff_cell_voltage
|
||
device_id: yambms_yambms${yambms_id}
|
||
options:
|
||
- "Max Cell Voltage"
|
||
- "Average Cell Voltage"
|
||
initial_option: "Max Cell Voltage"
|
||
restore_value: true
|
||
optimistic: true
|
||
icon: mdi:vector-difference
|
||
entity_category: config
|
||
|
||
# +--------------------------------------+
|
||
# | switch |
|
||
# +--------------------------------------+
|
||
switch:
|
||
- platform: template
|
||
name: "Charge enabled"
|
||
id: yambms${yambms_id}_switch_charging
|
||
device_id: yambms_yambms${yambms_id}
|
||
restore_mode: RESTORE_DEFAULT_ON
|
||
optimistic: true
|
||
entity_category: config
|
||
- platform: template
|
||
name: "Discharge enabled"
|
||
id: yambms${yambms_id}_switch_discharging
|
||
device_id: yambms_yambms${yambms_id}
|
||
restore_mode: RESTORE_DEFAULT_ON
|
||
optimistic: true
|
||
entity_category: config
|
||
- platform: template
|
||
name: "Float charge enabled"
|
||
id: yambms${yambms_id}_switch_float
|
||
device_id: yambms_yambms${yambms_id}
|
||
restore_mode: RESTORE_DEFAULT_ON
|
||
optimistic: true
|
||
entity_category: config
|
||
- platform: template
|
||
name: "EOC Timer enabled"
|
||
id: yambms${yambms_id}_switch_eoc_timer
|
||
device_id: yambms_yambms${yambms_id}
|
||
restore_mode: RESTORE_DEFAULT_ON
|
||
optimistic: true
|
||
entity_category: config
|
||
- platform: template
|
||
name: "Force Bulk"
|
||
id: yambms${yambms_id}_switch_force_bulk
|
||
device_id: yambms_yambms${yambms_id}
|
||
restore_mode: RESTORE_DEFAULT_OFF
|
||
optimistic: true
|
||
entity_category: config
|
||
- platform: template
|
||
name: "Request force charge"
|
||
id: yambms${yambms_id}_switch_request_force_charge
|
||
device_id: yambms_yambms${yambms_id}
|
||
restore_mode: RESTORE_DEFAULT_OFF
|
||
optimistic: true
|
||
entity_category: config
|
||
|
||
# +--------------------------------------+
|
||
# | binary_sensor |
|
||
# +--------------------------------------+
|
||
binary_sensor:
|
||
# Equalizing
|
||
- platform: template
|
||
id: yambms${yambms_id}_equalizing
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Equalizing state"
|
||
trigger_on_initial_state: true
|
||
# Charging allowed
|
||
- platform: template
|
||
id: yambms${yambms_id}_charging_allowed
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Charging allowed"
|
||
trigger_on_initial_state: true
|
||
# Discharging allowed
|
||
- platform: template
|
||
id: yambms${yambms_id}_discharging_allowed
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Discharging allowed"
|
||
trigger_on_initial_state: true
|
||
# Inverter communication status (CANBUS / RS485)
|
||
- platform: template
|
||
name: "Inverter communication status"
|
||
id: inverter_com_status
|
||
device_id: yambms_yambms${yambms_id}
|
||
entity_category: diagnostic
|
||
trigger_on_initial_state: true
|
||
# +--------------------------------------+
|
||
# | Discharging Instruction |
|
||
# +--------------------------------------+
|
||
- platform: template
|
||
name: "Discharging Instruction"
|
||
id: yambms${yambms_id}_discharging_instruction
|
||
device_id: yambms_yambms${yambms_id}
|
||
icon: mdi:battery-minus
|
||
trigger_on_initial_state: true
|
||
# +--------------------------------------+
|
||
# | Requested Force Charge |
|
||
# +--------------------------------------+
|
||
- platform: template
|
||
name: "Requested Force Charge"
|
||
id: yambms${yambms_id}_requested_force_charge
|
||
device_id: yambms_yambms${yambms_id}
|
||
icon: mdi:battery-charging-low
|
||
trigger_on_initial_state: true
|
||
lambda: |-
|
||
if (id(yambms${yambms_id}_switch_request_force_charge).state)
|
||
{
|
||
int soc = id(yambms${yambms_id}_battery_soc).state;
|
||
if (soc <= id(yambms${yambms_id}_request_force_charge_start_soc).state) return true;
|
||
else if (soc >= id(yambms${yambms_id}_request_force_charge_stop_soc).state) return false;
|
||
else if (id(yambms${yambms_id}_requested_force_charge).state) return true;
|
||
else return false;
|
||
}
|
||
else return false;
|
||
|
||
# +--------------------------------------+
|
||
# | number |
|
||
# +--------------------------------------+
|
||
number:
|
||
|
||
#
|
||
# Min/max values ​​are updated automatically based on battery chemistry and cell count.
|
||
#
|
||
|
||
# Bulk voltage
|
||
- platform: template
|
||
name: "Bulk voltage"
|
||
id: yambms${yambms_id}_bulk_voltage
|
||
device_id: yambms_yambms${yambms_id}
|
||
step: 0.1
|
||
min_value: 54.0 # LFP 3.37 * 16 cells
|
||
max_value: 58.4 # LFP 3.65 * 16 cells
|
||
restore_value: true
|
||
mode: "${yambms_input_number_mode}"
|
||
initial_value: "${yambms_bulk_v}"
|
||
unit_of_measurement: V
|
||
device_class: voltage
|
||
icon: mdi:battery-charging
|
||
optimistic: true
|
||
entity_category: config
|
||
# Float voltage
|
||
- platform: template
|
||
name: "Float voltage"
|
||
id: yambms${yambms_id}_float_voltage
|
||
device_id: yambms_yambms${yambms_id}
|
||
step: 0.1
|
||
min_value: 52.8 # LFP 3.30 * 16 cells
|
||
max_value: 55.2 # LFP 3.45 * 16 cells
|
||
restore_value: true
|
||
mode: "${yambms_input_number_mode}"
|
||
initial_value: "${yambms_float_v}"
|
||
unit_of_measurement: V
|
||
device_class: voltage
|
||
icon: mdi:battery-charging
|
||
optimistic: true
|
||
entity_category: config
|
||
# Rebulk Voltage
|
||
- platform: template
|
||
name: "Rebulk V."
|
||
id: yambms${yambms_id}_rebulk_voltage
|
||
device_id: yambms_yambms${yambms_id}
|
||
step: 0.1
|
||
min_value: 51.2 # LFP 3.20 * 16 cells
|
||
max_value: 54.0 # LFP 3.37 * 16 cells
|
||
restore_value: true
|
||
mode: "${yambms_input_number_mode}"
|
||
initial_value: "${yambms_rebulk_v}"
|
||
unit_of_measurement: V
|
||
device_class: voltage
|
||
icon: mdi:sine-wave
|
||
optimistic: true
|
||
entity_category: config
|
||
# Rebulk SoC
|
||
- platform: template
|
||
name: "Rebulk SoC"
|
||
id: yambms${yambms_id}_rebulk_soc
|
||
device_id: yambms_yambms${yambms_id}
|
||
step: 1
|
||
min_value: 0
|
||
max_value: 100
|
||
restore_value: true
|
||
mode: "${yambms_input_number_mode}"
|
||
initial_value: 85
|
||
unit_of_measurement: '%'
|
||
icon: mdi:battery-medium
|
||
optimistic: true
|
||
entity_category: config
|
||
# Rebulk Days
|
||
- platform: template
|
||
name: "Rebulk Days"
|
||
id: yambms${yambms_id}_rebulk_days
|
||
device_id: yambms_yambms${yambms_id}
|
||
step: 1
|
||
min_value: 0
|
||
max_value: 30
|
||
restore_value: true
|
||
mode: "${yambms_input_number_mode}"
|
||
initial_value: 14
|
||
unit_of_measurement: days
|
||
icon: mdi:calendar-refresh
|
||
optimistic: true
|
||
entity_category: config
|
||
on_value:
|
||
then:
|
||
- lambda: id(yambms${yambms_id}_var_rebulk_days_active) = false;
|
||
# Charger Offset V.
|
||
- platform: template
|
||
name: "Charger Offset V."
|
||
id: yambms${yambms_id}_charger_offset_v
|
||
device_id: yambms_yambms${yambms_id}
|
||
step: 0.1
|
||
min_value: -1
|
||
max_value: 1
|
||
restore_value: true
|
||
mode: "${yambms_input_number_mode}"
|
||
initial_value: 0.0
|
||
unit_of_measurement: V
|
||
device_class: voltage
|
||
icon: mdi:sine-wave
|
||
optimistic: true
|
||
entity_category: config
|
||
# Max requested charge current
|
||
- platform: template
|
||
name: "Max requested charge current"
|
||
id: yambms${yambms_id}_max_requested_charge_current
|
||
device_id: yambms_yambms${yambms_id}
|
||
step: 5
|
||
min_value: 0
|
||
max_value: ${yambms_max_requested_charge_current}
|
||
restore_value: true
|
||
mode: "${yambms_input_number_mode}"
|
||
initial_value: ${yambms_max_requested_charge_current}
|
||
unit_of_measurement: A
|
||
device_class: current
|
||
icon: mdi:current-dc
|
||
optimistic: true
|
||
entity_category: config
|
||
# Max requested discharge current
|
||
- platform: template
|
||
name: "Max requested discharge current"
|
||
id: yambms${yambms_id}_max_requested_discharge_current
|
||
device_id: yambms_yambms${yambms_id}
|
||
step: 5
|
||
min_value: 0
|
||
max_value: ${yambms_max_requested_discharge_current}
|
||
restore_value: true
|
||
mode: "${yambms_input_number_mode}"
|
||
initial_value: ${yambms_max_requested_discharge_current}
|
||
unit_of_measurement: A
|
||
device_class: current
|
||
icon: mdi:current-dc
|
||
optimistic: true
|
||
entity_category: config
|
||
# Max. Continuous Charging Power / Standard Charging Power
|
||
# EVE LF280K V3 = 1P / 0.5P
|
||
# EVE MB31 = 0.5P / 0.5P
|
||
- platform: template
|
||
name: "Max charge C-Rate"
|
||
id: yambms${yambms_id}_max_charge_crate
|
||
device_id: yambms_yambms${yambms_id}
|
||
step: 0.05
|
||
min_value: 0.05
|
||
max_value: 1
|
||
restore_value: true
|
||
mode: "${yambms_input_number_mode}"
|
||
initial_value: 0.5
|
||
unit_of_measurement: C
|
||
icon: mdi:battery-charging
|
||
optimistic: true
|
||
entity_category: config
|
||
# Max. Continuous Discharging Power / Standard Discharging Power
|
||
# EVE LF280K V3 = 1P / 0.5P
|
||
# EVE MB31 = 0.5P / 0.5P
|
||
- platform: template
|
||
name: "Max discharge C-Rate"
|
||
id: yambms${yambms_id}_max_discharge_crate
|
||
device_id: yambms_yambms${yambms_id}
|
||
step: 0.05
|
||
min_value: 0.05
|
||
max_value: 1
|
||
restore_value: true
|
||
mode: "${yambms_input_number_mode}"
|
||
initial_value: 0.5
|
||
unit_of_measurement: C
|
||
icon: mdi:battery-minus
|
||
optimistic: true
|
||
entity_category: config
|
||
# Request Force Charge Start SoC
|
||
- platform: template
|
||
name: "Request Force Charge Start SoC"
|
||
id: yambms${yambms_id}_request_force_charge_start_soc
|
||
device_id: yambms_yambms${yambms_id}
|
||
step: 1
|
||
min_value: 0
|
||
max_value: 100
|
||
restore_value: true
|
||
mode: "${yambms_input_number_mode}"
|
||
initial_value: 10
|
||
unit_of_measurement: '%'
|
||
icon: mdi:battery-low
|
||
optimistic: true
|
||
entity_category: config
|
||
# Request Force Charge Stop SoC
|
||
- platform: template
|
||
name: "Request Force Charge Stop SoC"
|
||
id: yambms${yambms_id}_request_force_charge_stop_soc
|
||
device_id: yambms_yambms${yambms_id}
|
||
step: 1
|
||
min_value: 0
|
||
max_value: 100
|
||
restore_value: true
|
||
mode: "${yambms_input_number_mode}"
|
||
initial_value: 30
|
||
unit_of_measurement: '%'
|
||
icon: mdi:battery-medium
|
||
optimistic: true
|
||
entity_category: config
|
||
|
||
|
||
|
||
# +--------------------------------------+
|
||
# | sensor |
|
||
# +--------------------------------------+
|
||
sensor:
|
||
# max_charge_current SUM
|
||
- platform: template
|
||
id: yambms${yambms_id}_max_charge_current
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Max Charge current"
|
||
update_interval: never
|
||
unit_of_measurement: A
|
||
device_class: current
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
# Control path: read back by the Auto CCL functions and by STEP 3
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# max_discharge_current SUM
|
||
- platform: template
|
||
id: yambms${yambms_id}_max_discharge_current
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Max Discharge Current"
|
||
update_interval: never
|
||
unit_of_measurement: A
|
||
device_class: current
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
# Control path: read back by the Auto DCL functions and by STEP 3
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# cell_count
|
||
- platform: template
|
||
name: "Cell Count"
|
||
id: yambms${yambms_id}_cell_count
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: ${yambms_update_interval}
|
||
icon: mdi:counter
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
lambda: return ${yambms_cell_count};
|
||
|
||
# min_voltage_cell MIN
|
||
- platform: template
|
||
id: yambms${yambms_id}_min_voltage_cell
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Min Voltage Cell"
|
||
update_interval: never
|
||
icon: mdi:numeric
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# max_voltage_cell MAX
|
||
- platform: template
|
||
id: yambms${yambms_id}_max_voltage_cell
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Max Voltage Cell"
|
||
update_interval: never
|
||
icon: mdi:numeric
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# min_cell_voltage MIN
|
||
- platform: template
|
||
id: yambms${yambms_id}_min_cell_voltage
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Min Cell Voltage"
|
||
update_interval: never
|
||
unit_of_measurement: V
|
||
device_class: voltage
|
||
state_class: measurement
|
||
accuracy_decimals: 3
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 0.001f;
|
||
${rate_limit_filter}
|
||
|
||
# max_cell_voltage MAX
|
||
- platform: template
|
||
id: yambms${yambms_id}_max_cell_voltage
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Max Cell Voltage"
|
||
update_interval: never
|
||
unit_of_measurement: V
|
||
device_class: voltage
|
||
state_class: measurement
|
||
accuracy_decimals: 3
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 0.001f;
|
||
${rate_limit_filter}
|
||
|
||
# delta_cell_voltage
|
||
- platform: template
|
||
id: yambms${yambms_id}_delta_cell_voltage
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Delta Cell Voltage"
|
||
update_interval: never
|
||
unit_of_measurement: V
|
||
device_class: voltage
|
||
state_class: measurement
|
||
accuracy_decimals: 3
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 0.001f;
|
||
${rate_limit_filter}
|
||
|
||
# total_voltage MEAN
|
||
- platform: template
|
||
id: yambms${yambms_id}_total_voltage
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Total Voltage"
|
||
update_interval: never
|
||
unit_of_measurement: V
|
||
device_class: voltage
|
||
state_class: measurement
|
||
accuracy_decimals: 2
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 0.01f;
|
||
${rate_limit_filter}
|
||
|
||
# current SUM
|
||
- platform: template
|
||
id: yambms${yambms_id}_current
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Current"
|
||
update_interval: never
|
||
unit_of_measurement: A
|
||
device_class: current
|
||
state_class: measurement
|
||
accuracy_decimals: 1
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 0.1f;
|
||
${rate_limit_filter}
|
||
|
||
# power SUM
|
||
- platform: template
|
||
id: yambms${yambms_id}_power
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Power"
|
||
update_interval: never
|
||
unit_of_measurement: W
|
||
device_class: power
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# battery_soc MEAN
|
||
- platform: template
|
||
name: "Battery SoC"
|
||
id: yambms${yambms_id}_battery_soc
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: never
|
||
unit_of_measurement: "%"
|
||
device_class: battery
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# battery_soh MEAN
|
||
- platform: template
|
||
id: yambms${yambms_id}_battery_soh
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Battery SoH"
|
||
update_interval: never
|
||
unit_of_measurement: "%"
|
||
state_class: measurement
|
||
icon: mdi:battery-heart-variant
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# installed_battery_capacity SUM
|
||
- platform: template
|
||
id: yambms${yambms_id}_installed_battery_capacity
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Installed Battery Capacity"
|
||
update_interval: ${yambms_update_interval}
|
||
unit_of_measurement: Ah
|
||
state_class: measurement
|
||
icon: mdi:car-battery
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
lambda: return id(yambms${yambms_id}_var_total_installed_battery_capacity);
|
||
|
||
# battery_capacity SUM
|
||
- platform: template
|
||
id: yambms${yambms_id}_battery_capacity
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Battery Capacity"
|
||
update_interval: never
|
||
unit_of_measurement: Ah
|
||
state_class: measurement
|
||
icon: mdi:car-battery
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# battery_capacity_remaining SUM
|
||
- platform: template
|
||
id: yambms${yambms_id}_battery_capacity_remaining
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Capacity Remaining"
|
||
update_interval: never
|
||
unit_of_measurement: Ah
|
||
state_class: measurement
|
||
icon: mdi:car-battery
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# cell_ovp MIN (Auto CCL)
|
||
- platform: template
|
||
id: yambms${yambms_id}_cell_ovp
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Cell OVP (MIN)"
|
||
update_interval: never
|
||
unit_of_measurement: V
|
||
device_class: voltage
|
||
state_class: measurement
|
||
accuracy_decimals: 3
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 0.001f;
|
||
${rate_limit_filter}
|
||
|
||
# cell_uvp MAX (Auto DCL and MAX Discharge Voltage)
|
||
- platform: template
|
||
id: yambms${yambms_id}_cell_uvp
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Cell UVP (MAX)"
|
||
update_interval: never
|
||
unit_of_measurement: V
|
||
device_class: voltage
|
||
state_class: measurement
|
||
accuracy_decimals: 3
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 0.001f;
|
||
${rate_limit_filter}
|
||
|
||
# balance_trigger_voltage MAX (Auto CVL)
|
||
- platform: template
|
||
id: yambms${yambms_id}_balance_trigger_voltage
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Balance Trigger Voltage (MAX)"
|
||
update_interval: never
|
||
unit_of_measurement: V
|
||
device_class: voltage
|
||
state_class: measurement
|
||
accuracy_decimals: 3
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 0.001f;
|
||
${rate_limit_filter}
|
||
|
||
# MIN temperature
|
||
- platform: template
|
||
id: yambms${yambms_id}_min_temperature
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Min temperature"
|
||
update_interval: never
|
||
unit_of_measurement: °C
|
||
device_class: temperature
|
||
state_class: measurement
|
||
accuracy_decimals: 1
|
||
filters:
|
||
# 0.2 °C step, the built-in delta filter cannot be used here because
|
||
# it rejects NAN, which must be published when no BMS is combined
|
||
- lambda: |-
|
||
static float last = NAN;
|
||
if (std::isnan(x))
|
||
{
|
||
if (std::isnan(last)) return {};
|
||
last = NAN;
|
||
return x;
|
||
}
|
||
if (std::isnan(last) || fabsf(x - last) > 0.2f)
|
||
{
|
||
last = x;
|
||
return x;
|
||
}
|
||
return {};
|
||
|
||
# MIN temperature sensor
|
||
- platform: template
|
||
id: yambms${yambms_id}_min_temperature_sensor
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Min temperature sensor"
|
||
update_interval: never
|
||
icon: mdi:numeric
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# MAX temperature
|
||
- platform: template
|
||
id: yambms${yambms_id}_max_temperature
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Max temperature"
|
||
update_interval: never
|
||
unit_of_measurement: °C
|
||
device_class: temperature
|
||
state_class: measurement
|
||
accuracy_decimals: 1
|
||
filters:
|
||
# 0.2 °C step, the built-in delta filter cannot be used here because
|
||
# it rejects NAN, which must be published when no BMS is combined
|
||
- lambda: |-
|
||
static float last = NAN;
|
||
if (std::isnan(x))
|
||
{
|
||
if (std::isnan(last)) return {};
|
||
last = NAN;
|
||
return x;
|
||
}
|
||
if (std::isnan(last) || fabsf(x - last) > 0.2f)
|
||
{
|
||
last = x;
|
||
return x;
|
||
}
|
||
return {};
|
||
|
||
# MAX temperature sensor
|
||
- platform: template
|
||
id: yambms${yambms_id}_max_temperature_sensor
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Max temperature sensor"
|
||
update_interval: never
|
||
icon: mdi:numeric
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# charging_cycles MEAN
|
||
- platform: template
|
||
id: yambms${yambms_id}_charging_cycles
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Charging Cycles"
|
||
update_interval: never
|
||
icon: mdi:counter
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# Alarm - errors_bitmask bitwise AND (16bit)
|
||
- platform: template
|
||
id: yambms${yambms_id}_errors_bitmask_alarm
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Errors Bitmask Alarm"
|
||
update_interval: never
|
||
icon: mdi:alert-circle-outline
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# Warning - errors_bitmask bitwise OR (16bit)
|
||
- platform: template
|
||
id: yambms${yambms_id}_errors_bitmask_warning
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "Errors Bitmask Warning"
|
||
update_interval: never
|
||
icon: mdi:alert-circle-outline
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# BMS in alarm (errors_bitmask_counter)
|
||
- platform: template
|
||
id: yambms${yambms_id}_errors_bitmask_counter
|
||
device_id: yambms_yambms${yambms_id}
|
||
name: "BMS in alarm"
|
||
update_interval: never
|
||
icon: mdi:counter
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# BMS count
|
||
- platform: template
|
||
name: "BMS count"
|
||
id: yambms${yambms_id}_bms_count
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: never
|
||
icon: mdi:counter
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# BMS combined
|
||
- platform: template
|
||
name: "BMS combined"
|
||
id: yambms${yambms_id}_bms_combined
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: never
|
||
icon: mdi:counter
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# BMS blocking charge
|
||
- platform: template
|
||
name: "BMS blocking charge"
|
||
id: yambms${yambms_id}_bms_blocking_charge
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: never
|
||
icon: mdi:counter
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# BMS blocking discharge
|
||
- platform: template
|
||
name: "BMS blocking discharge"
|
||
id: yambms${yambms_id}_bms_blocking_discharge
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: never
|
||
icon: mdi:counter
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# Shunt count
|
||
- platform: template
|
||
name: "Shunt count"
|
||
id: yambms${yambms_id}_shunt_count
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: never
|
||
icon: mdi:counter
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# Shunt combined
|
||
- platform: template
|
||
name: "Shunt combined"
|
||
id: yambms${yambms_id}_shunt_combined
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: never
|
||
icon: mdi:counter
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
|
||
# Battery Charging Power
|
||
- platform: template
|
||
name: "Battery Charging Power"
|
||
id: yambms${yambms_id}_battery_charging_power
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: never
|
||
unit_of_measurement: 'W'
|
||
device_class: power
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
|
||
# Battery Discharging Power
|
||
- platform: template
|
||
name: "Battery Discharging Power"
|
||
id: yambms${yambms_id}_battery_discharging_power
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: never
|
||
unit_of_measurement: 'W'
|
||
device_class: power
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
|
||
# Daily Charging Energy
|
||
- platform: total_daily_energy
|
||
name: "Daily Charging Energy"
|
||
device_id: yambms_yambms${yambms_id}
|
||
power_id: yambms${yambms_id}_battery_charging_power
|
||
unit_of_measurement: 'kWh'
|
||
device_class: energy
|
||
state_class: total_increasing
|
||
accuracy_decimals: 3
|
||
filters:
|
||
# Multiplication factor from W to kW is 0.001
|
||
- multiply: 0.001
|
||
|
||
# Daily Discharging Energy
|
||
- platform: total_daily_energy
|
||
name: "Daily Discharging Energy"
|
||
device_id: yambms_yambms${yambms_id}
|
||
power_id: yambms${yambms_id}_battery_discharging_power
|
||
unit_of_measurement: 'kWh'
|
||
device_class: energy
|
||
state_class: total_increasing
|
||
accuracy_decimals: 3
|
||
filters:
|
||
# Multiplication factor from W to kW is 0.001
|
||
- multiply: 0.001
|
||
|
||
# +--------------------------------------+
|
||
# | Requested Charge Voltage (CVL) |
|
||
# +--------------------------------------+
|
||
- platform: template
|
||
name: "Requested Charge Voltage"
|
||
id: yambms${yambms_id}_requested_charge_voltage
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: never
|
||
unit_of_measurement: V
|
||
device_class: voltage
|
||
state_class: measurement
|
||
accuracy_decimals: 1
|
||
# Control path: sent to the inverter
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 0.1f;
|
||
${rate_limit_filter}
|
||
|
||
# +--------------------------------------+
|
||
# | Requested Discharge Voltage (DVL) |
|
||
# +--------------------------------------+
|
||
- platform: template
|
||
name: "Requested Discharge Voltage"
|
||
id: yambms${yambms_id}_requested_discharge_voltage
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: never
|
||
unit_of_measurement: V
|
||
device_class: voltage
|
||
state_class: measurement
|
||
accuracy_decimals: 1
|
||
# Control path: sent to the inverter
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 0.1f;
|
||
${rate_limit_filter}
|
||
|
||
# +--------------------------------------+
|
||
# | Requested Charge Current (CCL) |
|
||
# +--------------------------------------+
|
||
- platform: template
|
||
name: "Requested Charge Current"
|
||
id: yambms${yambms_id}_requested_charge_current
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: never
|
||
unit_of_measurement: A
|
||
device_class: current
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
# Control path: sent to the inverter
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
# No on_value update of the derating reason here: this fires after STEP 3 has
|
||
# reset the auto vars. The reason is updated from STEP 3, before that reset.
|
||
|
||
# +--------------------------------------+
|
||
# | Requested Discharge Current (DCL) |
|
||
# +--------------------------------------+
|
||
- platform: template
|
||
name: "Requested Discharge Current"
|
||
id: yambms${yambms_id}_requested_discharge_current
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: never
|
||
unit_of_measurement: A
|
||
device_class: current
|
||
state_class: measurement
|
||
accuracy_decimals: 0
|
||
# Control path: sent to the inverter
|
||
filters:
|
||
- lambda: |-
|
||
const float delta = 1.0f;
|
||
${rate_limit_filter}
|
||
# No on_value update of the derating reason here: this fires after STEP 3 has
|
||
# reset the auto vars. The reason is updated from STEP 3, before that reset.
|
||
|
||
# +--------------------------------------+
|
||
# | Last Complete Charge |
|
||
# +--------------------------------------+
|
||
- platform: template
|
||
name: "Last Complete Charge Timestamp"
|
||
id: yambms${yambms_id}_eoc_timestamp_template
|
||
device_id: yambms_yambms${yambms_id}
|
||
device_class: timestamp
|
||
entity_category: diagnostic
|
||
internal: true
|
||
lambda: return id(yambms${yambms_id}_var_eoc_timestamp);
|
||
on_value:
|
||
then:
|
||
- text_sensor.template.publish:
|
||
id: yambms${yambms_id}_eoc_timestamp_human
|
||
state: !lambda |-
|
||
char str[19];
|
||
strftime(str, sizeof(str), " %H:%M %d %b %Y", localtime(&id(yambms${yambms_id}_var_eoc_timestamp)));
|
||
return {str};
|
||
|
||
|
||
|
||
text_sensor:
|
||
# +--------------------------------------+
|
||
# | Combiner Stall |
|
||
# +--------------------------------------+
|
||
- platform: template
|
||
name: "Combiner Stall"
|
||
id: yambms${yambms_id}_combiner_stall_reason
|
||
device_id: yambms_yambms${yambms_id}
|
||
icon: mdi:sync-alert
|
||
entity_category: diagnostic
|
||
update_interval: never
|
||
# +--------------------------------------+
|
||
# | Charging Instruction |
|
||
# +--------------------------------------+
|
||
- platform: template
|
||
name: "Charging Instruction"
|
||
id: yambms${yambms_id}_charging_instruction
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: never
|
||
icon: mdi:battery-plus
|
||
# +--------------------------------------+
|
||
# | Last Complete Charge |
|
||
# +--------------------------------------+
|
||
- platform: template
|
||
name: "Last Complete Charge"
|
||
id: yambms${yambms_id}_eoc_timestamp_human
|
||
device_id: yambms_yambms${yambms_id}
|
||
icon: mdi:clock-start
|
||
entity_category: diagnostic
|
||
# +--------------------------------------+
|
||
# | ****** Cut-off Charging Logic ****** |
|
||
# | ********* Charging Status ********* |
|
||
# +--------------------------------------+
|
||
- platform: template
|
||
name: "Charging Status"
|
||
id: yambms${yambms_id}_charging_status
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: never
|
||
icon: mdi:battery-arrow-up
|
||
|
||
# +--------------------------------------+
|
||
# | YamBMS Errors Bitmask (16bit) |
|
||
# +--------------------------------------+
|
||
|
||
# Bit 0 General alarm 0000 0000 0000 0001 0x0001
|
||
# Bit 1 Battery high voltage alarm 0000 0000 0000 0010 0x0002
|
||
# Bit 2 Battery low voltage alarm 0000 0000 0000 0100 0x0004
|
||
# Bit 3 Battery high temperature alarm 0000 0000 0000 1000 0x0008
|
||
# Bit 4 Battery low temperature alarm 0000 0000 0001 0000 0x0010
|
||
# Bit 5 Battery high temperature charge alarm 0000 0000 0010 0000 0x0020
|
||
# Bit 6 Battery low temperature charge alarm 0000 0000 0100 0000 0x0040
|
||
# Bit 7 Battery high discharge current alarm 0000 0000 1000 0000 0x0080
|
||
# Bit 8 Battery high charge current alarm 0000 0001 0000 0000 0x0100
|
||
# Bit 9 Contactor alarm 0000 0010 0000 0000 0x0200
|
||
# Bit 10 Short circuit alarm 0000 0100 0000 0000 0x0400
|
||
# Bit 11 BMS internal alarm 0000 1000 0000 0000 0x0800
|
||
# Bit 12 Cell imbalance alarm 0001 0000 0000 0000 0x1000
|
||
# Bit 13 Reserved 0010 0000 0000 0000 0x2000
|
||
# Bit 14 Reserved 0100 0000 0000 0000 0x4000
|
||
# Bit 15 Reserved 1000 0000 0000 0000 0x8000
|
||
|
||
# YamBMS Protection Alarm (all-bms)
|
||
- platform: template
|
||
name: "Alarm"
|
||
id: yambms${yambms_id}_alarm
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: ${yambms_update_interval}
|
||
entity_category: diagnostic
|
||
icon: mdi:battery-alert
|
||
lambda: |-
|
||
// Error Bitmask ?
|
||
uint16_t errors_bitmask = id(yambms${yambms_id}_errors_bitmask_alarm).state;
|
||
int eb_counter = id(yambms${yambms_id}_errors_bitmask_counter).state;
|
||
|
||
// At least one BMS in alarm
|
||
if ((eb_counter > 0) && (eb_counter < id(yambms${yambms_id}_var_bms_counter))) return {"Warning"};
|
||
// All BMS are in alarm
|
||
else if (errors_bitmask > 0)
|
||
{
|
||
if ((errors_bitmask & 0x0002)) return {"OVP"}; // Over Voltage Protection
|
||
else if ((errors_bitmask & 0x0004)) return {"UVP"}; // Under Voltage Protection
|
||
else if ((errors_bitmask & 0x0008)) return {"OTP"}; // Over Temp Protection
|
||
else if ((errors_bitmask & 0x0020)) return {"COTP"}; // Charge Over Temp Protection
|
||
else if ((errors_bitmask & 0x0010)) return {"UTP"}; // Under Temp Protection
|
||
else if ((errors_bitmask & 0x0040)) return {"CUTP"}; // Charge Under Temp Protection
|
||
else if ((errors_bitmask & 0x0080)) return {"DOCP"}; // Discharge Over Current Protection
|
||
else if ((errors_bitmask & 0x0100)) return {"COCP"}; // Charge Over Current Protection
|
||
else if ((errors_bitmask & 0x0400)) return {"SCP"}; // Short Circuit Protection
|
||
else if ((errors_bitmask & 0x0800)) return {"BMS"}; // BMS Internal Alarm
|
||
else if ((errors_bitmask & 0x1000)) return {"UBC"}; // Unbalanced Cell
|
||
else return {"Alarm"};
|
||
}
|
||
// No Alarm
|
||
else return {"NoAlarm"};
|
||
|
||
# YamBMS Warning (one-bms)
|
||
- platform: template
|
||
name: "Warning"
|
||
id: yambms${yambms_id}_warning
|
||
device_id: yambms_yambms${yambms_id}
|
||
update_interval: ${yambms_update_interval}
|
||
entity_category: diagnostic
|
||
icon: mdi:battery-alert
|
||
lambda: |-
|
||
// Error Bitmask ?
|
||
uint16_t errors_bitmask = id(yambms${yambms_id}_errors_bitmask_warning).state;
|
||
|
||
if (errors_bitmask > 0)
|
||
{
|
||
if ((errors_bitmask & 0x0002)) return {"OVP"}; // Over Voltage Protection
|
||
else if ((errors_bitmask & 0x0004)) return {"UVP"}; // Under Voltage Protection
|
||
else if ((errors_bitmask & 0x0008)) return {"OTP"}; // Over Temp Protection
|
||
else if ((errors_bitmask & 0x0020)) return {"COTP"}; // Charge Over Temp Protection
|
||
else if ((errors_bitmask & 0x0010)) return {"UTP"}; // Under Temp Protection
|
||
else if ((errors_bitmask & 0x0040)) return {"CUTP"}; // Charge Under Temp Protection
|
||
else if ((errors_bitmask & 0x0080)) return {"DOCP"}; // Discharge Over Current Protection
|
||
else if ((errors_bitmask & 0x0100)) return {"COCP"}; // Charge Over Current Protection
|
||
else if ((errors_bitmask & 0x0400)) return {"SCP"}; // Short Circuit Protection
|
||
else if ((errors_bitmask & 0x0800)) return {"BMS"}; // BMS Internal Alarm
|
||
else if ((errors_bitmask & 0x1000)) return {"UBC"}; // Unbalanced Cell
|
||
else return {"Alarm"};
|
||
}
|
||
// No Alarm
|
||
else return {"NoAlarm"};
|
||
|
||
# +----------------------------------------+
|
||
# | Charge Current Derating Reason |
|
||
# +----------------------------------------+
|
||
- platform: template
|
||
name: "CCL Derating Reason"
|
||
id: yambms${yambms_id}_ccl_derating_reason
|
||
device_id: yambms_yambms${yambms_id}
|
||
icon: "mdi:information-outline"
|
||
update_interval: never
|
||
entity_category: diagnostic
|
||
lambda: |-
|
||
|
||
float limit_1 = id(yambms${yambms_id}_var_auto_temperature_ccl);
|
||
float limit_2 = id(yambms${yambms_id}_var_auto_ccl);
|
||
float limit_3 = id(yambms${yambms_id}_var_auto_ccl_current_taper);
|
||
float limit_4 = id(yambms${yambms_id}_var_auto_soc_limit);
|
||
float limit_5 = id(yambms${yambms_id}_var_auto_eoc);
|
||
float limit_6 = id(yambms${yambms_id}_var_auto_custom_ccl);
|
||
|
||
float min_val = std::min({limit_1, limit_2, limit_3, limit_4, limit_5, limit_6});
|
||
|
||
if (min_val == 0.0f) return {"No Derating"};
|
||
if (min_val == limit_1) return {"Temperature Derating"};
|
||
if (min_val == limit_2) return {"Auto CCL Derating"};
|
||
if (min_val == limit_3) return {"Current Taper Derating"};
|
||
if (min_val == limit_4) return {"SoC Limit Derating"};
|
||
if (min_val == limit_5) return {"EOC Derating"};
|
||
if (min_val == limit_6) return {"${yambms_custom_ccl_derating_reason}"};
|
||
return {"Unknown"};
|
||
|
||
# +----------------------------------------+
|
||
# | Discharge Current Derating Reason |
|
||
# +----------------------------------------+
|
||
- platform: template
|
||
name: "DCL Derating Reason"
|
||
id: yambms${yambms_id}_dcl_derating_reason
|
||
device_id: yambms_yambms${yambms_id}
|
||
icon: "mdi:information-outline"
|
||
update_interval: never
|
||
entity_category: diagnostic
|
||
lambda: |-
|
||
float limit_1 = id(yambms${yambms_id}_var_auto_temperature_dcl);
|
||
float limit_2 = id(yambms${yambms_id}_var_auto_dcl);
|
||
float limit_3 = id(yambms${yambms_id}_var_auto_custom_dcl);
|
||
|
||
float min_val = std::min({limit_1, limit_2, limit_3});
|
||
|
||
if (min_val == 0.0f) return {"No Derating"};
|
||
if (min_val == limit_1) return {"Temperature Derating"};
|
||
if (min_val == limit_2) return {"Auto DCL Derating"};
|
||
if (min_val == limit_3) return {"${yambms_custom_dcl_derating_reason}"};
|
||
return {"Unknown"};
|