InFluxDB2 Field not found (because no data was written to it yet today)

Hi everyone!

I have an element in grafana that shows me the total Energy (kWh) that was sent to the Battery today.

The problem is that until my solar inverter begins to charge the battery, the field does not exists for a “today” query.
And so I get a “field not found” until the inverter begins to charge the battery.

Is there a way to “create” the E_STORAGE_CHARGE field with a 0 if it does not exist? :slight_smile:

import "timezone"
import "date"

option location = timezone.location(name: "Europe/Vienna")
  from(bucket: "fronius_aktuell")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "actual")
  |> filter(fn: (r) => r._field == "E_STORAGE_CHARGE")
  |> difference()
  |> sum()
  |> group(columns: ["_field"])
  |> pivot(rowKey: ["_start"], columnKey: ["_field"], valueColumn: "_value")
  |> map(fn: (r) => ({r with E_Speicher_Ladung: r.E_STORAGE_CHARGE}))
  |> keep(columns: ["_start", "E_Speicher_Ladung"])

Hi @cholzer1979

I think this should be possible using a condition in your Flux query. Have you tried anything?

I do not see a clever way for Grafana to change the field E_STORAGE_CHARGE to 0 if it does not exist, but in your results, to avoid the Field Not Found message, perhaps an override or value mapping expression in Grafana would help?

1 Like

I have tried:

|> map(fn: (r) => ({
      r with
      _value: if exists r._value then float(v: r._value) * 1  else 0.0
    })
  )

But while the * math works (I tried with * 2), the “else” does not create the field when it does not exist.

I have tried the options for the “special” value mappings, but that did not affect the “field not found” in canvas. :-/

Hi again @cholzer1979

Did you see this, and are you using the latest version of Grafana?

Not related to my issue.
The fields work just fine, if they actually exist/have data.

As I explained I have that problem only with the E_Storage_Charge field as that does not exist for today() until the inverter begins to charge the battery.

As a workaround I now use node-red to read the last value from E_Storage_Charge and store it in E_Storage_Charge at 0:01 AM, so from that time I now do have a value in E_Storage_Charge for today()

For the benefit of other forum readers: