Skip to content

Conversation

@vuka1
Copy link

@vuka1 vuka1 commented Sep 28, 2025

Summary

Add support for APsystems EHZI micro hybrid inverter with integrated battery storage and control capabilities.

Hardware Details

  • Device: APsystems EHZI micro hybrid inverter
  • Battery: 2.4kWh integrated battery storage
  • Firmware: Tested with v1.1.4.5
  • API: HTTP-based communication via local network

Features

  • Battery monitoring: Real-time power, SOC, and energy values
  • Battery control: Normal/Hold/Charge modes via setPower API
  • Localization: German and English descriptions
  • Hardware tested: Live testing with physical device at 192.168.20.8

Technical Implementation

  • HTTP API endpoints: /getOutputData and /setPower
  • Power values correctly inverted for evcc battery conventions (negative = charging)
  • Dynamic energy calculation based on SOC and configurable capacity
  • Configurable power limits with EHZI's dynamic limitation handling

Testing

  • ✅ Template validation with evcc --template-type meter
  • ✅ Documentation generation with make docs
  • ✅ Real-world testing in Home Assistant environment
  • ✅ Battery charging/discharging cycles verified
  • ✅ All battery control modes functional

Comparison to existing APsystems templates

This EHZI template differs from the existing EZ1 template as:

  • EHZI = Hybrid inverter with battery storage + control
  • EZ1 = PV-only inverter without battery capabilities

- Add support for APsystems EHZI micro hybrid inverter with 2.4kWh battery
- Support battery monitoring (power, SOC, energy) via HTTP API
- Include battery control capabilities (normal/hold/charge modes)
- Tested with hardware at 192.168.20.8, firmware 1.1.4.5
- Power values correctly inverted for evcc battery conventions
- Template includes German and English localization
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New security issues found

@andig andig added the devices Specific device support label Sep 28, 2025
@vuka1 vuka1 force-pushed the feature/apsystems-ehzi-template branch from 73b4868 to 199a850 Compare September 28, 2025 11:02
@andig andig changed the title feat: add APsystems EHZI micro hybrid inverter battery template Add APsystems EHZI micro hybrid battery inverter Sep 28, 2025
- Remove trailing spaces from German description
- Add newline at end of file to satisfy CI formatting checks
@vuka1
Copy link
Author

vuka1 commented Sep 28, 2025

I only have the battery connected to my EHZI inverter (no PV panels attached). Is anyone actively using this inverter with PV panels who could help add/ test the template in that configuration?

-- bug in setpower case 1: what variable to use to get the needed watt the inverter should charge / decharge (P=...)?

@vuka1 vuka1 force-pushed the feature/apsystems-ehzi-template branch 2 times, most recently from 7835fd1 to 32d4980 Compare September 28, 2025 19:26
@vuka1
Copy link
Author

vuka1 commented Oct 1, 2025

I cannot find a variable to set the batterie charging / decharging watt's. Is a formula within the template is acceptable?

      cmd: sh -c 'data=$(curl -s --max-time 3 http://127.0.0.1:{{ .evccport }}/api/state); home=$(echo "$data" | jq -r ".homePower // 0"); pv=$(echo "$data" | jq -r ".pvPower // 0"); power=$(echo "$home - $pv" | bc); max={{ .maxpower }}; min=$((- max)); if (( $(echo "$power > $max" | bc -l) )); then power=$max; elif (( $(echo "$power < $min" | bc -l) )); then power=$min; fi; curl -s --max-time 3 "http://{{ .host }}/setPower?p=$power" >/dev/null 2>&1'

Add template for APsystems EHZI hybrid inverter with battery control support.
This enables dynamic battery power management for the EHZI system.

## How the EHZI works:
The APsystems EHZI is a hybrid inverter that combines PV generation, battery storage,
and grid connection. Battery power control is done via HTTP endpoint:
- GET http://<host>/getOutputData - reads battery power (batP), SoC (batSoc), and system status
- GET http://<host>/setPower?p=<watts> - sets battery charge/discharge power
  - Positive values = discharge (battery supplies power to home)
  - Negative values = charge (battery takes power from grid/PV)
  - Value 0 = hold (no charge/discharge)

The EHZI dynamically limits actual power based on battery SoC, temperature, and
grid conditions, so requested power may differ from actual power.

## Template features:
- Dynamic power matching: Calculates net home demand (homePower - pvPower) and
  adjusts battery power every watchdog/2 seconds to minimize grid usage
- SoC limits: Respects minsoc (minimum SoC for discharge) and maxsoc (maximum SoC for charge)
- Battery modes: normal (dynamic), hold (maintain SoC), charge (force charge from grid)
- HTTP caching (5s) for faster UI validation and reduced API calls
- Watchdog-based continuous power adjustment in normal mode

## Configuration:
The template requires one-time activation via evcc UI after adding the battery:
1. Open evcc web interface
2. Click on battery icon or go to Settings
3. Enable "Battery Discharge Control" or set battery mode to "Normal"
4. Watchdog will then run automatically every watchdog/2 seconds

## Known issues and limitations:

### CRITICAL - PV integration missing:
The current implementation does NOT consider PV excess power for battery charging.
Template only does discharge management (home consumption from battery), but lacks
logic to charge battery from PV surplus. This needs to be added.

### Watchdog stability issues:
- Watchdog occasionally crashes/stops running without error messages
- Root cause unknown - possibly related to evcc's watchdog implementation or
  script execution failures (curl timeouts, bc calculation errors)
- Requires manual reactivation via UI when this occurs
- Frequency: Sporadic, not reliably reproducible

### SoC limits not always enforced:
- Intermittent issues where battery discharges below minsoc or charges above maxsoc
- Possibly related to watchdog script execution timing or race conditions
- SoC checks happen in script: if soc <= minsoc, then power=0
- May fail if batterySoc value from API is stale/cached when script runs
- Workaround: Lower safety margin (e.g., minsoc=15 instead of 10)

### Power value retrieval architecture:
The current approach to get home/pv power values is problematic:
```bash
data=$(curl http://127.0.0.1:7070/api/state)
home=$(echo "$data" | jq -r ".homePower // 0")
pv=$(echo "$data" | jq -r ".pvPower // 0")
soc=$(echo "$data" | jq -r ".batterySoc // 50")
```

Issues:
- Multiple JSON parsing operations in shell script (slow, fragile)
- No direct variable access - must query full API state
- Requires curl, jq, bc in system PATH
- Complex calculation logic in shell with bc: echo "$home - $pv" | bc
- Difficult to debug when values are incorrect

Better approach would be:
- Template variables that expose homePower, pvPower, batterySoc directly
- Native calculation support in template engine instead of shell scripts
- Or: dedicated plugin type for dynamic battery control with built-in variables

## Testing:
- Tested with EHZI at 192.168.20.8, 2.4kWh battery capacity
- Verified SoC limits (minsoc=45%, maxsoc=50%) work when watchdog is running
- Confirmed power calculation: homePower - pvPower = battery setpoint
- Verified EHZI power sign convention: batP negative = discharge, positive = charge
  (reversed from evcc convention, template uses * -1 to convert)
- HTTP cache reduces UI validation time from 12s to ~4s

## Next steps:
1. Fix PV excess charging logic - battery should charge when pvPower > homePower
2. Investigate watchdog stability issues - add error handling and logging
3. Improve SoC limit enforcement - consider adding hysteresis or safety margins
4. Refactor power value retrieval - propose template engine enhancement or
   create dedicated battery controller plugin type

Related: #<issue-number-if-exists>
Fixes: #<issue-number-if-exists>
@vuka1 vuka1 marked this pull request as draft October 2, 2025 07:01
@github-actions github-actions bot added the stale Outdated and ready to close label Oct 9, 2025
@github-actions github-actions bot closed this Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devices Specific device support stale Outdated and ready to close

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants