Affected files: .obsidian/workspace.json 2 Personal/Home Lab/Baerhalten/Home Assistant -> InfluxDB -> Grafana setup and debugging notes.md 2 Personal/Home Lab/Baerhalten/Home Assistant.md
8.6 KiB
title, created_date, updated_date, aliases, tags
| title | created_date | updated_date | aliases | tags |
|---|---|---|---|---|
| Home Assistant -> InfluxDB -> Grafana setup and debugging notes | 2026-03-17 | 2026-03-17 |
Home Assistant -> InfluxDB -> Grafana setup and debugging notes
Architecture
This setup has three layers:
- Home Assistant generates state changes and sensor values.
- InfluxDB 3 Core stores that time-series data.
- Grafana reads from InfluxDB and visualizes it.
Network layout
- Home Assistant runs outside the Docker Compose network.
- InfluxDB and Grafana run together in the same Docker Compose stack.
- Therefore:
- Home Assistant -> InfluxDB must use the Proxmox container IP and exposed port.
- Grafana -> InfluxDB should use the Docker service name.
Actual endpoints
Home Assistant -> InfluxDB
Home Assistant should connect to InfluxDB using:
- Protocol:
http - Host / URL:
192.168.194.120 - Port:
8181 - SSL verification: off
Reason: Home Assistant is outside the Docker network, so it cannot resolve influxdb3.
Grafana -> InfluxDB
Grafana should connect to InfluxDB using:
- URL:
http://influxdb3:8181
Reason: Grafana and InfluxDB are on the same Docker Compose network, so Docker DNS resolves influxdb3.
Docker Compose setup
The relevant Compose structure is:
services:
influxdb3:
image: influxdb:3-core
ports:
- "8181:8181"
grafana:
image: grafana/grafana:latest
depends_on:
- influxdb3
ports:
- "3000:3000"
This means:
- InfluxDB is reachable from outside Docker at
http://<proxmox-container-ip>:8181 - InfluxDB is reachable from Grafana internally at
http://influxdb3:8181
Home Assistant InfluxDB configuration
Important migration detail
Home Assistant is removing YAML-based InfluxDB connection settings.
So these connection keys should not stay in YAML:
api_versionhostportsslverify_sslssl_ca_certusernamepassworddatabasetokenorganizationbucketpath
Those should be configured through Devices & Services in the Home Assistant UI.
What can still stay in YAML
Behavior/settings like these can still stay in YAML:
measurement_attrdefault_measurementoverride_measurementincludeexcludetagstags_attributes
Final Home Assistant behavior setting
To get one table per entity/sensor, the key YAML setting is:
influxdb:
measurement_attr: entity_id
Reason:
- Default behavior grouped data into tables like
W,Wh,V,% - That made many sensors appear "missing", because they were grouped by unit
measurement_attr: entity_idchanges that back to one measurement/table per entity, which is easier to use in Grafana
InfluxDB concepts in this setup
Databases
We used databases such as:
homehomeassistantha_fresh
These are databases, not tables.
Tables / measurements
Inside a database, tables are created automatically when data is written.
Examples after using measurement_attr: entity_id:
sensor.solarnet_power_photovoltaicssensor.solarnet_power_grid_exportsensor.solarnet_power_load_consumed
Examples from the old grouped schema:
WWhVA
Tokens and authentication
What is used where
- Home Assistant uses an InfluxDB token to write data
- Grafana uses an InfluxDB token to query data
- Admin token is used for CLI/database management
Important note
Tokens and secrets that were exposed should be rotated.
How we debugged the setup
1. Verified InfluxDB is running
We checked Docker:
docker ps
docker logs --since 0.5m influxdb3
This confirmed:
- Grafana container is running
- InfluxDB container is running
- InfluxDB is actively flushing writes
2. Verified databases exist
docker exec -it influxdb3 influxdb3 show databases --token "$INFLUX_ADMIN_TOKEN"
This showed databases like:
_internalhomehomeassistant- later
ha_fresh
3. Verified Home Assistant can reach InfluxDB over the network
From Home Assistant shell:
curl http://192.168.194.120:8181/health
Response:
{"error": "the request was not authenticated"}
This was good because it proved:
- DNS/IP was correct
- network path worked
- InfluxDB was reachable
- only authentication remained
4. Reconfigured Home Assistant in the UI
Home Assistant InfluxDB integration was configured in Devices & Services using:
- HTTP
- host/IP of Proxmox container
- port
8181 - no SSL verification
- organization
dummy - bucket/database
ha_freshor similar - token
5. Enabled debug logs in Home Assistant
We confirmed HA was writing by seeing log lines like:
Wrote 8 events.
Wrote 10 events.
That proved:
- Home Assistant -> InfluxDB write path works
6. Verified writes actually landed in InfluxDB
We queried InfluxDB directly:
docker exec -it influxdb3 influxdb3 query --database ha_fresh --token "$INFLUX_ADMIN_TOKEN" 'SELECT * FROM "W" ORDER BY time DESC LIMIT 20'
This showed fresh rows from Home Assistant sensors, including:
pv_powersolarnet_power_photovoltaicssolarnet_power_load_consumedsolarnet_power_grid_export
That proved:
- Home Assistant -> InfluxDB works fully
- the issue was not ingestion
- the issue was schema / Grafana config
7. Verified Grafana container can reach InfluxDB
From inside the Grafana container, we tested:
curl -i http://influxdb3:8181/api/v3/query_sql -H "Authorization: Token YOUR_GRAFANA_TOKEN" -H "Content-Type: application/json" --data '{"db":"home","q":"SHOW TABLES"}'
This working proved:
- Docker networking is fine
influxdb3resolves correctly- Grafana-side token auth works
- the remaining problem was purely Grafana datasource configuration
8. Fixed Grafana datasource setup
Correct Grafana datasource basics
- Query language: SQL or the desired mode
- URL:
http://influxdb3:8181 - Database: the actual InfluxDB database in use
- Token: Grafana token
Important TLS issue
Grafana originally failed with an error like:
tls: first record does not look like a TLS handshake
That happened because Grafana tried TLS/FlightSQL behavior against a plain HTTP endpoint.
Fix:
- use the correct datasource mode
- use the right endpoint
- keep the connection consistent with the actual InfluxDB setup
9. Realized the schema had changed
Old schema assumption:
- one table per sensor
New schema that appeared initially:
- one table per unit, like
W,Wh,V
That is why old queries stopped working.
Example old query:
SELECT mean("value")
FROM "sensor.solarnet_power_photovoltaics"
WHERE $timeFilter
GROUP BY time(5m) fill(none)
Equivalent query in the grouped-by-unit schema:
SELECT mean("value")
FROM "W"
WHERE
"entity_id" = 'solarnet_power_photovoltaics'
AND $timeFilter
GROUP BY time(5m) fill(none)
Then we changed HA back to per-entity measurements using:
influxdb:
measurement_attr: entity_id
10. Reset the fresh database to keep it clean
After confirming the new schema worked, the goal was to keep only actually-used tables in the fresh DB.
General approach:
- delete or recreate
ha_fresh - reconnect HA to it
- let HA repopulate it with only actively written entities
That leaves a clean database without old junk.
Final recommended setup
Home Assistant
- Configure InfluxDB connection in the UI
- Keep only behavior options in YAML
- Use:
influxdb:
measurement_attr: entity_id
if per-entity tables are desired
InfluxDB
- Keep one clean database for HA data
- Use separate tokens for:
- admin
- Home Assistant
- Grafana
Grafana
- Use datasource URL:
http://influxdb3:8181
- Point it to the correct InfluxDB database
- Use the Grafana token
- Rebuild old queries if schema changed
Quick troubleshooting checklist for the future
If HA is not writing
- Check HA logs for InfluxDB errors
- Test connectivity from HA:
curl http://<influx-ip>:8181/health - Verify token / database / organization / bucket in HA UI
- Query InfluxDB directly to see whether data is arriving
If Grafana shows nothing
- Verify datasource URL is
http://influxdb3:8181 - Test token from inside Grafana container
- Confirm the right database is selected
- Check whether schema is per-entity or grouped-by-unit
- Rewrite queries accordingly
If sensors seem missing
- Check
SHOW TABLES - Query likely shared tables like
W,Wh,V - Check whether HA is grouping by unit instead of entity
- Set:
influxdb:
measurement_attr: entity_id
if one table per sensor is preferred