Repository navigation
Commit 0c51d16
fix: CRITICAL - Smart Blocker incorrectly blocking charger during daytime (v0.9.12)
CRITICAL BUG: Smart Blocker was blocking charger at 1:44 PM with reason "Nighttime (after sunset)"
USER REPORT:
Logs showed at 1:44 PM (daytime):
"Reason: Charger switch turned ON - Nighttime (after sunset)"
"Blocking still required: Nighttime (after sunset)"
User asked: "why did you block the charger?"
Answer: Because nighttime detection logic was COMPLETELY BROKEN!
ROOT CAUSE:
The _is_nighttime() method used flawed OR logic:
```python
is_night = now >= sunset or now < sunrise
```
At 1:44 PM:
- now >= sunset? NO (sunset is ~6 PM)
- now < sunrise? YES! (1:44 PM < 7:00 AM sunrise from this morning)
- Result: TRUE (incorrectly detected as nighttime)
This OR logic was fundamentally broken because it compared current time against
BOTH today's sunset AND today's (already passed) sunrise, causing ANY time
before sunset to be considered "before sunrise" = nighttime!
THE FIX:
Replaced OR logic with proper time-range logic:
```python
if now < sunset:
# Before sunset - check if we're still in nighttime from yesterday
# (i.e., before today's sunrise)
today_sunrise = get_astral_event_date(self.hass, "sunrise", now)
is_night = now < today_sunrise if today_sunrise else False
else:
# After sunset - we're in nighttime
is_night = True
```
Now correctly identifies:
- 1:44 PM (after sunrise 7 AM, before sunset 6 PM) → Daytime ✅
- 8:00 PM (after sunset) → Nighttime ✅
- 6:00 AM (before sunrise) → Nighttime ✅
IMPACT:
✅ Smart Blocker no longer blocks during daytime
✅ Charger can start with solar surplus during the day
✅ Smart Blocker still provides safety blocking at actual nighttime
✅ Resolves endless enforcement loop preventing solar surplus charging
✅ User's 1:44 PM solar surplus charging will now work
TESTING SCENARIOS:
Before fix:
- 1:44 PM: Blocked (❌ wrong - it's daytime!)
- 10:00 AM: Blocked (❌ wrong - it's daytime!)
- 2:00 PM: Blocked (❌ wrong - it's daytime!)
After fix:
- 1:44 PM: Allowed ✅ (correct - daytime)
- 10:00 AM: Allowed ✅ (correct - daytime)
- 8:00 PM: Blocked ✅ (correct - nighttime)
- 6:00 AM: Blocked ✅ (correct - nighttime)
Files Changed:
- custom_components/ev_smart_charger/automations.py (lines 294-309)
- custom_components/ev_smart_charger/manifest.json (version 0.9.12)
- README.md (version + changelog)
🎯 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 355f849 commit 0c51d16
3 files changed
Lines changed: 53 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
729 | 729 | | |
730 | 730 | | |
731 | 731 | | |
732 | | - | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
733 | 769 | | |
734 | 770 | | |
735 | 771 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
303 | 309 | | |
304 | 310 | | |
305 | 311 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
0 commit comments