InfluxDB v2 Sensors

I have an external InfluxDB that tracks a handful of sensors and I want to include these sensors as, well, sensors, in HA. However, the official docs don’t really work for me.

I tried the config based on the docs:

influxdb:
  api_version: 1
  ssl: false
  host: <host>
  port: <port>
  username: <user>
  password: <p>
  database: primary
sensor:
  - platform: influxdb
    api_version: 2
    ssl: false
    host: <host>
    port: <port>
    bucket: <bucket>
    organization: <org>
    token: <token>
    queries_flux: 
      - range_start: "-10d"
        name: "How long have I been here"
        query: >
          from(bucket: "Data")
          |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
         ...
          |> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
          |> yield(name: "last")
        value_template: "{{ value }}"

The disparity between v1 and v2 in both blocks was intentional, since there seem to problems with the v2 integration. I also tried just the first or just the second block, empty first block, etc… A bunch of combinations. Nothing worked.

Weirdly enough, the error message of the influx component keeps insisting, that it can’t connect to localhost, which is not the host I configured anywhere.

Background

I have some sensors that are supposed to save power and not send data all the time, so they accumulate a bunch of values and flush them all out via MQTT every hour or so. The MQTT integration does not seem able to read timestamps from the messages so I chose the sligthly indirect route via Influx.

Just to be sure, the first block is to push data to influxdb.
The second one pulls, which I understand is what you want.

See the note in the doc as well

I already tried that - and just tried again - nothing.

Maybe I’m completely misunderstanding the concepts here, but if I define a sensor as stated above and everything works fine, I should see the sensor in the device or entity tabs in the config, right?

Hey there, i’m new to HomeAssistant. And I have a similar Problem. My configured Sensor does not show up anywhere.
My Config:

   sensor:
  - platform: influxdb
    api_version: 2
    ssl: false
    host: !secret influx_host
    port: 8086
    organization: !secret influx_org
    token: !secret influx_key
    bucket: sensors
    queries_flux:
      - range_start: "-1d"
        name: "Solar Power"
        bucket: sensors
        unique_id: 9784ff08-081e-4531-a41a-eb99296f4cf2
        unit_of_measurement: kwh
        query: >
          filter(fn: (r) => r["_measurement"] == "Solar")
          |> filter(fn: (r) => r["_field"] == "value")
          |> integral(unit: 1h, column: "_value")
          |> keep(columns: ["_value"])
        value_template: "{{ value|float / 1000.0}}"

EDIT: It suddenly works. Sorry for bumping this POST.