InfluxDB sensor import

I am trying to get a sensor working for a very simple database. It has a time input every 30 mins. This query works on InfuxDB data explorer. InfluxDB and Home Assistant are running as separate containers on the server.

from(bucket: "mybucket")
  |> range(start: -30d)
  |> aggregateWindow(every: 30m, fn: mean, createEmpty: false)
  |> keep(columns: ["_value", "_time"])
  |> yield(name: "energy")
  |> last(column: "_value")

I have added the same to my sensor but not getting the same results. The group_function is taking care of the |> last and the range_start is taking care of the range. I had filters in but it doesn’t seem to make a difference

This is what I’m getting on my sensor. It is all being plotted today and just random data points so I don’t understand what’s going on. No errors in the logs.
image


influxdb:
  api_version: 2
  host: myhost
  ssl: false
  port: 8086
  token: mytoken
  organization: myorg
  bucket: homeassistant
  tags:
    source: HA
  tags_attributes:
    - friendly_name
  default_measurement: units

sensor:
  - platform: influxdb
    api_version: 2
    host: myhost
    port: 8086
    token: mytoken
    organization: myorg
    bucket: mybucket
    ssl: false  
    queries_flux:
      - range_start: "-30d"
        name: "Test Read"
        unique_id: myuniqueid
        query: >
          aggregateWindow(every: 30m, fn: mean, createEmpty: false)
          |> keep(columns: ["_time", "_value"])
          |> yield(name: "energy")
        unit_of_measurement: kWh
        group_function: last
        value_template: "{{ value }}"

Thanks for any advice!