diff --git a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_DEMO.yaml b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_DEMO.yaml
index 32227eb..7dfcb41 100644
--- a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_DEMO.yaml
+++ b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_DEMO.yaml
@@ -1,4 +1,4 @@
-# Updated : 2026.11.05
+# Updated : 2026.11.06
# Version : 1.8.1
# GitHub : https://github.com/Sleeper85/esphome-yambms
@@ -565,6 +565,20 @@ views:
row:
entity: sensor.yambms_demo_auto_eoc_current
name: Required Current
+ - type: conditional
+ conditions:
+ - entity: switch.yambms_demo_automatic_eoc_current
+ state: "on"
+ row:
+ entity: number.yambms_demo_auto_eoc_start_hour
+ name: Start hour
+ - type: conditional
+ conditions:
+ - entity: switch.yambms_demo_automatic_eoc_current
+ state: "on"
+ row:
+ entity: number.yambms_demo_auto_eoc_start_minute
+ name: Start minute
- type: conditional
conditions:
- entity: switch.yambms_demo_automatic_eoc_current
@@ -682,7 +696,7 @@ views:
{% if is_state('switch.yambms_demo_automatic_eoc_current','on') %}
| Automatic EOC Current |
- {% set eoc_status = states('sensor.yambms_demo_auto_eoc_status') %}{% set eoc_val %}{{ states('number.yambms_demo_auto_eoc_target_hour') | int }}:{{ '%02d' % (states('number.yambms_demo_auto_eoc_target_minute') | int) }} — {{ eoc_status }}{% endset %}{% if eoc_status.startswith('Stop:') %}{{ eoc_val }}{% elif eoc_status.startswith('Run') %}{{ eoc_val }}{% else %}{{ eoc_val }}{% endif %} |
+ {% set eoc_status = states('sensor.yambms_demo_auto_eoc_status') %}{% set eoc_val %}{{ states('number.yambms_demo_auto_eoc_start_hour') | int }}:{{ '%02d' % (states('number.yambms_demo_auto_eoc_start_minute') | int) }}–{{ states('number.yambms_demo_auto_eoc_target_hour') | int }}:{{ '%02d' % (states('number.yambms_demo_auto_eoc_target_minute') | int) }} — {{ eoc_status }}{% endset %}{% if eoc_status.startswith('Stop:') %}{{ eoc_val }}{% elif eoc_status.startswith('Run') %}{{ eoc_val }}{% else %}{{ eoc_val }}{% endif %} |
{% endif %}
{% if is_state('switch.yambms_demo_automatic_soc_limit','on') %}
diff --git a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_3xBMS.yaml b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_3xBMS.yaml
index 7fe4047..9707673 100644
--- a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_3xBMS.yaml
+++ b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_3xBMS.yaml
@@ -1,4 +1,4 @@
-# Updated : 2026.11.05
+# Updated : 2026.11.06
# Version : 1.8.1
# GitHub : https://github.com/Sleeper85/esphome-yambms
@@ -234,7 +234,7 @@ views:
{% if is_state('switch.yambms_1_automatic_eoc_current','on') %}
| Automatic EOC Current |
- {% set eoc_status = states('sensor.yambms_1_auto_eoc_status') %}{% set eoc_val %}{{ states('number.yambms_1_auto_eoc_target_hour') | int }}:{{ '%02d' % (states('number.yambms_1_auto_eoc_target_minute') | int) }} — {{ eoc_status }}{% endset %}{% if eoc_status.startswith('Stop:') %}{{ eoc_val }}{% elif eoc_status.startswith('Run') %}{{ eoc_val }}{% else %}{{ eoc_val }}{% endif %} |
+ {% set eoc_status = states('sensor.yambms_1_auto_eoc_status') %}{% set eoc_val %}{{ states('number.yambms_1_auto_eoc_start_hour') | int }}:{{ '%02d' % (states('number.yambms_1_auto_eoc_start_minute') | int) }}–{{ states('number.yambms_1_auto_eoc_target_hour') | int }}:{{ '%02d' % (states('number.yambms_1_auto_eoc_target_minute') | int) }} — {{ eoc_status }}{% endset %}{% if eoc_status.startswith('Stop:') %}{{ eoc_val }}{% elif eoc_status.startswith('Run') %}{{ eoc_val }}{% else %}{{ eoc_val }}{% endif %} |
{% endif %}
{% if is_state('switch.yambms_1_automatic_soc_limit','on') %}
@@ -668,6 +668,20 @@ views:
row:
entity: sensor.yambms_1_auto_eoc_current
name: Required Current
+ - type: conditional
+ conditions:
+ - entity: switch.yambms_1_automatic_eoc_current
+ state: "on"
+ row:
+ entity: number.yambms_1_auto_eoc_start_hour
+ name: Start hour
+ - type: conditional
+ conditions:
+ - entity: switch.yambms_1_automatic_eoc_current
+ state: "on"
+ row:
+ entity: number.yambms_1_auto_eoc_start_minute
+ name: Start minute
- type: conditional
conditions:
- entity: switch.yambms_1_automatic_eoc_current
diff --git a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_7xBMS.yaml b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_7xBMS.yaml
index ffc9dc9..0055edc 100644
--- a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_7xBMS.yaml
+++ b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_JK_RS485_7xBMS.yaml
@@ -1,4 +1,4 @@
-# Updated : 2026.11.05
+# Updated : 2026.11.06
# Version : 1.8.1
# GitHub : https://github.com/Sleeper85/esphome-yambms
@@ -234,7 +234,7 @@ views:
{% if is_state('switch.yambms_1_automatic_eoc_current','on') %}
| Automatic EOC Current |
- {% set eoc_status = states('sensor.yambms_1_auto_eoc_status') %}{% set eoc_val %}{{ states('number.yambms_1_auto_eoc_target_hour') | int }}:{{ '%02d' % (states('number.yambms_1_auto_eoc_target_minute') | int) }} — {{ eoc_status }}{% endset %}{% if eoc_status.startswith('Stop:') %}{{ eoc_val }}{% elif eoc_status.startswith('Run') %}{{ eoc_val }}{% else %}{{ eoc_val }}{% endif %} |
+ {% set eoc_status = states('sensor.yambms_1_auto_eoc_status') %}{% set eoc_val %}{{ states('number.yambms_1_auto_eoc_start_hour') | int }}:{{ '%02d' % (states('number.yambms_1_auto_eoc_start_minute') | int) }}–{{ states('number.yambms_1_auto_eoc_target_hour') | int }}:{{ '%02d' % (states('number.yambms_1_auto_eoc_target_minute') | int) }} — {{ eoc_status }}{% endset %}{% if eoc_status.startswith('Stop:') %}{{ eoc_val }}{% elif eoc_status.startswith('Run') %}{{ eoc_val }}{% else %}{{ eoc_val }}{% endif %} |
{% endif %}
{% if is_state('switch.yambms_1_automatic_soc_limit','on') %}
@@ -668,6 +668,20 @@ views:
row:
entity: sensor.yambms_1_auto_eoc_current
name: Required Current
+ - type: conditional
+ conditions:
+ - entity: switch.yambms_1_automatic_eoc_current
+ state: "on"
+ row:
+ entity: number.yambms_1_auto_eoc_start_hour
+ name: Start hour
+ - type: conditional
+ conditions:
+ - entity: switch.yambms_1_automatic_eoc_current
+ state: "on"
+ row:
+ entity: number.yambms_1_auto_eoc_start_minute
+ name: Start minute
- type: conditional
conditions:
- entity: switch.yambms_1_automatic_eoc_current
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 91602bb..1f44cac 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
@@ -1,4 +1,4 @@
-# Updated : 2026.11.05
+# Updated : 2026.11.06
# Version : 1.8.1
# GitHub : https://github.com/Sleeper85/esphome-yambms
@@ -234,7 +234,7 @@ views:
{% if is_state('switch.yambms_1_automatic_eoc_current','on') %}
| Automatic EOC Current |
- {% set eoc_status = states('sensor.yambms_1_auto_eoc_status') %}{% set eoc_val %}{{ states('number.yambms_1_auto_eoc_target_hour') | int }}:{{ '%02d' % (states('number.yambms_1_auto_eoc_target_minute') | int) }} — {{ eoc_status }}{% endset %}{% if eoc_status.startswith('Stop:') %}{{ eoc_val }}{% elif eoc_status.startswith('Run') %}{{ eoc_val }}{% else %}{{ eoc_val }}{% endif %} |
+ {% set eoc_status = states('sensor.yambms_1_auto_eoc_status') %}{% set eoc_val %}{{ states('number.yambms_1_auto_eoc_start_hour') | int }}:{{ '%02d' % (states('number.yambms_1_auto_eoc_start_minute') | int) }}–{{ states('number.yambms_1_auto_eoc_target_hour') | int }}:{{ '%02d' % (states('number.yambms_1_auto_eoc_target_minute') | int) }} — {{ eoc_status }}{% endset %}{% if eoc_status.startswith('Stop:') %}{{ eoc_val }}{% elif eoc_status.startswith('Run') %}{{ eoc_val }}{% else %}{{ eoc_val }}{% endif %} |
{% endif %}
{% if is_state('switch.yambms_1_automatic_soc_limit','on') %}
@@ -668,6 +668,20 @@ views:
row:
entity: sensor.yambms_1_auto_eoc_current
name: Required Current
+ - type: conditional
+ conditions:
+ - entity: switch.yambms_1_automatic_eoc_current
+ state: "on"
+ row:
+ entity: number.yambms_1_auto_eoc_start_hour
+ name: Start hour
+ - type: conditional
+ conditions:
+ - entity: switch.yambms_1_automatic_eoc_current
+ state: "on"
+ row:
+ entity: number.yambms_1_auto_eoc_start_minute
+ name: Start minute
- type: conditional
conditions:
- entity: switch.yambms_1_automatic_eoc_current
diff --git a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_without_BMS.yaml b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_without_BMS.yaml
index c738dbe..a464d9e 100644
--- a/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_without_BMS.yaml
+++ b/HomeAssistant_Dashboards/YamBMS_HA_Dashboard_without_BMS.yaml
@@ -1,4 +1,4 @@
-# Updated : 2026.11.05
+# Updated : 2026.11.06
# Version : 1.8.1
# GitHub : https://github.com/Sleeper85/esphome-yambms
@@ -234,7 +234,7 @@ views:
{% if is_state('switch.yambms_1_automatic_eoc_current','on') %}
| Automatic EOC Current |
- {% set eoc_status = states('sensor.yambms_1_auto_eoc_status') %}{% set eoc_val %}{{ states('number.yambms_1_auto_eoc_target_hour') | int }}:{{ '%02d' % (states('number.yambms_1_auto_eoc_target_minute') | int) }} — {{ eoc_status }}{% endset %}{% if eoc_status.startswith('Stop:') %}{{ eoc_val }}{% elif eoc_status.startswith('Run') %}{{ eoc_val }}{% else %}{{ eoc_val }}{% endif %} |
+ {% set eoc_status = states('sensor.yambms_1_auto_eoc_status') %}{% set eoc_val %}{{ states('number.yambms_1_auto_eoc_start_hour') | int }}:{{ '%02d' % (states('number.yambms_1_auto_eoc_start_minute') | int) }}–{{ states('number.yambms_1_auto_eoc_target_hour') | int }}:{{ '%02d' % (states('number.yambms_1_auto_eoc_target_minute') | int) }} — {{ eoc_status }}{% endset %}{% if eoc_status.startswith('Stop:') %}{{ eoc_val }}{% elif eoc_status.startswith('Run') %}{{ eoc_val }}{% else %}{{ eoc_val }}{% endif %} |
{% endif %}
{% if is_state('switch.yambms_1_automatic_soc_limit','on') %}
@@ -668,6 +668,20 @@ views:
row:
entity: sensor.yambms_1_auto_eoc_current
name: Required Current
+ - type: conditional
+ conditions:
+ - entity: switch.yambms_1_automatic_eoc_current
+ state: "on"
+ row:
+ entity: number.yambms_1_auto_eoc_start_hour
+ name: Start hour
+ - type: conditional
+ conditions:
+ - entity: switch.yambms_1_automatic_eoc_current
+ state: "on"
+ row:
+ entity: number.yambms_1_auto_eoc_start_minute
+ name: Start minute
- type: conditional
conditions:
- entity: switch.yambms_1_automatic_eoc_current
diff --git a/documents/README/YamBMS_functions.md b/documents/README/YamBMS_functions.md
index 578cd16..bee1adf 100644
--- a/documents/README/YamBMS_functions.md
+++ b/documents/README/YamBMS_functions.md
@@ -382,29 +382,41 @@ The voltage steps can be configured (default `0.1V`) with `Auto Float Voltage St

-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.
+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. Or you charge from the grid at night and want the battery full at the end of the cheap tariff, for example at 06:00.
-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:
+This function allows to set a charging window when `Bulk` charging. It limits the `Requested Charge Current (CCL)` so the battery should reach full charge at the target 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.
+- The charger/inverter can deliver the `Requested Charge Current (CCL)` during the charging window (sun or grid).
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 Start Hour`: This selects the hour at which the charging window starts (default `0`).
+- `Auto EOC Start Minute`: This selects the minute at which the charging window starts (default `0`).
+- `Auto EOC Target Hour`: This selects the hour of the desired target time (`0` to `23`).
- `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 maximum value is `98%` because the `Battery SoC` is clamped to `98%` until end-of-charge (this keeps some inverters from stopping charging when the SoC reaches 100%), so a higher threshold could never be reached before end-of-charge and the stop condition would never trigger.
+Charging window: the function is active from the start time to the next target time. The window may cross midnight:
+
+| Start | Target | Window |
+|---|---|---|
+| `0:00` (default) | `18:00` | `0:00` to `18:00`, daylight charging |
+| `22:00` | `6:00` | `22:00` to `6:00` the next morning, night charging from the grid |
+| `6:00` | `6:00` | Start = target: 24 hours, always active |
+
+Outside the window the `Requested Charge Current (CCL)` is not limited by this function. The times follow the local time of the ESPHome device, including daylight saving time: a `22:00` to `6:00` window lasts 9 hours in the night the clocks go back.
+
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 (and the grace period does not apply, see below).
+- `Wait: Starts at hh:mm`: The current time is outside the charging window (and the grace period does not apply, see below).
- `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.
@@ -413,7 +425,7 @@ The text sensor `Auto EOC Status` will show the current status of the function:
Holding the current: The function never releases the `Requested Charge Current (CCL)` limit to the maximum while it still has a current to hold, as this would let the current spike back up. The last limited current is held instead in two situations:
-- Grace period: normally the limit would be released as soon as the target time has passed. Instead, as long as there is a current being held, a one hour grace period applies: the function keeps holding the current at its last value for up to one hour past the target time so a battery that has not quite finished charges gently instead of spiking to the maximum. During this period the status is suffixed with ` (Grace period)`. The grace period ends one hour after the target time, after which the status returns to `Stop: Target time passed`.
+- Grace period: normally the limit would be released as soon as the target time has passed. Instead, as long as there is a current being held, a one hour grace period applies: the function keeps holding the current at its last value for up to one hour past the target time so a battery that has not quite finished charges gently instead of spiking to the maximum. During this period the status is suffixed with ` (Grace period)`. The grace period ends one hour after the target time, after which the status changes to `Wait: Starts at hh:mm`, or to `Run` if the next charging window has already started. The grace period has priority over a window starting within this hour.
- Target capacity reached: when the battery has reached the target capacity (`Battery Capacity` adjusted by `Auto EOC Capacity Modifier`, and by `Auto SoC Limit` if active) before the target time, the calculated current would drop to `0A` and normally release the limit. Instead the last limited current is held until the charger switches to `Float`. Note that if the `Auto EOC Capacity Modifier` targets a capacity below `100%`, the function considers the battery "done" at that lower capacity.
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.
diff --git a/documents/README/changelog/Changelog.md b/documents/README/changelog/Changelog.md
index dc4eb7a..47995ba 100644
--- a/documents/README/changelog/Changelog.md
+++ b/documents/README/changelog/Changelog.md
@@ -29,6 +29,7 @@
* Fixed the RS485 link staying up with `Disabled` : the proxy sensors kept their last value, so the Pylontech component went on answering the inverter with stale data and kept reporting its status as ON ; the sensors it checks are now invalidated when the protocol is off, which makes it stop answering and report the link as down
* Fixed the CAN bus not stopping when the protocol was set to `Disabled` at runtime : the frame index kept its previous value and the last frame was re-emitted every 100 ms
* Fixed the reported communication bus and protocol being overwritten when a node declares several inverter links : each link now owns its slot, and the telemetry reports every link instead of the last one
+ * Auto EOC : new `Auto EOC Start Hour` / `Auto EOC Start Minute` define the charging window, which may cross midnight, and the target hour can be set from `0` to `23` (night charging from the grid) ; outside the window the status is `Wait: Starts at hh:mm` instead of `Stop: Target time passed`, the default start `0:00` keeps the daylight behaviour
* `Daily Charging Energy` / `Daily Discharging Energy` (YamBMS and BMS) rounded to 10 Wh (`0.01 kWh`) instead of 1 Wh, to reduce the number of state changes recorded by Home Assistant
* YamBMS 1.8.0 :
diff --git a/packages/yambms/yambms_auto_eoc.yaml b/packages/yambms/yambms_auto_eoc.yaml
index d18663a..19699c6 100644
--- a/packages/yambms/yambms_auto_eoc.yaml
+++ b/packages/yambms/yambms_auto_eoc.yaml
@@ -1,5 +1,5 @@
-# Updated : 2026.07.16
-# Version : 1.2.3
+# Updated : 2026.11.06
+# Version : 1.3.0
# GitHub : https://github.com/Sleeper85/esphome-yambms
# YamBMS ( Yet another multi-BMS Merging Solution )
@@ -47,12 +47,44 @@ switch:
entity_category: config
number:
+ # Charging window : from the start time to the next target time, may cross midnight.
+ # Start = target means a 24h window. The default start 00:00 is a daylight window.
+ - platform: template
+ name: "Auto EOC Start Hour"
+ id: yambms${yambms_id}_auto_eoc_start_hour
+ device_id: yambms_yambms${yambms_id}
+ step: 1
+ min_value: 0
+ max_value: 23
+ restore_value: true
+ mode: "${yambms_input_number_mode}"
+ initial_value: 0
+ unit_of_measurement: h
+ icon: mdi:clock-start
+ optimistic: true
+ entity_category: config
+
+ - platform: template
+ name: "Auto EOC Start Minute"
+ id: yambms${yambms_id}_auto_eoc_start_min
+ device_id: yambms_yambms${yambms_id}
+ 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-start
+ optimistic: true
+ entity_category: config
+
- platform: template
name: "Auto EOC Target Hour"
id: yambms${yambms_id}_auto_eoc_target_hour
device_id: yambms_yambms${yambms_id}
step: 1
- min_value: 12
+ min_value: 0
max_value: 23
restore_value: true
mode: "${yambms_input_number_mode}"
@@ -251,28 +283,49 @@ interval:
return;
}
- // Get target time
- const int target_hour = id(yambms${yambms_id}_auto_eoc_target_hour).state;
+ // +-----------------------------------------------+
+ // | Charging window (start -> next target) |
+ // +-----------------------------------------------+
+ // The window runs from the start time to the next target time and may cross
+ // midnight (e.g. 22:00 -> 06:00 for night charging from the grid). Start = target
+ // is a 24h window. Times are built in local time from the noon of a given day, so
+ // stepping whole days never slips the date on a 23h / 25h DST day.
+ const int start_hour = id(yambms${yambms_id}_auto_eoc_start_hour).state;
+ const int start_minute = id(yambms${yambms_id}_auto_eoc_start_min).state;
+ const int target_hour = id(yambms${yambms_id}_auto_eoc_target_hour).state;
const int target_minute = id(yambms${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.second = 0;
- target_time.recalc_timestamp_local();
+ ESPTime noon = current_time;
+ noon.hour = 12;
+ noon.minute = 0;
+ noon.second = 0;
+ noon.recalc_timestamp_local();
+ auto local_at = [&](int day_offset, int hour, int minute) -> time_t {
+ ESPTime t = ESPTime::from_epoch_local(noon.timestamp + (time_t) day_offset * 86400);
+ t.hour = hour;
+ t.minute = minute;
+ t.second = 0;
+ t.recalc_timestamp_local();
+ return t.timestamp;
+ };
- // Calculate hours left until target time
- const float hours_left = (target_time.timestamp - current_time.timestamp) / 3600.0;
+ const time_t now_ts = current_time.timestamp;
+ // Next target : today if still ahead, otherwise tomorrow
+ int target_day = 0;
+ time_t next_target = local_at(0, target_hour, target_minute);
+ if (next_target <= now_ts) {
+ target_day = 1;
+ next_target = local_at(1, target_hour, target_minute);
+ }
+ const time_t prev_target = local_at(target_day - 1, target_hour, target_minute);
- // Check if we stop increasing the charge current
- bool stop_increasing = false;
- if (id(yambms${yambms_id}_battery_soc).has_state() && (id(yambms${yambms_id}_battery_soc).state >= id(yambms${yambms_id}_auto_eoc_stop_soc).state)) {
- ESP_LOGD("yambms_auto_eoc", "Stopping charge current increase, SoC is above threshold");
- stop_increasing = true;
- } else if (hours_left <= id(yambms${yambms_id}_auto_eoc_stop_hours).state) {
- ESP_LOGD("yambms_auto_eoc", "Stopping charge current increase, hours left is below threshold");
- stop_increasing = true;
+ // Window start : last start time before the next target
+ time_t window_start;
+ if ((start_hour == target_hour) && (start_minute == target_minute)) {
+ window_start = prev_target; // 24h window
+ } else {
+ window_start = local_at(target_day, start_hour, start_minute);
+ if (window_start >= next_target) window_start = local_at(target_day - 1, start_hour, start_minute);
}
// Determine if there is a previously limited current we can hold onto. This is used to
@@ -283,22 +336,37 @@ interval:
!std::isnan(id(yambms${yambms_id}_auto_eoc_charging_current_filtered).state) &&
(id(yambms${yambms_id}_auto_eoc_charging_current_filtered).state > 0.0f);
- // Check if the time is up
+ // Calculate hours left until the target time
+ float hours_left = (next_target - now_ts) / 3600.0;
+
+ // The target time has passed. Allow a one hour grace period during which the last
+ // limited current is held, so a battery that has not quite finished charges gently
+ // instead of spiking to maximum. It has priority over a window starting right after.
bool grace_period = false;
- if (hours_left <= 0) {
- // Time is up. Allow a one hour grace period during which the last limited current is
- // held, so a battery that has not quite finished charges gently instead of spiking to
- // maximum. If more than one hour has passed, or there is no current to hold, we stop.
- if ((hours_left < -1.0) || !has_hold_current) {
- id(yambms${yambms_id}_var_auto_eoc) = 0;
- id(yambms${yambms_id}_auto_eoc_charging_current_filtered).publish_state(NAN);
- id(yambms${yambms_id}_auto_eoc_status).publish_state("Stop: Target time passed");
- id(yambms${yambms_id}_var_charge_current_step)++;
- return;
- } else {
- grace_period = true;
- ESP_LOGD("yambms_auto_eoc", "Target time passed, holding current for grace period");
- }
+ const float hours_since_target = (now_ts - prev_target) / 3600.0;
+ if ((hours_since_target <= 1.0) && has_hold_current) {
+ grace_period = true;
+ hours_left = -hours_since_target;
+ ESP_LOGD("yambms_auto_eoc", "Target time passed, holding current for grace period");
+ } else if (now_ts < window_start) {
+ // Outside the charging window
+ char wait_status[40];
+ snprintf(wait_status, sizeof(wait_status), "Wait: Starts at %d:%02d", start_hour, start_minute);
+ id(yambms${yambms_id}_var_auto_eoc) = 0;
+ id(yambms${yambms_id}_auto_eoc_charging_current_filtered).publish_state(NAN);
+ id(yambms${yambms_id}_auto_eoc_status).publish_state(wait_status);
+ id(yambms${yambms_id}_var_charge_current_step)++;
+ return;
+ }
+
+ // Check if we stop increasing the charge current
+ bool stop_increasing = false;
+ if (id(yambms${yambms_id}_battery_soc).has_state() && (id(yambms${yambms_id}_battery_soc).state >= id(yambms${yambms_id}_auto_eoc_stop_soc).state)) {
+ ESP_LOGD("yambms_auto_eoc", "Stopping charge current increase, SoC is above threshold");
+ stop_increasing = true;
+ } else if (hours_left <= id(yambms${yambms_id}_auto_eoc_stop_hours).state) {
+ ESP_LOGD("yambms_auto_eoc", "Stopping charge current increase, hours left is below threshold");
+ stop_increasing = true;
}
// Get battery capacity