This adds 'yambms_max_inverter_charge_current' and 'yambms_max_inverter_discharge_current' substitutions. They are used to restrict the range of the charge/discharge current for easier control when the battery currents are much higher than the inverter currents.
205 lines
8.9 KiB
YAML
205 lines
8.9 KiB
YAML
# Updated : 2025.07.10
|
|
# Version : 1.5.8
|
|
# GitHub : https://github.com/Sleeper85/esphome-yambms
|
|
|
|
# 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>.
|
|
|
|
globals:
|
|
- id: bms${bms_id}_combined_once
|
|
type: bool
|
|
restore_value: no
|
|
initial_value: "false"
|
|
- id: bms${bms_id}_combined
|
|
type: bool
|
|
restore_value: no
|
|
initial_value: "false"
|
|
|
|
# Combine once without conditions
|
|
esphome:
|
|
on_boot:
|
|
then:
|
|
# Shunt counter (total)
|
|
- lambda: id(${yambms_id}_var_bms_counter) += 1;
|
|
|
|
binary_sensor:
|
|
# Indicates whether the BMS can be combined
|
|
- platform: template
|
|
name: "${name} ${bms_name} Can be combined"
|
|
id: bms${bms_id}_can_be_combined
|
|
lambda: return (id(bms${bms_id}_online_status).state && id(bms${bms_id}_battery_capacity).state > 0);
|
|
|
|
interval:
|
|
- interval: ${bms_combine_interval}
|
|
then:
|
|
- lambda: |-
|
|
// BMS number to combine ?
|
|
if (id(${yambms_id}_var_to_combine_bms_number) == ${bms_id})
|
|
{
|
|
// The BMS can be combined ?
|
|
if (id(bms${bms_id}_can_be_combined).state)
|
|
{
|
|
// +-----------------------------------------------+
|
|
// | Combine once only |
|
|
// +-----------------------------------------------+
|
|
|
|
if (id(bms${bms_id}_combined_once) == false)
|
|
{
|
|
id(${yambms_id}_var_total_installed_battery_capacity) += id(bms${bms_id}_battery_capacity).state;
|
|
id(bms${bms_id}_combined_once) = true;
|
|
}
|
|
|
|
// +-----------------------------------------------+
|
|
// | Combine not continuously |
|
|
// +-----------------------------------------------+
|
|
|
|
if (id(bms${bms_id}_combined) == false)
|
|
{
|
|
// To combine bms counter
|
|
id(${yambms_id}_var_to_combine_bms_counter) += 1;
|
|
|
|
// Combined
|
|
id(bms${bms_id}_combined) = true;
|
|
}
|
|
|
|
// +-----------------------------------------------+
|
|
// | Combine continuously |
|
|
// +-----------------------------------------------+
|
|
|
|
// YamBMS Errors Bitmask (16bit)
|
|
if (id(bms${bms_id}_yambms_errors_bitmask).state > 0)
|
|
{
|
|
uint16_t errors_bitmask = id(bms${bms_id}_yambms_errors_bitmask).state; // errors_bitmask (16bit)
|
|
id(${yambms_id}_var_errors_bitmask) |= errors_bitmask; // OR bitwise
|
|
id(${yambms_id}_var_errors_bitmask_counter) += 1; // errors_bitmask_counter
|
|
}
|
|
|
|
if (id(bms${bms_id}_charging_allowed).state)
|
|
{
|
|
// TOTAL charging_allowed_counter
|
|
id(${yambms_id}_var_charging_allowed_counter) += 1;
|
|
// TOTAL max_charge_current
|
|
id(${yambms_id}_var_total_max_charge_current) += id(bms${bms_id}_max_charge_current).state;
|
|
// Limit to max. charge current
|
|
if(id(${yambms_id}_var_total_max_charge_current) > ${yambms_max_requested_charge_current})
|
|
{
|
|
id(${yambms_id}_var_total_max_charge_current) = ${yambms_max_requested_charge_current};
|
|
}
|
|
}
|
|
// TOTAL bms_blocking_charge_counter
|
|
else id(${yambms_id}_var_bms_blocking_charge_counter) += 1;
|
|
|
|
if (id(bms${bms_id}_discharging_allowed).state)
|
|
{
|
|
// TOTAL discharging_allowed_counter
|
|
id(${yambms_id}_var_discharging_allowed_counter) += 1;
|
|
// TOTAL max_discharge_current
|
|
id(${yambms_id}_var_total_max_discharge_current) += id(bms${bms_id}_max_discharge_current).state;
|
|
// Limit to max. discharge current
|
|
if(id(${yambms_id}_var_total_max_discharge_current) > ${yambms_max_requested_discharge_current})
|
|
{
|
|
id(${yambms_id}_var_total_max_discharge_current) = ${yambms_max_requested_discharge_current};
|
|
}
|
|
}
|
|
// TOTAL bms_blocking_discharge_counter
|
|
else id(${yambms_id}_var_bms_blocking_discharge_counter) += 1;
|
|
|
|
// TOTAL total_voltage
|
|
id(${yambms_id}_var_bms_total_voltage) += id(bms${bms_id}_total_voltage).state;
|
|
|
|
// TOTAL current
|
|
id(${yambms_id}_var_bms_total_current) += id(bms${bms_id}_current).state;
|
|
|
|
// TOTAL power
|
|
id(${yambms_id}_var_bms_total_power) += id(bms${bms_id}_power).state;
|
|
|
|
// TOTAL battery_capacity
|
|
id(${yambms_id}_var_total_battery_capacity) += id(bms${bms_id}_battery_capacity).state;
|
|
|
|
// TOTAL capacity_remaining_ah
|
|
id(${yambms_id}_var_total_capacity_remaining_ah) += id(bms${bms_id}_capacity_remaining_ah).state;
|
|
|
|
// TOTAL SoC
|
|
// id(${yambms_id}_var_bms_total_soc) += id(bms${bms_id}_battery_soc).state;
|
|
|
|
// TOTAL SoH
|
|
id(${yambms_id}_var_bms_total_soh) += id(bms${bms_id}_battery_soh).state;
|
|
|
|
// TOTAL charging_cycles
|
|
id(${yambms_id}_var_total_charging_cycles) += id(bms${bms_id}_charging_cycles).state;
|
|
|
|
// TOTAL equalizing_counter
|
|
if (id(bms${bms_id}_equalizing).state) id(${yambms_id}_var_equalizing_counter) += 1;
|
|
|
|
// MIN/MAX values
|
|
// MAX balance_trigger_voltage
|
|
if (id(bms${bms_id}_balance_trigger_voltage).state > id(${yambms_id}_var_max_balance_trigger_voltage))
|
|
id(${yambms_id}_var_max_balance_trigger_voltage) = id(bms${bms_id}_balance_trigger_voltage).state;
|
|
|
|
// MIN min_cell_voltage
|
|
// MIN min_voltage_cell (cell number)
|
|
if (id(bms${bms_id}_min_cell_voltage).state < id(${yambms_id}_var_min_cell_voltage))
|
|
{
|
|
id(${yambms_id}_var_min_cell_voltage) = id(bms${bms_id}_min_cell_voltage).state;
|
|
id(${yambms_id}_var_min_voltage_cell) = id(bms${bms_id}_min_voltage_cell).state + (${bms_id} * 100);
|
|
}
|
|
|
|
// MAX max_cell_voltage
|
|
// MAX max_voltage_cell (cell number)
|
|
if (id(bms${bms_id}_max_cell_voltage).state > id(${yambms_id}_var_max_cell_voltage))
|
|
{
|
|
id(${yambms_id}_var_max_cell_voltage) = id(bms${bms_id}_max_cell_voltage).state;
|
|
id(${yambms_id}_var_max_voltage_cell) = id(bms${bms_id}_max_voltage_cell).state + (${bms_id} * 100);
|
|
}
|
|
|
|
// MIN cell_ovp
|
|
if (id(bms${bms_id}_cell_ovp).state < id(${yambms_id}_var_min_cell_ovp))
|
|
id(${yambms_id}_var_min_cell_ovp) = id(bms${bms_id}_cell_ovp).state;
|
|
|
|
// MAX cell_uvp
|
|
if (id(bms${bms_id}_cell_uvp).state > id(${yambms_id}_var_max_cell_uvp))
|
|
id(${yambms_id}_var_max_cell_uvp) = id(bms${bms_id}_cell_uvp).state;
|
|
|
|
// MIN temperature
|
|
// MIN temperature_sensor
|
|
if (id(bms${bms_id}_min_temperature).state < id(${yambms_id}_var_min_temperature))
|
|
{
|
|
id(${yambms_id}_var_min_temperature) = id(bms${bms_id}_min_temperature).state;
|
|
id(${yambms_id}_var_min_temperature_sensor) = id(bms${bms_id}_min_temperature_sensor).state;
|
|
}
|
|
|
|
// MAX temperature
|
|
// MAX temperature_sensor
|
|
if (id(bms${bms_id}_max_temperature).state > id(${yambms_id}_var_max_temperature))
|
|
{
|
|
id(${yambms_id}_var_max_temperature) = id(bms${bms_id}_max_temperature).state;
|
|
id(${yambms_id}_var_max_temperature_sensor) = id(bms${bms_id}_max_temperature_sensor).state;
|
|
}
|
|
}
|
|
|
|
// +-----------------------------------------------+
|
|
// | Uncombine not continuously |
|
|
// +-----------------------------------------------+
|
|
else if (id(bms${bms_id}_combined) == true)
|
|
{
|
|
// To combine bms counter
|
|
id(${yambms_id}_var_to_combine_bms_counter) -= 1;
|
|
|
|
// Uncombined
|
|
id(bms${bms_id}_combined) = false;
|
|
}
|
|
|
|
// Increment the counter for next BMS processing
|
|
id(${yambms_id}_var_to_combine_bms_number)++;
|
|
}
|