Skip to content

Commit 67d23d8

Browse files
author
Antonio ...
committed
fix: Critical Night Smart Charge sunrise termination bug (v1.3.17)
CRITICAL BUG FIX: Night charging could continue indefinitely past sunrise Root Cause Analysis: - BATTERY mode had monitoring loop but NO sunrise termination check - GRID mode had NO monitoring loop at all (zero autonomous stop conditions) - Active sessions bypassed periodic window checks - User reported charging notification at 08:40 AM (90 min after sunrise) Changes Made: 1. BATTERY Mode Enhanced - Added sunrise check to existing monitoring loop (every 15s) - Stops immediately when window closes (sunrise occurs) - Maintains existing home battery SOC and EV target checks 2. GRID Mode Monitoring Loop Created (NEW) - Complete monitoring loop added (previously missing) - Checks every 15 seconds for: * Sunrise termination (window closed) * EV target SOC reached * Charger status validation - Registered in _start_grid_charge() 3. Periodic Check Enhanced - Active sessions now re-validate window validity - Prevents sunrise bypass for running sessions - Terminates sessions detected outside valid window 4. Enhanced Logging - Detailed window comparison logging (Now >= Scheduled, Now < Sunrise) - Debug-level logging for frequent monitoring checks - Helps diagnose future window-related issues Stop Conditions Fixed: - BATTERY mode: Now stops at sunrise ✅ (was missing ❌) - GRID mode: Now stops at sunrise ✅ (was missing ❌) - GRID mode: Now stops when EV target reached ✅ (was missing ❌) Technical Details: - Added _grid_monitor_unsub timer tracking - Both modes check _is_in_active_window() every 15s - Session completion cancels both monitoring loops - Grid monitoring uses same 15s interval as battery mode Files Modified: - night_smart_charge.py: Added GRID monitoring loop, sunrise checks - const.py: VERSION = "1.3.17" - manifest.json: version = "1.3.17" - CLAUDE.md: Release notes with detailed analysis - NIGHT_CHARGE_SCENARIOS.md: Complete scenario documentation User Impact: 🔴 URGENT UPGRADE - Prevents: - Night charging continuing past sunrise - Unexpected grid charging when solar available - Overcharging when EV target already reached Related: User bug report (08:40 AM charging notification)
1 parent 95d6c03 commit 67d23d8

5 files changed

Lines changed: 744 additions & 8 deletions

File tree

CLAUDE.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
77
This is a **Home Assistant custom integration** for intelligent EV charging control. It manages EV charger automation based on solar production, time of day, battery levels, grid import protection, and intelligent priority balancing between EV and home battery charging.
88

99
**Domain:** `ev_smart_charger`
10-
**Current Version:** 1.3.14
10+
**Current Version:** 1.3.17
1111
**Installation:** HACS custom repository or manual installation to `custom_components/ev_smart_charger`
1212

1313
## Development Commands
@@ -753,6 +753,72 @@ async def _set_amperage(self, target_amperage: int):
753753

754754
## Version History
755755

756+
### v1.3.17 (2025-11-06)
757+
**CRITICAL: Night Smart Charge Sunrise Termination Fix**
758+
- **🚨 Critical Bug Fixed**: Night charging could continue indefinitely past sunrise
759+
- **Root Cause**: Missing sunrise termination logic in both BATTERY and GRID modes
760+
- **Reported Issue**: User received charging notification at 08:40 AM (1.5 hours after sunrise)
761+
762+
**Changes Made**:
763+
764+
1. **BATTERY Mode Enhanced** ([night_smart_charge.py:516-521](custom_components/ev_smart_charger/night_smart_charge.py#L516-L521))
765+
- Added sunrise check to monitoring loop (runs every 15 seconds)
766+
- Now stops immediately when sunrise occurs
767+
- Previous behavior: Only checked home battery SOC and EV target
768+
769+
2. **GRID Mode Monitoring Loop Created** ([night_smart_charge.py:559-611](custom_components/ev_smart_charger/night_smart_charge.py#L559-L611))
770+
- NEW: Created complete monitoring loop for GRID mode (previously had NONE)
771+
- Checks every 15 seconds for:
772+
- Sunrise termination
773+
- EV target SOC reached
774+
- Charger status validation
775+
- Previous behavior: NO monitoring at all (relied on user intervention or wallbox 100% limit)
776+
777+
3. **Periodic Check Window Re-validation** ([night_smart_charge.py:233-244](custom_components/ev_smart_charger/night_smart_charge.py#L233-L244))
778+
- Active sessions now re-validated for window validity
779+
- Prevents active sessions from bypassing sunrise check
780+
- Previous behavior: Active sessions skipped all checks
781+
782+
4. **Enhanced Window Validation Logging** ([night_smart_charge.py:330-349](custom_components/ev_smart_charger/night_smart_charge.py#L330-L349))
783+
- Added detailed comparison logging (Now >= Scheduled, Now < Sunrise)
784+
- Debug-level logging for frequent monitoring checks
785+
- Helps diagnose future window-related issues
786+
787+
**Stop Conditions Summary**:
788+
789+
| Mode | Sunrise | EV Target | Home Battery Min | Manual/Unplug |
790+
|------|---------|-----------|------------------|---------------|
791+
| BATTERY (v1.3.16) | ❌ Missing | ✅ Yes | ✅ Yes | ✅ Yes |
792+
| BATTERY (v1.3.17) |**FIXED** | ✅ Yes | ✅ Yes | ✅ Yes |
793+
| GRID (v1.3.16) | ❌ Missing | ❌ Missing | N/A | ✅ Yes only |
794+
| GRID (v1.3.17) |**FIXED** |**FIXED** | N/A | ✅ Yes |
795+
796+
**Technical Details**:
797+
- Added `_grid_monitor_unsub` timer for GRID mode monitoring
798+
- Both modes now check `_is_in_active_window()` every 15 seconds
799+
- Session completion properly cancels both monitoring loops
800+
- Grid monitoring registered in `_start_grid_charge()` (line 643-651)
801+
802+
**Example Fixed Scenario**:
803+
```
804+
01:00 AM - GRID mode starts (forecast insufficient, car_ready=True)
805+
03:00 AM - EV at 50%, target 80% (still charging...)
806+
07:00 AM - 🌅 SUNRISE - **NOW STOPS IMMEDIATELY** (previously continued)
807+
```
808+
809+
**User Impact**:
810+
- 🔴 **URGENT UPGRADE** - Night charging will no longer continue past sunrise
811+
- Prevents unexpected grid charging during day when solar available
812+
- Prevents overcharging when EV target already reached
813+
814+
**Files Modified**:
815+
- [night_smart_charge.py](custom_components/ev_smart_charger/night_smart_charge.py): Added GRID monitoring loop, sunrise checks in both modes
816+
- [const.py](custom_components/ev_smart_charger/const.py): VERSION = "1.3.17"
817+
- [manifest.json](custom_components/ev_smart_charger/manifest.json): version = "1.3.17"
818+
819+
**Related Documentation**:
820+
- Complete scenario analysis: [NIGHT_CHARGE_SCENARIOS.md](NIGHT_CHARGE_SCENARIOS.md)
821+
756822
### v1.3.16 (2025-11-05)
757823
**Throttled Logging for Sensor Errors**
758824
- **Problem Fixed**: When sensors become unavailable (e.g., `unknown` state), Solar Surplus logged errors every minute, causing log spam (200+ messages)

0 commit comments

Comments
 (0)