Populate sensor sensor state with historical data from influxdb

Hi folks,

I have a question regarding using an influxdb sensor to populate it with data (from influxdb) from the last 6 months. Below is the query I have put as a influxdb sensor.

- platform: influxdb
  api_version: 2
  ssl: false
  host: xxx.xxx.xx.xx
  port: 8086
  organization: home
  token: !secret influxdb_home_bucket_read_token
  bucket: 'homeautomation'
  queries_flux:
    - name: "test test"
      group_function: mean
      query: >
          filter(fn: (r) => r["friendly_name"] == "covid_zimbabwe" and r["_field"] == "Active_Cases")
          |> aggregateWindow(every: 1h, fn: mean, createEmpty: false)
          |> yield(name: "mean")
      range_start: "-180d"

This query does work within influxdb, as in, I get the correct data and plot and also runs on home assistant with error, however I get the following info from the log:

Query returned multiple results, only value from first one is shown: from(bucket:“homeautomation”) |> range(start: -180d, stop: now()) |> filter(fn: (r) => r[“friendly_name”] == “covid_zimbabwe” and r[“_field”] == “Active_Cases”) |> aggregateWindow(every: 1h, fn: mean, createEmpty: false) |> yield(name: “mean”) |> mean(column: “_value”).

which leads me to the observation that, similarly to the sql integration (SQL - Home Assistant), it only returns the last/first value from a query. But then again, perhaps I’m just missing something.

FYI: I do know that I can expose dashboards from influxdb/grafana and embed them in home assistant, but this is not what I want.

1 Like