Skip to main content

EG4 Inverter Python Client

Python License

eg4_python is a Python library that provides both async and sync methods to interact with the EG4 Inverter cloud API. It handles login, data retrieval, and session management efficiently — ideal for integration with Home Assistant, MCP, automation platforms, or custom monitoring solutions.

Caveats


Features

✅ Asynchronous and synchronous support (via asyncio and sync wrappers)
✅ Automatic re-authentication on session expiry (401 errors)
✅ Modular structure for future expandability
✅ Supports DISCOVERING multiple inverters from a single account


Installation

Using PyPI (Recommended)

pip install eg4_python

Development Version (Editable Mode)

git clone https://github.com/yourusername/eg4_python.git
cd eg4_python
pip install -e .[dev]  # For development and testing

Usage

Example Code

You can look at the "test" function in client.py

import asyncio
from eg4_python import EG4InverterAPI

async def main():
    api = EG4InverterAPI(username="username", password="password", base_url="https://monitor.eg4electronics.com")
    await api.login(ignore_ssl=True)

    # Display Inverters
    for index, inverter in enumerate(api.get_inverters()):
        print(f"Inverter {index}: {inverter}")

    print("Selecting Inverter 0")
    api.set_selected_inverter(inverterIndex=0)

    # Fetch Runtime Data
    runtime_data = await api.get_inverter_runtime_async()
    print("Runtime Data:", runtime_data)

    # Fetch Energy Data
    energy_data = await api.get_inverter_energy_async()
    print("Energy Data:", energy_data)

    # Fetch Battery Data
    battery_data = await api.get_inverter_battery_async()
    print("Battery Data:", battery_data)
    await api.close()

asyncio.run(main())

Configuration

Environment Variables (Recommended for Secrets)

Create a .env file:

USERNAME=your_username
PASSWORD=your_password
SERIAL_NUMBER=
PLANT_ID=
BASE_URL=https://monitor.eg4electronics.com

Example .env Loading in Code

import os
from dotenv import load_dotenv

load_dotenv()
USERNAME = os.getenv("USERNAME")
PASSWORD = os.getenv("PASSWORD")

API Methods

Authentication & Session Management

  • async def login() – Handles login and saves the JSESSIONID cookie. Accepts ignore_ssl=[true|false]
  • async def close() – Gracefully closes the HTTP session.

Setup

  • get_inverters() - list the inverters associated with the account, after login
  • set_selected_inverter(inverterIndex=index) - Selects an inverter from the list of inverters
  • set_selected_inverter(plantId=plantId, serialNum=serialNum) - Explicitly sets the selected inverter

Data Retrieval

  • async def get_inverter_runtime_async() – Retrieves inverter runtime data.
  • async def get_inverter_energy_async() – Retrieves inverter energy data.
  • async def get_inverter_battery_async() – Retrieves battery data, including individual battery units.

Parameters read/write

  • async def read_settings_async() – reads parameters.
  • async def write_settings_async() – writes a parameter value.

Sync Methods (Wrappers)

  • get_inverter_runtime()
  • get_inverter_energy()
  • get_inverter_battery()
  • read_settings()
  • write_settings()

Running Tests

Ensure you have development dependencies installed:

pip install -e .[dev]

Then run the test suite:

pytest tests/

Roadmap

  • ✅ Initial EG4 API implementation
  • ✅ Async/Sync support
  • ✅ Setting inverter values
  • 🔜 ...Full Home Assistant Integration
  • 🔜 ...You tell me

License

This project is licensed under the APACHE License. License


Contributing

Contributions are welcome! Please open issues, suggest improvements, or submit pull requests.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/awesome-feature)
  3. Commit your changes (git commit -m 'Add an awesome feature')
  4. Push to the branch (git push origin feature/awesome-feature)
  5. Open a Pull Request

Author

Garreth Jeremiah
GitHub Profile


Acknowledgments

Special thanks to DAB Ultimate beer!

Metadata

Release files for eg4-python 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for eg4-python 0.1.2
File Size Uploaded
eg4_python-0.1.2.tar.gz 18.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for eg4-python 0.1.2
File Interpreter ABI Platform
eg4_python-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 34.7 kB

Release files / eg4_python-0.1.2.tar.gz

Download URL eg4_python-0.1.2.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
50326fa09b3c6ee11b0daf06af0de5ab1b794a2504dc11ecf052321785f67ad0
BLAKE2b-256 checksum
How to use checksums
fb633f8712c339e3eb66eae9bea0b3e787bf1670c1202cde6f8d2da5fb5523c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / eg4_python-0.1.2-py3-none-any.whl

Download URL eg4_python-0.1.2-py3-none-any.whl
Size 16.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
631559e1045581761008f5184409f69d788fa5a2fde0d51569b6cf3b5cf37ba9
BLAKE2b-256 checksum
How to use checksums
eb515cc2320854e8e348de5328ce32b30ffb775519e73c83f6ae038d9b91c556
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page