diff --git a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_DEMO.yaml b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_DEMO.yaml index 661b57a..383ba9f 100644 --- a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_DEMO.yaml +++ b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_DEMO.yaml @@ -293,6 +293,27 @@ views: - entity: number.yambms_demo_yambms_1_auto_float_voltage_step name: Voltage Step title: YamBMS - Auto Float + - type: entities + entities: + - entity: switch.yambms_yambms_1_automatic_eoc_current + name: Automatic EOC Current + - entity: sensor.yambms_yambms_1_auto_eoc_status + name: Status + - entity: sensor.yambms_yambms_1_auto_eoc_current + name: Required Current + - entity: number.yambms_yambms_1_auto_eoc_target_hour + name: Target hour + - entity: number.yambms_yambms_1_auto_eoc_target_minute + name: Target minute + - entity: number.yambms_yambms_1_auto_eoc_correction + name: Current Correction + - entity: number.yambms_yambms_1_auto_eoc_capacity_modifier + name: Capacity Modifier + - entity: number.yambms_yambms_1_auto_eoc_increase_stop_hours + name: Stop hours + - entity: number.yambms_yambms_1_auto_eoc_increase_stop_soc + name: Stop SoC + title: YamBMS - Auto EOC - type: entities entities: - entity: number.yambms_demo_yambms_1_rebulk_soc diff --git a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_3xBMS.yaml b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_3xBMS.yaml index 8595c51..2a0da40 100644 --- a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_3xBMS.yaml +++ b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_3xBMS.yaml @@ -267,6 +267,27 @@ views: - entity: number.yambms_yambms_1_auto_float_voltage_step name: Voltage Step title: YamBMS - Auto Float + - type: entities + entities: + - entity: switch.yambms_yambms_1_automatic_eoc_current + name: Automatic EOC Current + - entity: sensor.yambms_yambms_1_auto_eoc_status + name: Status + - entity: sensor.yambms_yambms_1_auto_eoc_current + name: Required Current + - entity: number.yambms_yambms_1_auto_eoc_target_hour + name: Target hour + - entity: number.yambms_yambms_1_auto_eoc_target_minute + name: Target minute + - entity: number.yambms_yambms_1_auto_eoc_correction + name: Current Correction + - entity: number.yambms_yambms_1_auto_eoc_capacity_modifier + name: Capacity Modifier + - entity: number.yambms_yambms_1_auto_eoc_increase_stop_hours + name: Stop hours + - entity: number.yambms_yambms_1_auto_eoc_increase_stop_soc + name: Stop SoC + title: YamBMS - Auto EOC - type: entities entities: - entity: number.yambms_yambms_1_rebulk_soc diff --git a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_7xBMS.yaml b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_7xBMS.yaml index a2a16ea..c1abd08 100644 --- a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_7xBMS.yaml +++ b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_7xBMS.yaml @@ -267,6 +267,27 @@ views: - entity: number.yambms_yambms_1_auto_float_voltage_step name: Voltage Step title: YamBMS - Auto Float + - type: entities + entities: + - entity: switch.yambms_yambms_1_automatic_eoc_current + name: Automatic EOC Current + - entity: sensor.yambms_yambms_1_auto_eoc_status + name: Status + - entity: sensor.yambms_yambms_1_auto_eoc_current + name: Required Current + - entity: number.yambms_yambms_1_auto_eoc_target_hour + name: Target hour + - entity: number.yambms_yambms_1_auto_eoc_target_minute + name: Target minute + - entity: number.yambms_yambms_1_auto_eoc_correction + name: Current Correction + - entity: number.yambms_yambms_1_auto_eoc_capacity_modifier + name: Capacity Modifier + - entity: number.yambms_yambms_1_auto_eoc_increase_stop_hours + name: Stop hours + - entity: number.yambms_yambms_1_auto_eoc_increase_stop_soc + name: Stop SoC + title: YamBMS - Auto EOC - type: entities entities: - entity: number.yambms_yambms_1_rebulk_soc diff --git a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_UART-GPS_BLE_3xBMS.yaml b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_UART-GPS_BLE_3xBMS.yaml index c4ff912..2cac270 100644 --- a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_UART-GPS_BLE_3xBMS.yaml +++ b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_UART-GPS_BLE_3xBMS.yaml @@ -267,6 +267,27 @@ views: - entity: number.yambms_yambms_1_auto_float_voltage_step name: Voltage Step title: YamBMS - Auto Float + - type: entities + entities: + - entity: switch.yambms_yambms_1_automatic_eoc_current + name: Automatic EOC Current + - entity: sensor.yambms_yambms_1_auto_eoc_status + name: Status + - entity: sensor.yambms_yambms_1_auto_eoc_current + name: Required Current + - entity: number.yambms_yambms_1_auto_eoc_target_hour + name: Target hour + - entity: number.yambms_yambms_1_auto_eoc_target_minute + name: Target minute + - entity: number.yambms_yambms_1_auto_eoc_correction + name: Current Correction + - entity: number.yambms_yambms_1_auto_eoc_capacity_modifier + name: Capacity Modifier + - entity: number.yambms_yambms_1_auto_eoc_increase_stop_hours + name: Stop hours + - entity: number.yambms_yambms_1_auto_eoc_increase_stop_soc + name: Stop SoC + title: YamBMS - Auto EOC - type: entities entities: - entity: number.yambms_yambms_1_rebulk_soc diff --git a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_without_BMS.yaml b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_without_BMS.yaml index 7b9618e..e490112 100644 --- a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_without_BMS.yaml +++ b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_without_BMS.yaml @@ -267,6 +267,27 @@ views: - entity: number.yambms_yambms_1_auto_float_voltage_step name: Voltage Step title: YamBMS - Auto Float + - type: entities + entities: + - entity: switch.yambms_yambms_1_automatic_eoc_current + name: Automatic EOC Current + - entity: sensor.yambms_yambms_1_auto_eoc_status + name: Status + - entity: sensor.yambms_yambms_1_auto_eoc_current + name: Required Current + - entity: number.yambms_yambms_1_auto_eoc_target_hour + name: Target hour + - entity: number.yambms_yambms_1_auto_eoc_target_minute + name: Target minute + - entity: number.yambms_yambms_1_auto_eoc_correction + name: Current Correction + - entity: number.yambms_yambms_1_auto_eoc_capacity_modifier + name: Capacity Modifier + - entity: number.yambms_yambms_1_auto_eoc_increase_stop_hours + name: Stop hours + - entity: number.yambms_yambms_1_auto_eoc_increase_stop_soc + name: Stop SoC + title: YamBMS - Auto EOC - type: entities entities: - entity: number.yambms_yambms_1_rebulk_soc diff --git a/documents/README/YamBMS_functions.md b/documents/README/YamBMS_functions.md index c9d647b..116a61d 100644 --- a/documents/README/YamBMS_functions.md +++ b/documents/README/YamBMS_functions.md @@ -135,6 +135,48 @@ This feature might not work with all inverters as good or is not required if the The voltage steps can be configured (default `0.1V`) with `Auto Float Voltage Step`. The update interval can be configured (default `3 minutes`) with `Auto Float Update Interval`. +## Auto EOC + +![Image](../../images/YamBMS_Auto_EOC.png "YamBMS Auto EOC") + +When to use: Your battery would be full early in the day and then be idle for the rest of the day. You want to charge it slowly and have it full at a specified time, for example in the evening. + +This function allows to set a target time when `Bulk` charging. It limits the `Requested Charge Current (CCL)` so the battery should reach full charge at the specified time. As the algorithm is quite simple there are some requirements for it to work correctly: + +- The time of the ESPHome device must be correct and available. +- The `Battery Capacity` must be correct. +- The charger/inverter can deliver the `Requested Charge Current (CCL)` over the time frame -> the sun must be shining. + +There are some configuration options to adjust the behaviour: + +- `Automatic EOC Current`: This switch enables or disables the function. When disabled, it will not limit the `Requested Charge Current (CCL)`. +- `Auto EOC Target Hour`: This selects the hour of the desired target time. +- `Auto EOC Target Minute`: This selects the minute of the desired target time. +- `Auto EOC Correction`: This increases or decreases the `Requested Charge Current (CCL)` and allows for correcting charger/inverter differences, for example if the inverter delivers less current than requested. +- `Auto EOC Capacity Modifier`: This allows to lower the target capacity for the calculation. If your battery `Capacity Remaining` does not reach `Battery Capacity` when 100% full, you can adjust the value here. +- `Auto EOC Increase Stop Hours`: When nearing the target time but the charge current can not be reached, the `Requested Charge Current (CCL)` will increase until it reaches the max. charge current. To avoid this, a time frame bevor the target time can be chosen in which the current will not be increased. E.g. if this option is set to 1 hour, the `Requested Charge Current (CCL)` is 40A and the time is between `Target Hour - 1 hour` and `Target Hour`, it will stay at 40A. +- `Auto EOC Increase Stop SoC`: Similar to `Auto EOC Increase Stop Hours`, this stops increasing the `Requested Charge Current (CCL)` when the `SoC` is equal or above the specified `SoC`. + +The text sensor `Auto EOC Status` will show the current status of the function: +- `Stop: Disabled`: Function is disabled or capacity not available. +- `Stop: Float`: YamBMS currently in `Float` mode, not `Bulk`. +- `Stop: Time not valid`: The ESPHome device time is not valid. +- `Stop: Target time passed`: The current time is after the selected target time. +- `Stop: Current above limit`: The required charge current is above the current charge limit. +- `Run: Current increase stopped`: Running, but no current increase because of `Auto EOC Increase Stop Hours` or `Auto EOC Increase Stop SoC`. +- `Run`: Working normally. + +The sensor `Auto EOC Current` will show the calculated charging current. Note that it is filtered by an EWMA filter with a default 3 minute delay. +That means that changes to the options or parameters are not immediately visible. This avoids that the `Requested Charge Current (CCL)` will fluctuate too much. It will show 0A when the function is disabled/stopped or there is no solution. + +The function used to calculate the required charging current is very basic. The missing battery capacity (difference between `Battery Capacity` and `Capacity Remaining`) divided by the remaining hours. It will be updated every minute, but afterwards filtered before it is used for `Requested Charge Current (CCL)`. That means it will adapt, but not take into account any special circumstances. For example if `Auto CCL` is enabled and required, the charge current may further be limited by `Auto CCL`. The target time may then not be reached exactly. To account for this, the parameter `Auto EOC Correction` can be used to increase the overall current a little to compensate for the lower end current. + +Here is an example when the target time is set to 18:00. Starting at 00:00, the required current increases as the battery is discharged. When the battery starts charging as the sun is up, the required current stabilizes around 14A. +The current is increased at the end as it does not exactly hit its required charge, but at 17:30, the required current is stable because the parameter `Auto EOC Increase Stop Hours` was set to 0.5 hours, so it will not be increased anymore. +At about 18:08 the battery is 100% after a short balancing period. + +![Image](../../images/YamBMS_Auto_EOC_Graph.png "YamBMS Auto EOC Graph") + ## Requested Values ![Image](../../images/YamBMS_Requested_Values.png "YamBMS_Requested_Values") diff --git a/images/YamBMS_Auto_EOC.png b/images/YamBMS_Auto_EOC.png new file mode 100644 index 0000000..7adfc5b Binary files /dev/null and b/images/YamBMS_Auto_EOC.png differ diff --git a/images/YamBMS_Auto_EOC_Graph.png b/images/YamBMS_Auto_EOC_Graph.png new file mode 100644 index 0000000..a316cb3 Binary files /dev/null and b/images/YamBMS_Auto_EOC_Graph.png differ diff --git a/packages/yambms/yambms.yaml b/packages/yambms/yambms.yaml index 72942a9..5f241eb 100644 --- a/packages/yambms/yambms.yaml +++ b/packages/yambms/yambms.yaml @@ -26,5 +26,6 @@ packages: yambms_auto_ccl: !include yambms_auto_ccl.yaml yambms_auto_dcl: !include yambms_auto_dcl.yaml yambms_auto_float: !include yambms_auto_float.yaml + yambms_auto_eoc: !include yambms_auto_eoc.yaml # Update service yambms_service: !include yambms_service.yaml diff --git a/packages/yambms/yambms_auto_eoc.yaml b/packages/yambms/yambms_auto_eoc.yaml new file mode 100644 index 0000000..ed00b79 --- /dev/null +++ b/packages/yambms/yambms_auto_eoc.yaml @@ -0,0 +1,281 @@ +# Updated : 2025.07.26 +# Version : 1.1.1 +# 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 . + +substitutions: + # +--------------------------------------+ + # | Use the settings below with caution | + # +--------------------------------------+ + # Alpha value for the exponential moving average filter. + required_charge_current_alpha: "0.25" + # Filter delay in minutes. The charge current will not be updated more often than this value. + # This is to prevent the charge current from fluctuating too much. + required_charge_current_filter_delay: "3" + +switch: + - platform: template + name: ${name} ${yambms_name} Automatic EOC Current + id: ${yambms_id}_switch_auto_eoc + restore_mode: RESTORE_DEFAULT_OFF + optimistic: true + entity_category: config + +number: + - platform: template + name: ${name} ${yambms_name} Auto EOC Target Hour + id: ${yambms_id}_auto_eoc_target_hour + step: 1 + min_value: 12 + max_value: 23 + restore_value: true + mode: "${yambms_input_number_mode}" + initial_value: 18 + unit_of_measurement: h + icon: mdi:clock-digital + optimistic: true + entity_category: config + + - platform: template + name: ${name} ${yambms_name} Auto EOC Target Minute + id: ${yambms_id}_auto_eoc_target_min + step: 15 + min_value: 0 + max_value: 45 + restore_value: true + mode: "${yambms_input_number_mode}" + initial_value: 0 + unit_of_measurement: m + icon: mdi:clock-digital + optimistic: true + entity_category: config + + - platform: template + name: "${name} ${yambms_name} Auto EOC Correction" + id: "${yambms_id}_auto_eoc_correction" + step: 1 + min_value: -20 + max_value: 20 + restore_value: true + mode: "${yambms_input_number_mode}" + initial_value: 0 + unit_of_measurement: '%' + icon: mdi:arrow-oscillating + optimistic: true + entity_category: config + + - platform: template + name: "${name} ${yambms_name} Auto EOC Capacity Modifier" + id: "${yambms_id}_auto_eoc_modifier" + step: 1 + min_value: -10 + max_value: 0 + restore_value: true + mode: "${yambms_input_number_mode}" + initial_value: -2 + unit_of_measurement: '%' + icon: mdi:battery-arrow-down + optimistic: true + entity_category: config + + - platform: template + name: "${name} ${yambms_name} Auto EOC Increase Stop Hours" + id: "${yambms_id}_auto_eoc_stop_hours" + step: 0.5 + min_value: 0 + max_value: 4 + restore_value: true + mode: "${yambms_input_number_mode}" + initial_value: 1 + unit_of_measurement: 'h' + icon: mdi:timer-stop + optimistic: true + entity_category: config + + - platform: template + name: "${name} ${yambms_name} Auto EOC Increase Stop SoC" + id: "${yambms_id}_auto_eoc_stop_soc" + step: 1 + min_value: 50 + max_value: 100 + restore_value: true + mode: "${yambms_input_number_mode}" + initial_value: 97 + unit_of_measurement: '%' + icon: mdi:battery-charging-80 + optimistic: true + entity_category: config + +text_sensor: + # +--------------------------------------+ + # | Auto EOC Status | + # +--------------------------------------+ + - platform: template + name: "${name} ${yambms_name} Auto EOC Status" + id: ${yambms_id}_auto_eoc_status + update_interval: never + icon: mdi:information-outline + entity_category: diagnostic + +sensor: + # +--------------------------------------+ + # | Auto EOC Charging | + # +--------------------------------------+ + # Filter charging current to smooth out fluctuations + # The value will be updated every 3 minutes + - platform: copy + source_id: ${yambms_id}_auto_eoc_charging_current + name: ${name} ${yambms_name} Auto EOC Current + id: "${yambms_id}_auto_eoc_charging_current_filtered" + unit_of_measurement: A + device_class: current + filters: + - exponential_moving_average: + alpha: ${required_charge_current_alpha} + send_every: ${required_charge_current_filter_delay} + send_first_at: 1 + - round: 0 + + - platform: template + name: ${name} ${yambms_name} Auto EOC Required Current + id: ${yambms_id}_auto_eoc_charging_current + update_interval: 60s + unit_of_measurement: A + device_class: current + internal: true + filters: + - round: 0 + lambda: |- + // Check if enabled + if (!id(${yambms_id}_switch_auto_eoc).state || + !id(${yambms_id}_battery_capacity).has_state() || + !id(${yambms_id}_capacity_remaining_ah).has_state() || + !id(${yambms_id}_max_charge_current).has_state()) { + // Auto EOC Charging disabled + //ESP_LOGI("auto_eoc", "Auto EOC Charging is disabled or battery capacity is not available"); + id(${yambms_id}_auto_eoc) = 0; + id(${yambms_id}_auto_eoc_status).publish_state("Stop: Disabled"); + return 0; + } + + // Check if Float is active + if (id(${yambms_id}_charging_instruction).state == "Float") { + id(${yambms_id}_auto_eoc) = 0; + id(${yambms_id}_auto_eoc_status).publish_state("Stop: Float"); + return 0; + } + + // Check if current time is valid + const auto current_time = id(my_time).now(); + if (!current_time.is_valid()) { + ESP_LOGW("auto_eoc", "Time not valid"); + id(${yambms_id}_auto_eoc) = 0; + id(${yambms_id}_auto_eoc_status).publish_state("Stop: Time not valid"); + return 0; + } + + // Get target time + const int target_hour = id(${yambms_id}_auto_eoc_target_hour).state; + const int target_minute = id(${yambms_id}_auto_eoc_target_min).state; + + // Create target timestamp + auto target_time = current_time; + target_time.hour = target_hour; + target_time.minute = target_minute; + target_time.recalc_timestamp_local(); + + // Calculate hours left until target time + const float hours_left = (target_time.timestamp - current_time.timestamp) / 3600.0; + + if (hours_left <= 0) { + //ESP_LOGI("auto_eoc", "Target time has already passed"); + id(${yambms_id}_auto_eoc) = 0; + id(${yambms_id}_auto_eoc_status).publish_state("Stop: Target time passed"); + return 0; + } + + // Check if we stop increasing the charge current + bool stop_increasing = false; + if (id(${yambms_id}_battery_soc).has_state() && (id(${yambms_id}_battery_soc).state >= id(${yambms_id}_auto_eoc_stop_soc).state)) { + ESP_LOGI("auto_eoc", "Stopping charge current increase, SoC is above threshold"); + stop_increasing = true; + } else if (hours_left <= id(${yambms_id}_auto_eoc_stop_hours).state) { + ESP_LOGI("auto_eoc", "Stopping charge current increase, hours left is below threshold"); + stop_increasing = true; + } + + // Get battery capacity + auto battery_capacity = id(${yambms_id}_battery_capacity).state; + + // Apply negative capacity modifier + battery_capacity += (battery_capacity * (id(${yambms_id}_auto_eoc_modifier).state / 100.0)); + + // Calculate missing capacity + auto capacity_required = battery_capacity - id(${yambms_id}_capacity_remaining_ah).state; + if (capacity_required < 0) { + capacity_required = 0; + } + + // Get active charge current, this will be our maximum charge current + float charge_current = id(${yambms_id}_max_charge_current).state + id(${yambms_id}_auto_ccl); + + // Calculate required charge current + float required_charge_current = capacity_required / hours_left; + + // Apply charge current correction factor + const float correction_factor = (id(${yambms_id}_auto_eoc_correction).state / 100.0) + 1.0; + required_charge_current *= correction_factor; + + // If the required charge current higher than the maximum charge current, return 0 to indicate + // that there is no solution + float return_value = 0; + if (required_charge_current >= charge_current) { + //ESP_LOGI("auto_eoc", "Required charge current is higher than maximum charge current"); + required_charge_current = 0; + id(${yambms_id}_auto_eoc_status).publish_state("Stop: Current above limit"); + } else { + // The value is valid, return it + return_value = required_charge_current; + + // Check if filtered charging current is available + if (id(${yambms_id}_auto_eoc_charging_current_filtered).has_state()) { + const float filtered_charge_current = id(${yambms_id}_auto_eoc_charging_current_filtered).state; + + // Check if current is increasing and we should stop + if (stop_increasing && (required_charge_current > filtered_charge_current)) { + // Return previous filtered charge current + return_value = filtered_charge_current; + id(${yambms_id}_auto_eoc_status).publish_state("Run: Current increase stopped"); + } else { + // Update status to running + id(${yambms_id}_auto_eoc_status).publish_state("Run"); + } + + // Use filtered charge current for calculations + required_charge_current = filtered_charge_current; + } + } + + // Limit required charge current to maximum charge current + if (required_charge_current && (required_charge_current < charge_current)) { + // Calculate negative difference to charge current + id(${yambms_id}_auto_eoc) = round(required_charge_current - charge_current); + } else { + id(${yambms_id}_auto_eoc) = 0; + } + + return return_value; diff --git a/packages/yambms/yambms_core.yaml b/packages/yambms/yambms_core.yaml index d633aff..4742602 100644 --- a/packages/yambms/yambms_core.yaml +++ b/packages/yambms/yambms_core.yaml @@ -120,6 +120,10 @@ globals: type: float restore_value: no initial_value: '0.0' + - id: ${yambms_id}_auto_eoc + type: float + restore_value: no + initial_value: '0.0' - id: ${yambms_id}_auto_float type: float restore_value: no @@ -458,8 +462,12 @@ sensor: - delta: 0.1 lambda: |- // Charging Allowed - if ((id(${yambms_id}_charging_instruction).state == "Bulk") | (id(${yambms_id}_charging_instruction).state == "Float")) - return (id(${yambms_id}_max_charge_current).state + id(${yambms_id}_auto_ccl)); + if ((id(${yambms_id}_charging_instruction).state == "Bulk") | (id(${yambms_id}_charging_instruction).state == "Float")) { + float requested_charge_current = id(${yambms_id}_max_charge_current).state + id(${yambms_id}_auto_ccl) + id(${yambms_id}_auto_eoc); + if (requested_charge_current < 0) + return 0; + return requested_charge_current; + } // Charging Not Allowed else return 0;