Writing data to InfluxDB

Hi,

I have an issue with writing event data from HA to an InfluxDB bucket.
in short, it boils down to this; The HA debug logging for the InfluxDB integration reports it is writing data but I am unable to find any data in InfluxDB.

2022-08-27 13:06:13.822 DEBUG (influxdb) [homeassistant.components.influxdb] Wrote 26 events.

I run HAOS 8.5 (Core 2022.8.6) in a KVM instance on my TrueNAS-SCALE-22.02.2.1 NAS.
I run InfluxDB 2.4 in an influxdb2022.0.0 Docker container on the same NAS.
HAOS is able to access the influx container across a bridge interface.

the influx config in HA is as follows (from this guide);

# saving data to influxdb
influxdb:
  api_version: 2
  ssl: false
  host: [influxdbdockerIP]
  port: 8086
  token: [tokenthathaswriteaccess]
  organization: bb87ec5d0a46acb1
  bucket: home-assistant
  tags:
    source: HA
  tags_attributes:
    - friendly_name
    - device_class
  default_measurement: units

If I change this config to something I know will not work, I get errors in my HA log - example, if I change the host ip;

2022-08-27 13:17:48.103 ERROR (SyncWorker_7) [homeassistant.components.influxdb] Cannot connect to InfluxDB due to ‘<urllib3.connection.HTTPConnection object at 0x7f8c966efbe0>: Failed to establish a new connection: [Errno 113] Host is unreachable’. Please check that the provided connection details (host, port, etc.) are correct and that your InfluxDB server is running and accessible. Retrying in 60 seconds.

Likewise, if I update the config so it is correct but turn off the docker container, I get a similar message - so I know that HA can see and validate that InfluxDB is there and is sending data, I just don’t see that data arrive in InfluxDB.

The token in use has write access to the bucket mentioned, not that it matters, if I change the token to a new one with RW or the local admin one created during initial setup, then I get the same result; HA reports it’s writing data but nothing appears in InfluxDB.

I can check that InfluxDB is active and listening with the following curl;

curl -sL -I <influxiphere>:8086/ping

And that gives me a 204 HTTP response which, acoording to InfluxDB here is a succes;
image

So everything I have available to me says I’m writing data to InfluxDB but the Data Explorer is giving me a whole lot of nothing.

I’ve gone through Discord and the forums here and checked issues on github but nothing jumps out at me as being related.
Before I go bang on Influx’ door(I have since crossposted on Influx’ community forums here) asking if there’s anything obvious I’ve missed I was hoping someone could point me to an obvious oversight on my part.

I can post my config if you think it will help…

influxdb:
  api_version: 2
  host: 192.168.1.11
  token: #TOKEN#
  bucket: home_assistant2/autogen
  port: 8086
  ssl: false
  verify_ssl: false
  organization: #ORG#
  measurement_attr: entity_id
  include:
    entities:
      - weather.city
    domains:
      - sensor
      - switch
      - person
  exclude:
    domains:
      - automation

Hi there!

Thank you for taking the time to reply and for sharing your config.
I’m sorry to say this didn’t help.

I did note a couple of differences between yours and my config, for example you’re appending the autogen retention policy to the bucket name, specifying the entity_id as a measurement attribute and have additional includes and an exclude that I don’t have.

I changed my config to include the retention policy to the bucketname was immediately met with a 404 response code reporting that it doesn’t exist so I removed the autogen and all is “well” again.
I added the measurement_attr to my config which didn’t actually change anything for me.

Finally, I deleted my home-assistant bucket, created a new home_assistant bucket and changed the API token to match.

influxdb:
  api_version: 2
  ssl: false
  host: [ip]
  port: 8086
  token: [newtoken]
  organization: bb87ec5d0a46acb1
  bucket: home_assistant
  tags:
    source: HA
  tags_attributes:
    - friendly_name
    - device_class
  default_measurement: units
  measurement_attr: entity_id
  include:
    domains:
      - sensor
      - switch
      - person

Alas - same issue;

all these writes, but no data in the actual bucket in InfluxDB. :frowning:
image

Maybe this is a difference in which version of the InfluxDB frontend you’re looking at but when I click on my bucket I see this:
Screen Shot 2022-08-29 at 10.17.18 AM

I tried clicking the plus column to add a filter so it would show me the list of fields and I don’t see _measurement anywhere. I do see unit_of_measurement though which has the same options as measurement:
Screen Shot 2022-08-29 at 10.18.47 AM

Are you sure you’re looking at the right field? Have you tried switching to others?

Hi and thank you, too, for taking the time to reply.

My issue is there just isn’t any data in InfluxDB at all so there are no other fields for me to check;

Because the bucket hasn’t been populated at all, I don’t have anything in it to switch or toggle or look at other than this.

That is very strange. Is there any errors in the logs of InfluxDB? Maybe HA thinks its sending things successfully but InfluxDB isn’t accepting it?

Also what is the time range? That does affect what shows up there. I assume its a valid one.

EDIT: Also did you check permissions of the user you are using? They have permission to read from that bucket in that org right?

Apologies for the late reply - it’s been a nightmare week.

Late last night, I managed to ‘fix’ the issue and can confirm it’s not HA related.
It has something to do with disc permissions of the data folder of InfluxDB.
While I can’t quite put my finger on what exactly is going wrong, I do now have a working influx integration in HA which is sending data to Influx.

Hey :wave:
can you say me how you fixed this?

For me the data export to InfluxDB running in a Docker container with “bridge” mode, the following works. HA is running on “host”, as per official HA docker setup docs.:

host: must be an IP (at least for me). I does not work for me using the Docker containers’ hostname of Influx, influxdb. I have to use the actual bridge IP of the Docker container 172.17.0.2. It cannot be the NAS physical IP when both HA and Influx run in containers, someone told me.

Another thing which works seems to be:
Set network of InfluxDB also to host. Then I can simply use the NAS IP for host: in HA config, not the docker bridge IPs (which might change over container re-creation anyways).

I don’t see any security implications of running Influx on Docker host network, since HA runs there too. Please correct me if that is false.