hass-history-mcp
Provides access to historical Home Assistant data, including entity history, energy consumption, last seen timestamps, and device uptime detection.
Queries an InfluxDB 1.8 instance storing Home Assistant sensor data, supporting history retrieval, bucketed aggregates, and custom SELECT/SHOW queries.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@hass-history-mcpHow much energy did my washing machine use last week in kWh?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
hass-history-mcp
An MCP (Model Context Protocol) server that gives Claude access to historical Home Assistant data — something the standard Home Assistant MCP integration doesn't expose. It answers questions like:
How much power has a given entity drawn over the last week?
What's my estimated energy consumption (kWh) for a device or circuit?
Has a device been offline recently, and for how long?
What was the last reported state/value of an entity, and how long ago?
It works by querying an existing InfluxDB 1.8 instance that Home Assistant is already writing sensor data to (via the built-in InfluxDB integration), rather than talking to Home Assistant's recorder database directly. This means it can see further back than HA's default recorder purge window (commonly 10 days), since InfluxDB retention is independent of that.
How it works
Home Assistant's InfluxDB integration writes each entity's state as a point
tagged with entity_id and domain, with the numeric value in a value field.
The measurement name is usually the entity's unit of measurement (e.g. W,
kWh, %), which varies per sensor — so every query in this server matches
across measurements with a regex (/.*/) and filters by the entity_id tag
instead. This makes the tools work regardless of your exact
default_measurement configuration.
Two things to know about real-world databases:
friendly_nameis usually a field, not a tag (oftenfriendly_name_str). Onlyentity_idanddomainare reliably tags, so you can'tGROUP BYfriendly name unless you've added it totags_attributesin your Home Assistant InfluxDB config. Adding it applies to new data only.The same entity can appear in several measurements. Integrations that set a different
default_measurementwrite to names likesensor.my_entity_batteryalongside the unit-based%. Because InfluxQL appliesLIMITper series, a query spanning measurements returns one row per measurement — so "most recent" must be resolved by comparing timestamps, not by taking the first row.get_last_seenandget_device_uptimehandle this; keep it in mind for your ownrun_influxqlqueries.
Related MCP server: InfluxDB MCP Server
Timezones
InfluxDB stores everything in UTC. Set LOCAL_TZ to your IANA zone (default
America/Toronto) so that bucketed queries align to local midnight rather
than UTC midnight — otherwise a "daily" energy total silently covers a window
offset by your UTC offset. Every history tool also accepts a per-call tz
argument that overrides LOCAL_TZ, and returns timestamps carrying a local
offset. Use the zone name rather than a fixed offset so daylight-saving
transitions are handled correctly.
Tools
Tool | Description |
| List known entity_id values, optionally filtered by domain ( |
| Raw history, or bucketed averages if |
| Integrates a Watts sensor into kWh, bucketed by local day/hour. |
| Most recent value across all measurements, in UTC and local time, plus age. |
| Detects gaps between data points to estimate uptime % and list offline windows in local time. |
| Escape hatch for custom queries — restricted to |
Configuration
Set via environment variables:
Variable | Default | Notes |
|
| Container name if on the same docker network, else host IP/DNS |
|
| |
|
| Database name — note HA's default has no underscore |
| (empty) | Only needed if auth is enabled |
| (empty) | |
|
| |
|
| |
|
| IANA zone for local-time bucketing |
The compose files read these from your environment, so nothing host-specific is
committed. Set them in Portainer under Stack → Environment variables, or in
a .env file beside the compose file:
INFLUXDB_HOST=10.0.0.5
LOCAL_TZ=America/TorontoRequires the MCP Python SDK v2 (mcp>=2). v1's mcp.server.fastmcp module was
removed in 2.x — MCPServer replaces FastMCP.
Running with Docker
docker compose up -d --builddocker-compose.yml runs it standalone. If you'd rather add it to an existing
stack, docker-compose.snippet.yml holds just the service block — paste it
under that file's services: key.
Portainer
Use Stacks → Add stack → Repository and point it at this repo, so Portainer
has the source needed to build the image. The Web editor tab can't build from a
Dockerfile — pasting the compose file there will fail unless you swap build: .
for a prebuilt image:.
Once running, point your MCP client (e.g. Claude Desktop) at:
http://<host>:8006/mcpVerifying your schema
Before relying on the results, confirm the InfluxDB schema matches what this server expects. Run these in order — each is bounded and cheap:
-- 1. Measurement names (these are your units: W, kWh, %, ...)
SHOW MEASUREMENTS LIMIT 20
-- 2. Confirm the entity_id tag exists
SHOW TAG VALUES FROM /.*/ WITH KEY = "entity_id" LIMIT 10
-- 3. Confirm the field is named `value`, against ONE known measurement
SELECT * FROM "W" WHERE time > now() - 1h LIMIT 1Do not run
SELECT * FROM /.*/ LIMIT 1.LIMITapplies per series, not globally, so that query materializes one row for every series across every measurement at once. On a database with a few thousand entities it can grow InfluxDB's memory to many gigabytes and trigger the kernel OOM killer — taking down InfluxDB and potentially the whole host. Always bound schema checks to a single measurement and a time range, as in step 3 above.
If your tags_attributes / default_measurement Home Assistant config is
customized, the field name might not be value — in that case, adjust the
queries in server.py accordingly.
License
MIT — use however you like.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Read-only electricity, gas, and weather data with structured provenance and units.
Query site stats, realtime visitors, breakdowns and goals from Plausible Analytics.
Query Honeycomb observability data: traces, events, metrics, SLOs, triggers, and boards.
Query Australia's electricity market (NEM/AEMO): prices, generation, FCAS, interconnectors, bids.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceAn MCP server that enables interactions with InfluxDB's open-source time-series database API, allowing data querying, management, and operations through natural language.
- AlicenseNot gradedqualityDmaintenanceEnables interaction with InfluxDB v3 (Core/Enterprise/Cloud Dedicated) through MCP clients. Supports database management, data querying and writing, schema inspection, and token administration operations.1,632MIT
- AlicenseNot gradedqualityDmaintenanceInfluxDB-v1-MCP is a powerful Model Context Protocol (MCP) interface specifically designed for InfluxDB v1.x, enabling AI assistants to intelligently manage and query time-series databases.Apache 2.0

InfluxDB MCP Serverofficial
FlicenseAqualityBmaintenanceEnables interaction with InfluxDB 3 (Core/Enterprise/Cloud Dedicated/Clustered/Cloud Serverless) through MCP clients, providing tools for querying, writing, managing databases, tokens, and more.2715336
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/carlosperezc/hass-history-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server