InfluxDB 2 Sensor Invalid Config

Hi Everyone,

Been trying to setup a sensor in home assistant from InfluxDB 2 and IOTAWATT ( I dont want to use the IOTAWAT integration as the polling is causing issues)

Please see attached the error I get in the YAML checker and also the code snippets.

Any assistance is greatly appreciated :wink:

  #IOTAWATT INFLUXDB DATABASE
influxdb:
  host: 192
  api_version: 2
  port: 8086
  ssl: false
  organization: c
  token: 6
  bucket: iotawatt
  exclude:
    entity_globs: "*"

sensor:
  ##########INFLUXDB
  - platform: influxdb
    api_version: 2
    organization: c
    token: V
    bucket: iotawatt
    queries_flux:
      - name: "Solar_HA_IDB"
        query: >
          filter(fn: (r) => r["_measurement"] == "iotawatt")
          |> filter(fn: (r) => r["_field"] == "Watts")
          |> filter(fn: (r) => r["input"] == "Solar_HA")
          |> last(column: "_value")
          |> keep(columns: ["_value"])
      - range_start: "-7d"
        group_function: last

I have also tried what is in the documentation InfluxDB - Home Assistant

filter(fn: (r) => r._measurement == "iotawatt" and r._field == "Watts" and r.input == "Solar_HA")

With the same results as the image above.

The only time I got the error to go away was when I had filter in the same indentation as query: > but that throws a different error of filter not existing under “queries_flux” obviously.

Remove the dash in front of range_start

    queries_flux:
      - name: "Solar_HA_IDB"
        query: >
          filter(fn: (r) => r["_measurement"] == "iotawatt")
          |> filter(fn: (r) => r["_field"] == "Watts")
          |> filter(fn: (r) => r["input"] == "Solar_HA")
          |> last(column: "_value")
          |> keep(columns: ["_value"])
        range_start: "-7d"
        group_function: last


Thank you that was indeed the fix.

I also had to add the host,port, and ssl to the sensor section, weird I thought it would pull it all from influxdb section.

Thanks for the help!