Skip to main content

A Python API for interacting with EG4 Inverter systems.

Project description

EG4 Inverter API

Python License

eg4_inverter_api is a Python library that provides both async and sync methods to interact with the EG4 Inverter system API. It handles login, data retrieval, and session management efficiently — ideal for integration with Home Assistant, 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)
✅ Designed to integrate easily with Home Assistant
✅ Modular structure for future expandability
✅ Supports multiple inverters from a single account


Installation

Using PyPI (Recommended)

pip install eg4_inverter_api

Development Version (Editable Mode)

git clone https://github.com/yourusername/eg4_inverter_api.git
cd eg4_inverter_api
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_inverter_api import EG4InverterAPI

async def main():
    api = EG4InverterAPI("username", "password")
    await api.login()

    # 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.
  • async def close() – Gracefully closes the HTTP session.

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.

Sync Methods (Wrappers)

  • get_inverter_runtime()
  • get_inverter_energy()
  • get_inverter_battery()

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eg4_inverter_api-0.1.0.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eg4_inverter_api-0.1.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file eg4_inverter_api-0.1.0.tar.gz.

File metadata

  • Download URL: eg4_inverter_api-0.1.0.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for eg4_inverter_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d75fbe92995d666572f66fc19f3cc66486b518c4ecacf1955379ba7f3dd36c44
MD5 2e59145b31421983063efd7102c0cda7
BLAKE2b-256 f6dde04411634654030a8f108fa76dcdf137e21a083ef42ba52941290a4f3445

See more details on using hashes here.

File details

Details for the file eg4_inverter_api-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for eg4_inverter_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ba681743de55baaeeb4414752d9ab31a565ece36a59bf3614ed319ec00fa8b0
MD5 7a3b6dab3162477719f8a3c12c227487
BLAKE2b-256 73f8bf0190062fdabbcc18f9a91c03266b976126cc93ce8cbd07497dc2ff46a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page