Skip to content

Fix spot price (pricezone endpoint gone), add last API poll sensor - #9

Merged
andreasthell merged 2 commits into
mainfrom
claude/loving-carson-jhqmhn
Sep 23, 2026
Merged

andreasthell merged 2 commits into
mainfrom
claude/loving-carson-jhqmhn

Conversation

@andreasthell

Copy link
Copy Markdown
Owner

Spot price, spot price incl. VAT and price zone were unavailable on 1.5.2. /ems/pricezone now returns an HTTP error, and the spot price request came after it in the same step, so it was never sent. The request itself is unchanged since 1.5.1, but the zone is fetched only once per HA start, so a 1.5.1 instance started earlier kept a zone from when the endpoint still worked.

A HAR export from the EnergyInBalance web app (2026-09-23) shows it no longer calls /ems/pricezone at all. It takes the zone from Mba in /site/Statuses and requests /ems/spotprice with zone, fromDate, toDate and siteId.

Changes

  • Price zone comes from Mba in /site/Statuses, which the integration already fetches every cycle. /ems/pricezone is only a fallback.
  • The spot price request sends siteId so it matches the web app.
  • New diagnostic sensor "Last API poll" (Senaste API-hämtning):
    • Its value is the time of the last successful refresh.
    • Its attributes show the last refresh error and, for each slow update (revenue, price, energy, logbook, diagnostics, news), last_success, last_error and next_attempt.
    • The attributes are excluded from the recorder.
    • The sensor stays available when a refresh fails, so the error remains visible.
  • Request errors name the HTTP status or a timeout, e.g. Request to /ems/pricezone failed: HTTP 404 instead of ClientResponseError, still without query values. aiohttp's total timeout raises TimeoutError, which is now caught as well.
  • Slow updates return an error description instead of a bool. The status map replaces the separate next-update map.
  • docs/api.md notes the pricezone change, and the README's troubleshooting section points to the new sensor. The version is bumped to 1.5.3.

Testing

  • I ran the coordinator against the HAR's real /site/Statuses and /ems/spotprice responses, with /ems/pricezone returning 404 and the clock set to the HAR's time. The zone resolved to SE4 and the price for the 12:30 slot was selected, matching the HAR. The HAR itself is not committed.
  • New tests cover:
    • update status, success, failure and recovery;
    • energy errors naming the meter group;
    • price zone from Mba and the fallback;
    • spot price without the pricezone endpoint;
    • HTTP status and timeout in error messages;
    • the last poll sensor's value, attributes, availability and unrecorded attributes.
  • All 101 tests pass. ruff check and ruff format --check are clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Tt2YacbPwiWKinpfhCss29


Generated by Claude Code

…uses

- New diagnostic sensor "Last API poll": its value is the last successful
  refresh. Its attributes show the last refresh error and, for each slow
  update (revenue, price, energy, logbook, diagnostics, news), its last
  success, last error and next attempt. The attributes are excluded from
  the recorder, and the sensor stays available when a refresh fails so
  the error remains visible.
- Request errors now name the HTTP status or a timeout ("Request to
  /ems/pricezone failed: HTTP 404") instead of just ClientResponseError,
  still without the URL's query values. aiohttp's total timeout raises
  TimeoutError, which is now caught as well.
- The price zone is read from the site's Mba (market balance area) in
  /site/Statuses, which is already fetched every cycle. /ems/pricezone is
  only a fallback, so spot prices no longer depend on it: it returns an
  HTTP error for at least one site.
- Slow updates return an error description instead of a bool; the six
  status fields replace the separate next-update map.

Version 1.5.3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tt2YacbPwiWKinpfhCss29
A HAR export from the EnergyInBalance web app (2026-09-23) shows it no
longer calls /ems/pricezone: it takes the zone from Mba in /site/Statuses
and requests /ems/spotprice with zone, fromDate, toDate and siteId. The
integration now sends siteId too, so the request matches the web app.

Verified by running the coordinator against the HAR's Statuses and spot
price responses with /ems/pricezone returning 404: the zone resolves to
SE4 and the current slot's price is selected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tt2YacbPwiWKinpfhCss29
@andreasthell
andreasthell merged commit 6014df8 into main Sep 23, 2026
3 checks passed
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.

2 participants