Skip to content

Commit 52d2fcd

Browse files
Antonio ...claude
andcommitted
fix: Treat charger as 0A when OFF to enable proper start logic in EV_FREE mode (v0.9.10)
CRITICAL FIX: Charger now starts correctly when OFF during EV_FREE priority with solar surplus. USER INSIGHT: User correctly identified: "If priority switches from HOME to EV_FREE it should start charging" This revealed that v0.9.9 was incomplete - only fixed early return, not the comparison logic. ROOT CAUSE: When charger is OFF, the system was reading the stored amperage setting (e.g., 16A from previous session) instead of treating the OFF state as 0A for comparison purposes. Scenario that failed: 1. Priority = HOME → EV charger STOPPED (home battery charging) 2. Priority switches to EV_FREE → both targets met, solar surplus available (6000W) 3. System reads current_amps = 16A (stored setting) 4. Calculates target_amps = 26A (from solar surplus) 5. Comparison: 26A > 16A = TRUE → should start (CORRECT) BUT if surplus was lower: 3. System reads current_amps = 16A (stored setting) 4. Calculates target_amps = 6A (low solar surplus) 5. Comparison: 6A > 16A = FALSE → no action taken (WRONG - should have started at 6A) THE COMPLETE FIX: Modified solar_surplus.py lines 557-573 to check charger switch state BEFORE reading amperage: - If charger is ON: Read actual amperage from sensor (normal operation) - If charger is OFF: Set current_amps = 0 (allows any surplus to trigger start) Now the comparison at line 677 works correctly: - target_amps (6A or 26A) > current_amps (0A) = TRUE - Calls _set_amperage() which starts charger at target amperage IMPACT: ✅ Priority transitions HOME → EV_FREE now start charging automatically ✅ Fresh installations with charger OFF now work correctly ✅ ALL surplus levels (even 6A minimum) trigger charger start when OFF ✅ Proper state machine: OFF (0A) → any surplus → ON at calculated amperage This completes the fix started in v0.9.9 (fall-through logic) with proper amperage handling. Files Changed: - custom_components/ev_smart_charger/solar_surplus.py (lines 557-573) - custom_components/ev_smart_charger/manifest.json (version 0.9.10) - README.md (version + detailed changelog explaining both fixes) 🎯 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a9f6940 commit 52d2fcd

3 files changed

Lines changed: 53 additions & 10 deletions

File tree

‎README.md‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A Home Assistant integration for intelligent EV charging control based on solar production, time of day, and battery levels.
44

5-
## Current Version: 0.9.9
5+
## Current Version: 0.9.10
66

77
[![GitHub Release](https://img.shields.io/github/v/release/antbald/ha-ev-smart-charger)](https://github.com/antbald/ha-ev-smart-charger/releases)
88
[![hacs_badge](https://img.shields.io/badge/HACS-Custom-orange.svg)](https://github.com/custom-components/hacs)
@@ -729,7 +729,42 @@ Then restart Home Assistant.
729729

730730
## Changelog
731731

732-
### v0.9.9 (2025-10-29) - Current - EV_FREE Solar Surplus Charging Fix
732+
### v0.9.10 (2025-10-29) - Current - Critical: Charger Start Fix in EV_FREE Mode
733+
- **FIX: Charger now treats amperage as 0 when OFF, enabling proper start logic**
734+
- **Critical Issue**: When charger was OFF, `current_amps` was read from charger setting (e.g., 16A from previous session)
735+
- Solar surplus logic compared `target_amps` (e.g., 26A) vs `current_amps` (16A) → triggered increase (correct)
736+
- BUT if `target_amps` (6A) < `current_amps` (16A), charger would NOT start despite having surplus
737+
- **v0.9.9 incomplete fix**: Only removed early return, didn't fix amperage comparison
738+
739+
- **Root Cause Identified:**
740+
- User correctly pointed out: "If priority switches from HOME to EV_FREE, it should start charging"
741+
- When Priority Balancer transitions HOME → EV_FREE, charger is OFF (was stopped for home battery)
742+
- Solar surplus available (6000W = 26A), but comparison logic failed because charger OFF state not handled
743+
- System read stored amperage setting instead of treating OFF charger as 0A
744+
745+
- **Complete Fix:**
746+
- Modified amperage detection logic (lines 557-573) to check charger switch state FIRST
747+
- If charger is **ON**: Read actual amperage from sensor (normal operation)
748+
- If charger is **OFF**: Set `current_amps = 0` (allows ANY surplus to trigger start)
749+
- Now comparison works correctly: `target_amps (26A) > current_amps (0A)` = TRUE → starts charger
750+
751+
- **Impact:**
752+
- **Priority transitions now work**: HOME → EV_FREE automatically starts charging with available solar
753+
- **Fresh installations work**: Charger OFF + solar surplus → starts automatically
754+
- **All surplus levels work**: Even low surplus (6A) will start charger when OFF
755+
- **Proper state machine**: OFF (0A) → any surplus → ON at target amperage
756+
757+
- **Technical Details:**
758+
- Added charger switch state check before reading amperage
759+
- Treats OFF charger as 0A for comparison logic
760+
- Ensures line 677 condition `target_amps > current_amps` always evaluates correctly
761+
- Complements v0.9.9 EV_FREE fall-through fix
762+
763+
- **Files Modified:**
764+
- `solar_surplus.py` - Amperage detection logic (lines 557-573)
765+
- `manifest.json` - Version 0.9.10
766+
767+
### v0.9.9 (2025-10-29) - EV_FREE Solar Surplus Charging Fix (Incomplete)
733768
- **FIX: EV_FREE priority now allows solar surplus charging when charger is OFF**
734769
- Previously, when Priority Balancer set priority to EV_FREE (both EV and home battery targets met), the automation would stop charging if charger was ON and then exit early
735770
- This prevented the charger from starting when it was OFF, even with abundant solar surplus available

‎custom_components/ev_smart_charger/manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"domain": "ev_smart_charger",
33
"name": "EV Smart Charger",
4-
"version": "0.9.9",
4+
"version": "0.9.10",
55
"documentation": "https://github.com/antbald/ha-ev-smart-charger",
66
"issue_tracker": "https://github.com/antbald/ha-ev-smart-charger/issues",
77
"codeowners": ["@antbald"],

‎custom_components/ev_smart_charger/solar_surplus.py‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -554,15 +554,23 @@ async def _async_periodic_check(self, now=None) -> None:
554554
_LOGGER.info("=" * 80)
555555
return
556556

557-
# Get current amperage setting
558-
current_setting_state = self.hass.states.get(self._charger_current)
559-
if current_setting_state:
560-
try:
561-
current_amps = int(float(current_setting_state.state))
562-
except (ValueError, TypeError):
557+
# Get current amperage - treat as 0 if charger is OFF
558+
charger_state = self.hass.states.get(self._charger_switch)
559+
charger_is_on = charger_state and charger_state.state == "on"
560+
561+
if charger_is_on:
562+
# Charger is ON, get actual amperage setting
563+
current_setting_state = self.hass.states.get(self._charger_current)
564+
if current_setting_state:
565+
try:
566+
current_amps = int(float(current_setting_state.state))
567+
except (ValueError, TypeError):
568+
current_amps = 6
569+
else:
563570
current_amps = 6
564571
else:
565-
current_amps = 6
572+
# Charger is OFF, treat as 0A (allows any surplus to start it)
573+
current_amps = 0
566574

567575
# Calculate surplus
568576
surplus_watts = fv_production - home_consumption

0 commit comments

Comments
 (0)