Skip to main content
Glama
ffleurey

ha-analytics-mcp

by ffleurey

ha_history_get_state_history

Retrieve state-change history for Home Assistant entities. Use session mode to count and measure durations of specific states, or timeline mode for full transition logs.

Instructions

Gets the state-change history for any discrete-state entity in Home. Use for binary sensors (motion, door, window, presence), person/device_tracker (zone and location history), and any entity with named states.

Two modes: session mode when state_value is set, timeline mode when it is omitted. Source: HA recorder state history — limited to ~10 days by default. Returns a timeline of transitions, or session counts and durations when state_value is set.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
end_timeNoPeriod end, same formats as start_time. Default: now.
group_byNoSession mode only. "day" returns one row per day (date | count | first | last | total active). Combine with day_start_hour=6 for overnight/cross-midnight grouping.
entity_idYesExact entity_id resolved earlier, e.g. "binary_sensor.entrance_motion". Do not guess.
comparisonNoSession mode only. Compare session count and duration to a reference period.
start_timeNoPeriod start. Formats: relative (7d/30d/24h/2w/1y), named ("last month"/"last week"/"yesterday"/"last summer"/"Q1"), or ISO ("2026-04-01"). Default: 30d. Special: "overnight" = 22:00 yesterday → 06:00 today.
max_resultsNoMax rows to return. Default: 20. Pass "all" to list all. Timeline mode: caps transitions shown. Session mode: caps sessions or days.
state_valueNoTarget state to detect sessions for, case-insensitive. Binary sensors: "on" or "off". Person/device_tracker: a zone name e.g. "home", "not_home". Prefix ! for "any state except", e.g. "!home" = time spent outside Home. Omit to get a full timeline of all state transitions instead.
day_start_hourNoOnly with group_by="day". Shifts the day boundary from midnight to this hour (0-23). E.g. 6 → post-midnight activity (01:30) is attributed to the previous evening's date.
max_gap_minutesNoSession mode only. Bridge inactive gaps shorter than this into one session (minutes). Default: 0 (no merging). E.g. 2-5 for motion sensors when a person pauses briefly.
min_duration_minutesNoSession mode only. Discard sessions shorter than this (minutes). Default: 0. Filters brief glitches, e.g. 1 for motion sensors.
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden. It discloses the data source (HA recorder), a ~10 day limit, and the shape of returns (timeline or session counts/durations). Missing details include whether read-only is guaranteed, potential errors, or performance characteristics, but the provided context is adequate for a read-like tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is four sentences, each earning its place: purpose, usage, mode distinction, and source/return summary. Front-loaded with the primary action and uses bullet-like clarity without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex tool with 10 parameters and no output schema, the description explains the two modes, the source, and the default retention limit. It lacks details on error handling or edge cases, but the schema and the mode explanation cover most of the essential context. A bit more detail on when session mode is preferable would push it higher.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline is 3. The description adds value by clarifying the relationship between state_value and the two modes, which is not explicitly stated in the schema. It also orients the reader to session mode vs timeline mode, enhancing parameter understanding beyond individual descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb 'Gets' and clearly identifies the resource: state-change history for discrete-state entities. It distinguishes from siblings by listing concrete use cases (binary sensors, person/device_tracker) and mentions two explicit modes. This makes the tool's purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides explicit 'Use for' guidance with example entity types, and explains the two modes (session vs timeline) based on the state_value parameter. However, it does not explicitly exclude other tools or mention alternatives like get_state or get_sensor_stats, so there is room for more differentiation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ffleurey/ha-analytics-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server