Hi,

I saw people asking similar questions in the forum, but couldn’t find an answer. Thus trying again:

Currently I managed to get to ONE value, representing the mean power consumption during a specific time period, e.g. today so far 262W consumption in average.

In detail, this query…

from(bucket: “openHAB”)

|> range(start: today(), stop: now())

|> filter(fn: (r) => r[“_measurement”] == “Shelly3EM_ALL_CURRENTWATTS”)

|> mean()

…results in:

What’s missing is a mapping or rather calculation to kWh, e.g. using

|> map(fn: (r) => ({r with _value: r._value * TIME_PERIOD__HOURS / 1000.0}))

I tried several attemps with “date.hour(now ())” but I always faced syntax erros

Any help is highly appreciated.

I’ve now addressed this the following way. No clue if there is a more elegant solution:

passedHours = from(bucket: “openHAB”)

|> range(start: today(), stop: now())

|> filter(fn: (r) => r[“_measurement”] == “Shelly3EM_ALL_CURRENTWATTS”)

|> elapsed(unit: 1s)

|> aggregateWindow(every: 1d, fn: sum, column:“elapsed”)

|> map(fn: (r) => ({ r with elapsed: float(v: r.elapsed)/3600.0 }))

averageWatt = from(bucket: “openHAB”)

|> range(start: today(), stop: now())

|> filter(fn: (r) => r[“_measurement”] == “Shelly3EM_ALL_CURRENTWATTS”)

|> aggregateWindow(every: 1d, fn: mean)

join(tables: {t1: passedHours, t2: averageWatt}, on: [“_time”])

|> map(fn: (r) => ({ r with kWh: float(v: r._value) * float (v: r.elapsed) / 1000.0}))

|> drop(columns: [“_value”, “elapsed”])