Skip to content

Add SPH device support via the regional mobile API#145

Open
morland96 wants to merge 2 commits into
indykoning:masterfrom
morland96:feature/regional-mobile-sph-support
Open

Add SPH device support via the regional mobile API#145
morland96 wants to merge 2 commits into
indykoning:masterfrom
morland96:feature/regional-mobile-sph-support

Conversation

@morland96

@morland96 morland96 commented May 4, 2026

Copy link
Copy Markdown

Summary

Newer SPH/SPM hybrid inverters (e.g. SPM-10000TL-HU) aren't reachable via the existing legacy mix_/tlx_/storage_* endpoints — those return null/zero values. They're also not reachable via the V1 sph_* methods because V1's device_list omits these devices entirely.

I proxied my phone and looks like ShinePhone mobile app to reverse engineer the same set of methods for SPH/SPM inverters:

  • sph_system_status(plant_id, sph_sn) — real-time SOC, vBat, PV (per-string), battery charge/discharge, grid in/out, local load, AC voltage/frequency
  • sph_energy_overview(plant_id, sph_sn) — daily and lifetime kWh totals
  • sph_energy_prod_and_cons(plant_id, sph_sn, date, chart_type) — chart series (day/month/year/total)
  • sph_settings(sph_sn) — full settings bean (149 adjustable parameters on this device)
  • update_sph_inverter_setting(serial, type, params) — write a setting via newTcpsetAPI.do?op=sphSet

An exampled is included: examples/sph_legacy_example.py

Checklist

  • I've made sure the PR does small incremental changes. (new code additions are dificult to review when e.g. the entire repository got improved codestyle in the same PR.)
  • I've added/updated the relevant docs for code changes i've made.

Newer SPH inverters aren't reachable via the V1 OpenAPI. Add methods
that target the regional mobile host (server-{region}-api.growatt.com)
which is what the ShinePhone app uses.

Methods on GrowattApi:
- sph_system_status() — real-time values (SOC, PV, battery, grid, load)
- sph_energy_overview() — daily and lifetime totals
- sph_energy_prod_and_cons() — chart series (day/month/year/total)
- sph_settings() — full settings bean
- update_sph_inverter_setting() — write a setting
@morland96 morland96 force-pushed the feature/regional-mobile-sph-support branch from 4bed1df to df3d417 Compare May 4, 2026 15:26
Add noqa comments for intentional datetime.now() without tz
(local time is correct for the Growatt API) and for the
chart_type magic number comparison (API constants documented
in docstring).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@johanzander johanzander left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Overall this looks good — clean, well-scoped, follows existing patterns (tlx_, mix_), and fills a real gap for newer SPH/SPM models that aren't reachable via V1 or the legacy mix/tlx/storage endpoints.

One thing I'd like the repo owner to weigh in on:

The change on line 90 of base_api.py switches __get_date_string from datetime.datetime.now(datetime.UTC) to naive datetime.datetime.now(). The reasoning in the comment is sound (Growatt interprets the date string in the plant's local timezone), but this is a behavioral change for all existing callers (e.g. plant_detail, mix_detail, tlx_energy_prod_cons), not just the new SPH methods. Users who were relying on the UTC default could see different results near midnight.

@indykoning — are you OK with this change to the shared __get_date_string default, or should we keep UTC there and only use local time in the new SPH-specific date handling?

@johanzander

Copy link
Copy Markdown
Collaborator

One more thing: could you add type annotations to the new SPH methods? The rest of the codebase on master has them.

@indykoning

Copy link
Copy Markdown
Owner

The reasoning in the comment is sound (Growatt interprets the date string in the plant's local timezone), but this is a behavioral change for all existing callers (e.g. plant_detail, mix_detail, tlx_energy_prod_cons)

I agree with this, though it could be a bug i introduced when adding and running ruff:
c754b8f#diff-3da34889a61a85f5b4f4bf8ab496d0474ff3353036f3ab4ac2ddeefdb951247fR84

If we could double check that e.g. the https://github.com/indykoning/PyPi_GrowattServer/blob/master/growattServer/base_api.py#L200 plant_detail function also uses the localized date instead of UTC my worries will have been taken care of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants