Hi everyone,
I’m having trouble integrating InfluxDB with my Home Assistant setup and could really use some help! Despite triple-checking my credentials (organization ID, bucket, and token), I’m still encountering a 401 Unauthorized
error upon restarting HA. I’m confident the information is correct, but I can’t seem to get it working. Here’s my setup and details:
Setup Details
Home Assistant Version**: 2024.12.5
Frontend Version**: 20241127.8
Install Method: Home Assistant Container
InfluxDB Version2.7: Official Docker container installed via the Unraid app store
InfluxDB API Version**: v2
InfluxDB Connection Settings: Using a token with all-access permissions scoped to the correct organization and bucket.
Problem Description
When I start Home Assistant, the integration fails to connect to InfluxDB and reports the following error in the logs:
InfluxDB bucket is not accessible due to ‘(401) Reason: Unauthorized HTTP response headers: HTTPHeaderDict({‘Date’: ‘Wed, 01 Jan 2025 21:54:39 GMT’, ‘Content-Type’: ‘application/json; charset=utf-8’, ‘Content-Length’: ‘55’, ‘Connection’: ‘keep-alive’, ‘trace-id’: ‘878ac579a75c3939’, ‘trace-sampled’: ‘false’, ‘x-platform-error-code’: ‘unauthorized’, ‘Strict-Transport-Security’: ‘max-age=31536000; includeSubDomains’, ‘X-Influxdb-Request-ID’: ‘4d5e44ded96a5657349b35a090c332fd’, ‘X-Influxdb-Build’: ‘Cloud’}) HTTP response body: b’{“code”:“unauthorized”,“message”:“unauthorized access”}’ ‘. Please check that the bucket, org and token are correct and that the token has the correct permissions set.’
I’ve verified:
- The organization ID (16-character alphanumeric) is correct.
- The bucket name is accurate.
- The token is an all-access token with permissions for the specified organization and bucket.
Interestingly, when I configure only the InfluxDB history component in my YAML (without defining any sensors), Home Assistant starts without issues. However, as soon as I add the sensor
block to query InfluxDB, the 401 errors appear, and the integration fails.
InfluxDB works fine for other services (e.g., a Raspberry Pi writing sensor data via HTTP), so I’m confident the database is set up correctly. The problem seems isolated to the Home Assistant integration.
Here’s the relevant part of my configuration.yaml
influxdb:
api_version: 2
host: localhost
port: 8086
token: BwI7LzY7VZktTpY7LqnDkb4RI5TOr6bor1n-4cy9Xf5QvG-ILXjazbk5oHWuwMC0ajQR08LclccWKkgBitzN5w==
organization: 428b9a2f80bace1c
bucket: SensorData
ssl: false
include:
domains:
- sensor
- binary_sensor
entities:
- weather.home
exclude:
entity_globs: “*”
sensor:
- platform: influxdb
api_version: 2
token: BwI7LzY7VZktTpY7LqnDkb4RI5TOr6bor1n-4cy9Xf5QvG-ILXjazbk5oHWuwMC0ajQR08LclccWKkgBitzN5w==
organization: 428b9a2f80bace1c
bucket: SensorData
queries_flux:- name: “Test Sensor”
query: >
from(bucket: “SensorData”)
|> range(start: -15m)
unit_of_measurement: “test_units”
- name: “Test Sensor”
What I’ve Tried
- Verified InfluxDB Access: I can access InfluxDB via the InfluxDB UI and query the bucket without issues using the same token, organization, and bucket.
- Token Permissions: The token has all access enabled, including read/write permissions for the bucket.
- Organization ID: Confirmed the 16-character alphanumeric ID is correct (not the string name).
- Bucket Name: Double-checked the bucket name.
- Connection Tests: Verified that other clients (e.g., a Raspberry Pi) can write to and read from InfluxDB using the same token.
- Logs:The 401 error suggests unauthorized access, but everything appears to be configured properly.
- successful curl requests and queries using the verified credentials in terminal
Questions
- Could this be an issue with Home Assistant’s InfluxDB integration specifically for API v2?
- Is there a way to inspect or debug the actual JSON payload being sent by Home Assistant to InfluxDB?
- Has anyone successfully used this setup with Home Assistant Container and InfluxDB via Docker? Are there any additional configurations or troubleshooting steps I might be missing?
Thanks in advance for any advice or insights! I’d appreciate any suggestions or examples from anyone who’s successfully set this up.