Skip to main content

sungrow-isolarcloud

A maintained fork of the pysolarcloud library for interacting with Sungrow's iSolarCloud API.

Install from PyPI:

pip install sungrow-isolarcloud

This fork adds:

  • Support for requesting additional / custom measure points without modifying the upstream point map (useful for battery charge/discharge power fields that vary by inverter model).
  • A best-effort per-device realtime helper for devices such as EV chargers (Plants.async_get_device_realtime).
  • A heartbeat helper for External EMS dispatch mode (Control.async_heartbeat / Control.heartbeat_loop).
  • Convenience constants for dispatch command value sets (Control.CHARGE_DISCHARGE_COMMANDS, Control.FORCED_CHARGING).

The package supports the following functionality:

  • OAuth2 authentication
  • Getting a list plants
  • Getting details of a plant
  • Getting devices of a plant
  • Getting "real-time" data of a plant (Data is updated every 5 minutes according to Sungrow's documentation)
  • Getting historical data
  • Getting and updating grid control settings

Quirks

The iSolarCloud API is quite new and not very mature. Some tips:

  • The authorisation flow is based on OAuth2 but doesn't work exactly as you would expect
  • The state parameter is not passed back after to the authorisation step. This makes it more tricky to resume the flow in a client application.
  • User is asked to approve the authorisation if the flow is invoked again, e.g. in case the tokens have expired - unlike many OAuth2 implementations who will perform a "silent" authorisation if the user has already approved the access.
  • The API documentation lists a lot of data points which do not seem to be returned from my inverter, it probably varies between models.
  • There are different iSolarCloud servers for different regions, see the pysolarcloud.Server enum
  • API endpoints accept a language code but respond with Chinese text when when English is requested

Usage

Register your app

  1. Create an account in the iSolarCloud Developer Portal
  2. Create an app in the developer portal
    • Answer "Yes" to authorize with OAuth2.0
    • Enter a Redirect URL for your app (this can be changed later)
  3. Wait for approval by Sungrow
  4. Find the needed configuration details in the developer portal. You will need:
    • Appkey
    • Secret Key
    • Application Id (This is shown as a query parameter within the Authorize URL in the developer portal)

Example

from pysolarcloud import Auth, Server
from pysolarcloud.plants import Plants

app_key = "your app key"
secret_key = "your secret key"
app_id = "your app id"
redirect_uri = "your redirect uri"

auth = Auth(Server.Europe, app_key, secret_key, app_id)
url = auth.auth_url(redirect_uri)
  1. Redirect user to url
  2. User selects plant(s) and grants authorisation
  3. iSolarCloud will redirect the user to redirect_uri with query parameter code
await auth.async_authorize(code, redirect_uri)
plants_api = Plants(auth)
plant_list = await plants_api.async_get_plants()
if plant_list:
   print(f"{len(plant_list)} plants found:")
   for plant in plant_list:
         print(f"Plant ID: {plant["ps_id"]}, Name: {plant["ps_name"]}")
else:
   print("No plants found.")
   return

print("\nFetching detailed information for each plant...\n")
plant_ids = [str(plant["ps_id"]) for plant in plant_list]
plant_details = await plants_api.async_get_plant_details(plant_ids)
for plant in plant_details:
   print(f"Details for Plant ID {plant["ps_id"]}: {plant}")

print("\nFetching real-time data for each plant...\n")
real_time_data = await plants_api.async_get_realtime_data(plant_ids)
for plant_id, data in real_time_data.items():
   # Print only the data points where value is not None
   data_values = {k: v for k, v in data.items() if v and v.get("value") is not None}
   print(f"Real-time data for Plant ID {plant_id}: {data_values}")

The Auth class keeps the access between calls and refreshes it when needed. If you prefer to manage this state yourself, you can create your own subclass of AbstractAuth.

Grid Control

The Control class enables retrieving and updating grid control settings. Parameters and value sets are documented in the iSolarCloud Developer portal.

Example

from pysolarcloud.control import Control
from pysolarcloud.plants import DeviceType

devices = await plants_api.async_get_plant_devices(plant_id, device_types=[DeviceType.ENERGY_STORAGE_SYSTEM])
device_uuid = devices[0]["uuid"]
control_api = Control(auth)
# Fetch current config
current_settings = await control_api.async_read_parameters(device_uuid)
print(current_settings)
# Make an update using the canonical command values.
# energy_management_mode (10003) must leave Self-consumption for charge/discharge to actuate:
# 0 self-consumption, 2 compulsory/forced, 3 external energy dispatch, 4 VPP.
await control_api.async_update_parameters(
    device_uuid,
    {
        "energy_management_mode": Control.encode_parameter("energy_management_mode", "compulsory"),
        "charge_discharge_command": Control.CHARGE_DISCHARGE_COMMANDS["charge"],
        "charge_discharge_power": "2500",
    },
)

# When using External EMS / forced dispatch, send a heartbeat periodically.
# 10017 = external_ems_heartbeat, value is the heartbeat interval in seconds (1-1000).
# Appendix 10: send the heartbeat when switching EMS modes through the API.
await control_api.async_heartbeat(device_uuid, interval_seconds=60)

User-account login (unofficial, experimental)

In addition to the official OpenAPI OAuth flow (Auth), this fork provides UserAuth, which logs in with a normal iSolarCloud user account (email + password) via the reverse-engineered app/web API — no developer application required.

from pysolarcloud import Server, UserAuth

async with UserAuth(Server.Europe, "you@example.com", "password") as auth:
    plants = await auth.async_get_plants()
    print(plants)

⚠️ Unofficial and experimental. This is not Sungrow's documented OpenAPI. It may change or break without notice and its use may be subject to Sungrow's terms of service. The protocol was reimplemented clean-room from the MIT-licensed homebridge-platform-isolarcloud (see NOTICE). Credentials are only sent to iSolarCloud over TLS and are never logged.

Contributions

Ideas or contributions are welcome. I am not afiliated with Sungrow, I'm just another user of the API. My main use case will be a HomeAssistant integration based on this package.

Enjoy!

Download files

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

Source Distribution

sungrow_isolarcloud-0.13.0.tar.gz (30.5 kB view details)

Uploaded Source

Built Distribution

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

sungrow_isolarcloud-0.13.0-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file sungrow_isolarcloud-0.13.0.tar.gz.

File metadata

  • Download URL: sungrow_isolarcloud-0.13.0.tar.gz
  • Upload date:
  • Size: 30.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for sungrow_isolarcloud-0.13.0.tar.gz
Algorithm Hash digest
SHA256 2888d275f0417df38d0b47ebcb1626f66fdce79c8e732f0d0169bb6f6e523ce4
MD5 ad44ee23d120752c28c61c8e96f2e337
BLAKE2b-256 59f2865c49f5e141ae785f9d24a1c3663626341d8fba763e7cdf6d1e2c1107a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for sungrow_isolarcloud-0.13.0.tar.gz:

Publisher: release-please.yml on KRoperUK/pysolarcloud

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sungrow_isolarcloud-0.13.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sungrow_isolarcloud-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b0469c25a6d417d0a6e270cffa1ef88e2f41acb76dbeacd200fa95c3aca1591
MD5 70f0e85a06119c773cd34dd6e4843553
BLAKE2b-256 1e7b7769f3cf688f0a7e24182d250e97ebfb51784eefb41ac3f630df84be1eac

See more details on using hashes here.

Provenance

The following attestation bundles were made for sungrow_isolarcloud-0.13.0-py3-none-any.whl:

Publisher: release-please.yml on KRoperUK/pysolarcloud

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.15.0

2 files

0.14.0

2 files

This release

0.13.0 This release

2 files

0.12.1

2 files

0.12.0

2 files

0.11.0

2 files

0.10.4

2 files

0.10.3

2 files

0.10.2

2 files

0.10.1

2 files

0.10.0

2 files

0.9.1

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 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