Add context fields to history and logbook APIs #2882
Unanswered
loganrosen
asked this question in
Core functionality
Replies: 1 comment
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 optional context fields (
user_id,parent_id) to the history and logbook APIs. The context data already exists in the database and shows up in the current state API (/api/states/<entity>), but it's currently stripped from all historical endpoints like/api/history/periodand/api/logbook.With an optional
include_context=trueparameter, each historical state change would include who or what triggered it - whether it was a user action, an automation, a physical device, or a service call.Current limitations
The history APIs return state changes but don't include any attribution data. If I see that my kitchen light turned on 60 times last week, I can't tell if those were manual actions (which I should automate) or already triggered by automations (no action needed).
This makes several use cases impossible or unreliable:
The data exists in the database (
states.context_user_id_bin,states.context_parent_id_bin) and is accessible in real-time through/api/states/<entity>, but there's no way to get it for historical analysis without direct database access (which requires filesystem access and isn't suitable for integrations).Technical benefits
include_context=falseto maintain current API behavior and performanceExample API addition:
Would return:
{ "entity_id": "light.kitchen", "state": "on", "last_changed": "2024-01-01T10:00:00+00:00", "context": { "id": "abc123", "parent_id": null, "user_id": "def456" } }Additional context
I know context tracking has some reliability issues (#90669, #1888), but even imperfect data is more useful than no data. For pattern analysis, I can combine context with heuristics to handle gaps.
Related but different requests:
This request is specifically about exposing existing context data through historical APIs.
Alternatives I've tried:
The data is already in the database. This would just make it accessible through the standard APIs.
All reactions