Skip to content
Go back

Home Assistant + InfluxDB for Long-Term History

By SumGuy 8 min read
Home Assistant + InfluxDB for Long-Term History

The 10-Day Cliff (And Why It Sucks)

Home Assistant’s default recorder keeps 10 days of history. Ten. Days.

If you’re tracking anything remotely interesting—temperature swings across seasons, power consumption trends, occupancy patterns—10 days is like trying to understand your car’s fuel economy by looking at yesterday’s commute. You’re missing the whole story.

Here’s the thing: Home Assistant’s built-in SQLite recorder is fine for “what happened last week?” but it’ll discard your data like garbage. Want to see if your heating efficiency changed from winter to spring? Gone. Wondering if that new AC unit is actually saving you money compared to last year? The evidence is already in the bin.

That’s where InfluxDB comes in. It’s a time-series database built for exactly this problem—store millions of sensor readings, query them efficiently, and build dashboards that actually tell you something about how your home behaves over months and years.


Why InfluxDB and Not Just Postgres?

Short answer: time-series databases are purpose-built for this. They compress data better, query faster, and handle retention policies natively. Postgres works, sure, but you’re using a sledgehammer to hang a picture.

InfluxDB 2.x runs in a Docker container, auto-generates retention policies, and integrates with Home Assistant in two lines of YAML. Plus, Grafana treats InfluxDB like a first-class citizen—you write Flux queries (InfluxDB’s query language) that feel natural for time-series work.

The trade-off? InfluxDB is opinionated. You’re not writing custom SQL; you’re writing Flux. But for a home lab, that’s fine. The syntax is actually pretty readable once you get past the first query.


Setup: Docker Compose + Home Assistant Config

Let’s assume you’ve got Home Assistant running somewhere (Docker, bare metal, doesn’t matter). We’re adding InfluxDB as a companion service.

Docker Compose

Drop this in your compose file. I’m using InfluxDB 2.7 (latest stable as of May 2026):

docker-compose.yml
services:
influxdb:
image: influxdb:2.7-alpine
container_name: influxdb
ports:
- "8086:8086"
environment:
DOCKER_INFLUXDB_INIT_MODE: setup
DOCKER_INFLUXDB_INIT_USERNAME: admin
DOCKER_INFLUXDB_INIT_PASSWORD: changeme
DOCKER_INFLUXDB_INIT_ORG: homeassistant
DOCKER_INFLUXDB_INIT_BUCKET: homeassistant
volumes:
- influxdb_data:/var/lib/influxdb2
- influxdb_config:/etc/influxdb2
restart: unless-stopped
volumes:
influxdb_data:
influxdb_config:

Spin it up:

Terminal window
docker compose up -d influxdb

Wait 10 seconds. Check logs:

Terminal window
docker logs influxdb

You should see Server listening on port 8086. If not, InfluxDB is probably initializing—give it another 5 seconds.

Home Assistant Configuration

In Home Assistant, add this to your configuration.yaml:

configuration.yaml
influxdb:
api_version: 2
ssl: false
host: influxdb
port: 8086
token: "your-token-here"
organization: "homeassistant"
bucket: "homeassistant"
tags:
source: homeassistant
tags_attributes:
- friendly_name

Wait, where do we get that token? You need to set it up via the InfluxDB web UI first.

InfluxDB Initial Setup

Navigate to http://localhost:8086 (or your server’s IP):

  1. Create initial admin: Username admin, password (change the changeme from Compose)
  2. Organization name: homeassistant (must match the YAML config)
  3. Bucket name: homeassistant (must match)
  4. Generate token: Go to DataTokensGenerate TokenRead/Write Token
    • Scope: Read + Write on the homeassistant bucket
    • Copy that token, paste it into configuration.yaml

Restart Home Assistant:

developer-tools.yaml in HA
# Or just restart the container from shell:
docker restart home-assistant

Check the Home Assistant logs. If you see no errors about InfluxDB, you’re connected.

Verify the Connection

Log into InfluxDB’s web UI again. Go to Explore → select the homeassistant bucket → run a simple query:

from(bucket: "homeassistant")
|> range(start: -24h)
|> limit(n: 10)

You should see sensor data flowing in. If you get nothing, Home Assistant might not have any compatible entities yet (numeric sensors, temperatures, power readings). Give it a few minutes and refresh.


What Gets Sent to InfluxDB?

Home Assistant only sends “numeric” entities by default: temperatures, humidity, power consumption, battery levels, occupancy counts, motion sensors as numbers. Binary sensors (on/off) get sent as 1/0. Text entities and automations? They stay in SQLite.

You can be selective about what gets logged. Add this to your influxdb: config block:

configuration.yaml - selective logging
influxdb:
# ... previous config ...
include:
entities:
- sensor.living_room_temperature
- sensor.power_meter_total
- sensor.bedroom_humidity
exclude:
entities:
- sensor.time # don't log this, it's spammy

Good candidates for long-term tracking:


Retention Policies: Don’t Store Forever

By default, InfluxDB will keep everything. That sounds great until your disk is full in six months.

Set up a retention policy via the web UI:

  1. Buckets → select homeassistant
  2. Retention → set to 1 year (or whatever makes sense for you)

For a home lab, one year of data is usually perfect. You can ask questions like “is my heating bill going up?” and actually have a year’s worth of comparison. Beyond that, you’re probably not going back.

If you want aggressive retention (e.g., high-resolution data for 3 months, then aggregate to daily for a year), that requires custom InfluxDB tasks. Not covering that here—it’s overkill for most home labs. The simple “1 year, keep everything” approach works fine.


Building Dashboards: Grafana

Now you’ve got a year of sensor data. Time to make it pretty.

Add Grafana to your Compose:

docker-compose.yml addition
grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- "3000:3000"
environment:
GF_SECURITY_ADMIN_PASSWORD: admin
volumes:
- grafana_data:/var/lib/grafana
restart: unless-stopped
volumes:
grafana_data:

Restart Compose. Navigate to http://localhost:3000 → log in with admin/admin.

Connect InfluxDB as a Data Source

  1. ConfigurationData SourcesAdd data source
  2. Select InfluxDB
  3. Query Language: Flux (not InfluxQL)
  4. URL: http://influxdb:8086
  5. Organization: homeassistant
  6. Token: (paste the same token from Home Assistant config)
  7. Default Bucket: homeassistant
  8. Save & Test

Create a Panel: Monthly Temperature Comparison

Create a new dashboard. Add a panel. Set the data source to InfluxDB. Write a Flux query:

import "experimental"
from(bucket: "homeassistant")
|> range(start: -1y, stop: now())
|> filter(fn: (r) => r["_measurement"] == "°C" and r["entity_id"] == "sensor.living_room_temperature")
|> aggregateWindow(every: 1h, fn: mean, createEmpty: false)

This gives you hourly-averaged temperature for the past year. Drop it into a time-series panel. You’ll see the heating ramp up in December, drop in March, spike in July.

Want to compare this year to last year? Add a second query with range(start: -2y, stop: -1y) to fetch last year’s data in the same graph.

Power Consumption Example

Here’s something actually useful: track power consumption by time of day, month to month:

from(bucket: "homeassistant")
|> range(start: -1y)
|> filter(fn: (r) => r["_measurement"] == "W" and r["entity_id"] == "sensor.power_meter_total")
|> aggregateWindow(every: 1d, fn: sum, createEmpty: false)

This sums power every 24 hours. Throw it into a bar chart. You’ll see summer months spike (AC running) and winter months dip (heating costs more electricity in some regions, but less AC). Now you have data for conversations like “why is the bill up?”


Common Pitfalls

“I’m not seeing any data.”

“InfluxDB is taking up too much disk space.”

“Grafana queries are slow.”

“I want to archive old data.”


Worth It?

Honest take: if you’re just running a few lights and a thermostat, this is overkill. Home Assistant’s default recorder is fine.

But if you’re actually collecting data—power meters, multiple temperature sensors, occupancy tracking, anything seasonal—InfluxDB + Grafana is the way to see patterns you’d miss otherwise. You go from “the heating bill went up” to “the heating bill went up because the temperature outside was 3°C colder in February than last year, and your furnace ran 40% more cycles.”

That’s not just analytics. That’s ammunition for home improvement decisions. And for a Docker container and some YAML config, it’s not a hard sell.

Set it up on a weekend, let it run for a month, then build a dashboard. You’ll understand your home in ways you couldn’t before.


Share this post on:

Send a Webmention

Written about this post on your own site? Send a webmention and it'll show up above once verified.


Next Post
ddrescue vs TestDisk vs PhotoRec

Discussion

Powered by Garrul . Sign in with GitHub or Google, or post anonymously.

Related Posts