feat: Major update - Battery Optimizer v3.4.0 with comprehensive fixes

## 🎯 Hauptänderungen

### Version 3.4.0 - SOC-Drift & Charging Capacity
-  Sicherheitspuffer (20-50% konfigurierbar) für untertägige SOC-Schwankungen
-  Monatliche automatische Batterie-Kalibrierung
- 🐛 SOC-Plausibilitäts-Check (filtert 65535% Spikes beim Modus-Wechsel)
- 🐛 Zeitabhängige API-Abfrage (vor/nach 14:00 Uhr)

### Neue Features
- 🔋 **Safety Buffer**: Kompensiert SOC-Drift und Eigenverbrauch
- 🔋 **Auto-Calibration**: Monatlicher Vollzyklus für SOC-Genauigkeit
- 🔋 **Spike Protection**: 4-fach Schutz gegen ungültige SOC-Werte
- 🔋 **Smart API**: Verhindert HTTP 500 Errors bei fehlenden Tomorrow-Preisen

### Dokumentation
- 📚 SOC_CALIBRATION_GUIDE.md - Umfassender Kalibrierungs-Guide
- 📚 FIX_CHARGING_CAPACITY.md - Sicherheitspuffer-Dokumentation
- 📚 FIX_SOC_SPIKE_PROBLEM.md - Spike-Protection-Lösung
- 📚 FIX_API_TIMING.md - Zeitabhängige API-Abfrage
- 📚 DIAGNOSE_LADE_PROBLEM.md - Debug-Guide

### Neue Dateien
- battery_calibration_automation.yaml - 4 Automations für Kalibrierung
- battery_calibration_input_helper.yaml - Input Helper Config
- battery_optimizer_input_helper_safety_buffer.yaml - Puffer Config
- debug_schedule.py - Umfassendes Debug-Script

### Scripts
- battery_charging_optimizer.py v3.4.0
- hastrom_flex_extended.py v1.1.0
- debug_schedule.py v1.0.0

### Fixes
- 🐛 SOC springt auf 65535% beim ESS-Modus-Wechsel → Debounce + Plausibilitäts-Check
- 🐛 API-HTTP-500 vor 14:00 → Zeitabhängige Abfrage
- 🐛 Batterie nicht bis 100% geladen → Sicherheitspuffer
- 🐛 SOC driftet ohne Vollzyklen → Automatische Kalibrierung

## 🚀 Installation

1. Input Helper erstellen (siehe battery_optimizer_input_helper_safety_buffer.yaml)
2. Automations installieren (siehe battery_calibration_automation.yaml)
3. Scripts aktualisieren (battery_charging_optimizer.py v3.4.0)
4. PyScript neu laden

## 📊 Verbesserungen

- Präzisere Ladeplanung durch Sicherheitspuffer
- Robustheit gegen SOC-Drift
- Keine API-Fehler mehr vor 14:00
- Hardware-Stopp bei 100% wird respektiert
- Bessere Batterie-Gesundheit durch regelmäßige Kalibrierung

🤖 Generated with Claude Code (claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
felix.zoesch
2025-12-12 08:04:07 +01:00
parent 5ab422426f
commit 0fa03a566a
90 changed files with 22002 additions and 0 deletions

237
entity_validation_report.md Normal file
View File

@@ -0,0 +1,237 @@
# Home Assistant Entity Validation Report
Generated: 2025-11-19
## Summary
This report analyzes all entity references in the OpenEMS battery optimizer configuration files and validates their existence in the Home Assistant system.
---
## Files Analyzed
1. `/Users/felix/Nextcloud/AI/projects/homeassistant/openems/v1/battery_optimizer_rest_commands.yaml`
2. `/Users/felix/Nextcloud/AI/projects/homeassistant/openems/v1/battery_optimizer_config.yaml`
3. `/Users/felix/Nextcloud/AI/projects/homeassistant/openems/v1/battery_optimizer_dashboard.yaml`
4. `/Users/felix/Nextcloud/AI/projects/homeassistant/openems/v1/battery_optimizer_automations.yaml`
5. `/Users/felix/Nextcloud/AI/projects/homeassistant/openems/v1/automation_hourly_execution_DRINGEND.yaml`
6. `/Users/felix/Nextcloud/AI/projects/homeassistant/openems/v2/battery_optimizer_dashboard.yaml`
7. `/Users/felix/Nextcloud/AI/projects/homeassistant/openems/v2/battery_optimizer_config.yaml`
8. `/Users/felix/Nextcloud/AI/projects/homeassistant/openems/v3/battery_optimizer_dashboard.yaml`
9. `/Users/felix/Nextcloud/AI/projects/homeassistant/openems/v3/battery_optimizer_dashboard_minimal.yaml`
10. `/Users/felix/Nextcloud/AI/projects/homeassistant/openems/v3/battery_optimizer_sections_minimal.yaml`
11. `/Users/felix/Nextcloud/AI/projects/homeassistant/openems/v3/battery_optimizer_dashboard_compact.yaml`
12. `/Users/felix/Nextcloud/AI/projects/homeassistant/openems/v3/battery_optimizer_sections_compact.yaml`
13. `/Users/felix/Nextcloud/AI/projects/homeassistant/openems/v3/battery_optimizer_sections_standard.yaml`
14. `/Users/felix/Nextcloud/AI/projects/homeassistant/openems/battery_optimizer_config.yaml`
15. `/Users/felix/Nextcloud/AI/projects/homeassistant/openems/rest_requests.yaml`
---
## Entity References by Category
### Input Boolean Entities
| Entity ID | File(s) | Status |
|-----------|---------|--------|
| `input_boolean.battery_optimizer_enabled` | v1/config.yaml (defined), v1/dashboard.yaml, v1/automations.yaml, v2/dashboard.yaml, v2/config.yaml (defined), v3/all dashboards, openems/config.yaml (defined) | **DEFINED** ✓ |
| `input_boolean.battery_optimizer_manual_override` | v1/config.yaml (defined), v1/dashboard.yaml, v1/automations.yaml, v2/dashboard.yaml, v2/config.yaml (defined), openems/config.yaml (defined) | **DEFINED** ✓ |
| `input_boolean.goodwe_manual_control` | v2/dashboard.yaml, v3/all dashboards | **NEEDS VERIFICATION** ⚠️ |
### Input Number Entities
| Entity ID | File(s) | Status |
|-----------|---------|--------|
| `input_number.battery_optimizer_min_soc` | v1/config.yaml (defined), v1/dashboard.yaml, v1/automations.yaml, v2/config.yaml (defined), openems/config.yaml (defined) | **DEFINED** ✓ |
| `input_number.battery_optimizer_max_soc` | v1/config.yaml (defined), v1/dashboard.yaml, v2/config.yaml (defined), openems/config.yaml (defined) | **DEFINED** ✓ |
| `input_number.battery_optimizer_price_threshold` | v1/config.yaml (defined), v1/dashboard.yaml, v2/config.yaml (defined), openems/config.yaml (defined) | **DEFINED** ✓ |
| `input_number.battery_optimizer_max_charge_power` | v1/config.yaml (defined), v1/dashboard.yaml, v2/config.yaml (defined), openems/config.yaml (defined) | **DEFINED** ✓ |
| `input_number.battery_optimizer_reserve_capacity` | v1/config.yaml (defined), v1/dashboard.yaml, v2/config.yaml (defined), openems/config.yaml (defined) | **DEFINED** ✓ |
| `input_number.battery_optimizer_pv_threshold` | v2/dashboard.yaml, v2/config.yaml (defined), openems/config.yaml (defined) | **DEFINED** ✓ |
| `input_number.battery_capacity_kwh` | v2/dashboard.yaml, v2/config.yaml (defined), openems/config.yaml (defined) | **DEFINED** ✓ |
| `input_number.charge_power_battery` | v2/dashboard.yaml | **NEEDS VERIFICATION** ⚠️ |
| `input_number.battery_min_soc` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `input_number.battery_max_soc` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `input_number.battery_charging_power` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `input_number.battery_reserve_capacity` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `input_number.battery_price_threshold` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
### Input Select Entities
| Entity ID | File(s) | Status |
|-----------|---------|--------|
| `input_select.battery_optimizer_strategy` | v1/config.yaml (defined), v1/dashboard.yaml | **DEFINED** ✓ |
### Input Text Entities
| Entity ID | File(s) | Status |
|-----------|---------|--------|
| `input_text.battery_optimizer_status` | v2/dashboard.yaml, v2/config.yaml (defined), openems/config.yaml (defined) | **DEFINED** ✓ |
### Sensor Entities
| Entity ID | File(s) | Status |
|-----------|---------|--------|
| `sensor.battery_state_of_charge` | v1/dashboard.yaml | **NEEDS VERIFICATION** ⚠️ |
| `sensor.nächste_ladestunde` | v1/dashboard.yaml | **TEMPLATE SENSOR** - defined as template ✓ |
| `sensor.geplante_ladungen_heute` | v1/dashboard.yaml | **TEMPLATE SENSOR** - defined as template ✓ |
| `sensor.hastrom_flex_pro` | v1/config.yaml, v1/dashboard.yaml, v1/automations.yaml | **NEEDS VERIFICATION** ⚠️ |
| `sensor.durchschnittspreis_heute` | v1/dashboard.yaml | **TEMPLATE SENSOR** - defined as template ✓ |
| `sensor.pv_power` | v1/dashboard.yaml | **NEEDS VERIFICATION** ⚠️ |
| `sensor.battery_power` | v1/dashboard.yaml, v2/dashboard.yaml | **NEEDS VERIFICATION** ⚠️ |
| `sensor.house_consumption` | v1/dashboard.yaml | **NEEDS VERIFICATION** ⚠️ |
| `sensor.gw_netzbezug` | v1/dashboard.yaml | **NEEDS VERIFICATION** ⚠️ |
| `sensor.gw_netzeinspeisung` | v1/dashboard.yaml | **NEEDS VERIFICATION** ⚠️ |
| `sensor.today_s_pv_generation` | v1/dashboard.yaml | **NEEDS VERIFICATION** ⚠️ |
| `sensor.energy_production_tomorrow` | v1/dashboard.yaml | **NEEDS VERIFICATION** ⚠️ |
| `sensor.energy_production_tomorrow_2` | v1/dashboard.yaml | **NEEDS VERIFICATION** ⚠️ |
| `sensor.today_battery_charge` | v1/dashboard.yaml | **NEEDS VERIFICATION** ⚠️ |
| `sensor.today_battery_discharge` | v1/dashboard.yaml | **NEEDS VERIFICATION** ⚠️ |
| `sensor.bought_from_grid_today` | v1/dashboard.yaml | **NEEDS VERIFICATION** ⚠️ |
| `sensor.sold_to_grid_today` | v1/dashboard.yaml | **NEEDS VERIFICATION** ⚠️ |
| `sensor.openems_ess0_soc` | v2/dashboard.yaml | **NEEDS VERIFICATION** ⚠️ |
| `sensor.openems_ess0_activepower` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `sensor.openems_grid_activepower` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `sensor.openems_production_activepower` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `sensor.openems_consumption_activepower` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `sensor.esssoc` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `sensor.hastrom_flex_extended_current_price` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `sensor.battery_charging_plan_status` | v2/dashboard.yaml, v3/dashboards, openems/config.yaml (defined) | **DEFINED** ✓ |
| `sensor.battery_next_action` | v2/config.yaml (defined), openems/config.yaml (defined) | **DEFINED** ✓ |
| `sensor.battery_estimated_savings` | v2/config.yaml (defined), openems/config.yaml (defined) | **DEFINED** ✓ |
| `sensor.battery_next_charge_time` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `sensor.openems_state` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `sensor.battery_capacity` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `sensor.openems_ess0_capacity` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `sensor.forecast_solar_energy_today` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `sensor.forecast_solar_energy_tomorrow` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
### Automation Entities
| Entity ID | File(s) | Status |
|-----------|---------|--------|
| `automation.battery_charging_schedule_calculation` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
| `automation.battery_charging_schedule_execution` | v3/dashboards | **NEEDS VERIFICATION** ⚠️ |
### PyScript State Entities
| Entity ID | File(s) | Status |
|-----------|---------|--------|
| `pyscript.battery_charging_schedule` | v1/config.yaml, v1/dashboard.yaml, openems/config.yaml | **PYSCRIPT ENTITY** ✓ |
| `pyscript.battery_charging_plan` | v3/dashboards | **PYSCRIPT ENTITY** ✓ |
### REST Command Entities
| Entity ID | File(s) | Status |
|-----------|---------|--------|
| `rest_command.set_ess_remote_mode` | v1/rest_commands.yaml (defined), openems/rest_requests.yaml (defined) | **DEFINED** ✓ |
| `rest_command.set_ess_internal_mode` | v1/rest_commands.yaml (defined), openems/rest_requests.yaml (defined) | **DEFINED** ✓ |
---
## Issues Found
### 1. **Entity Name Inconsistencies**
Multiple versions use different entity naming conventions:
- **V1/V2**: Use `input_number.battery_optimizer_*` prefix
- **V3**: Use shortened `input_number.battery_*` prefix
- **OpenEMS root**: Uses `input_number.battery_optimizer_*` prefix
**Recommendation**: Standardize on one naming convention. Based on the root config file, `battery_optimizer_*` appears to be the canonical naming.
### 2. **Missing Entity Definitions**
The following entities are referenced but not defined in configuration files:
- `input_boolean.goodwe_manual_control`
- `input_number.charge_power_battery`
- All `input_number.battery_*` entities (shortened names in v3)
- Most OpenEMS sensors (`sensor.openems_*`, `sensor.esssoc`)
- haStrom price sensors (`sensor.hastrom_flex_pro`, `sensor.hastrom_flex_extended_current_price`)
- Forecast Solar sensors
- Battery status sensors
**These may be defined elsewhere in your Home Assistant configuration or created by integrations.**
### 3. **Template Sensor Dependencies**
Template sensors defined in config files depend on PyScript states that must exist:
```yaml
# Depends on: pyscript.battery_charging_schedule.schedule
sensor.battery_charging_plan_status
sensor.battery_next_action
sensor.battery_estimated_savings
```
### 4. **Dashboard References to Non-Existent Entities**
V3 dashboards reference entities with different names than those defined in the configuration:
**Dashboard uses**: `input_number.battery_min_soc`
**Config defines**: `input_number.battery_optimizer_min_soc`
This will cause errors in the dashboard rendering.
---
## Recommendations
### Priority 1: Name Standardization
Choose one naming convention and update all files:
**Option A (Recommended)**: Use full `battery_optimizer_*` names (matches root config)
- Update V3 dashboards to use `battery_optimizer_` prefix
**Option B**: Use shortened `battery_*` names
- Update root config file and V1/V2 files
- Update automations and PyScript references
### Priority 2: Verify Integration-Created Entities
Check that these integrations are properly configured:
1. **OpenEMS Modbus Integration** - Should create `sensor.openems_*` entities
2. **haStrom Integration** - Should create price sensors
3. **Forecast.Solar Integration** - Should create forecast sensors
### Priority 3: Create Missing Helper Entities
If not already created, add these to your configuration:
- `input_boolean.goodwe_manual_control`
- `input_number.charge_power_battery`
- Any `sensor.*` entities that aren't integration-provided
### Priority 4: PyScript State Verification
Ensure PyScript scripts are creating the expected states:
- `pyscript.battery_charging_schedule`
- `pyscript.battery_charging_plan`
---
## Testing Checklist
1. [ ] Load configuration files and check for YAML errors
2. [ ] Verify all `input_*` helpers exist in Home Assistant UI
3. [ ] Check Developer Tools → States for all referenced sensors
4. [ ] Verify PyScript states exist after running optimization
5. [ ] Test dashboard loading - check for "Entity not available" errors
6. [ ] Verify automations trigger correctly
7. [ ] Check Home Assistant logs for missing entity warnings
---
## Next Steps
To complete validation, I need access to your Home Assistant system to:
1. Query all existing entities via the ha-mcp-server
2. Cross-reference with this list
3. Provide a definitive "exists/missing" report
**Would you like me to:**
- Connect to your Home Assistant to verify which entities actually exist?
- Generate corrected configuration files with standardized names?
- Create a consolidated configuration that merges the best from each version?