Expose recorder long-term statistics via REST API (parity with WebSocket) #3865
Unanswered
h3x89
asked this question in
Core functionality
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Describe your core improvement
Add a REST HTTP endpoint for querying long-term statistics (LTS) stored
by the Recorder integration — equivalent to the existing WebSocket command
recorder/statistics_during_period.Proposed endpoint:
POST /api/statistics_during_period
accepting the same parameters as the WebSocket command: start_time, end_time,
statistic_ids, period, types.
Current limitations
Long-term statistics are accessible only via WebSocket API
(recorder/statistics_during_period). The REST API covers only short-term
state history via /api/history/period/ — limited by purge_keep_days
(typically 10 days). There is no REST path to LTS data that persists
indefinitely in the statistics table.
A related issue (#131355) was closed as stale with no resolution — a user
explicitly asked "Any way to retrieve the long term statistics through the api?"
and the answer was "maybe via WebSocket".
Technical benefits
MCP proxies) gain access to LTS without needing a WebSocket client
a REST wrapper would call the same underlying recorder function
Additional context
Concrete use case: LiteLLM MCP proxy exposes HA as a tool to an AI agent
via REST OpenAPI spec. The agent reads current states and recent history
just fine — but any trend analysis older than 10 days is impossible because
LTS is WebSocket-only. Workarounds (direct SQLite query, proxy sidecar) are
fragile and not portable.
REST API docs for reference: https://developers.home-assistant.io/docs/api/rest
WebSocket command docs: https://developers.home-assistant.io/docs/api/websocket
Beta Was this translation helpful? Give feedback.
All reactions