15 minute average of electricity power and time shift

Hello!
I would like to create a graph with 15 minute average of my HomeAssistant/InfluxDB/Grafana Shelly3EM data of electricity power. I have a state MojElektro electricity app reference to compare with.
This is the code so far:
from(bucket: “homeassistant/autogen”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“entity_id”] == “power_a_b_c”)
|> filter(fn: (r) => r[“_measurement”] == “W”)
|> filter(fn: (r) => r[“_field”] == “value”)

Now I need to calculate 15 min average of data. Then I must time shift it for 15 minutes in advance to sync it with state app.
MojElektro app shows average of 2kW at 23.45.
Grafana app shows roughly the same kW at 23.30.
I am trying to use Flux in Grafana because of time difference in my measurements vs state measurements (probably NTS problem or data calculation difference).
I will attach screenshots for clarification.
Thank you in advance.

InfluxDB in Grafana:

This is the graph and Flux code in InfluxDB so far:

Hi, again.
I managed to create Flux code for Grafana for 15 minute average. It seems that time shift issue resolved by itself.

from(bucket: “homeassistant/autogen”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “W”)
|> filter(fn: (r) => r[“entity_id”] == “power_a_b_c”)
|> filter(fn: (r) => r[“_field”] == “value”)
|> aggregateWindow(every: 15m, fn: mean, createEmpty: false)
|> yield(name: “mean”)

1 Like

Hello Tomaž!

Do you know in myelektro calculates using rolling interval or in static intervals?

Static Intervals: This means that the intervals are fixed, starting at the top of the hour and then every 15 minutes thereafter (e.g., 11:00 to 11:15, 11:15 to 11:30, and so on). The electricity usage during each of these intervals is measured separately.

Rolling Averages: In this case, the usage is calculated as an average over the last 15 minutes, regardless of the exact start time of the measurement. This method smooths out short-term fluctuations in usage but doesn’t align measurements to specific quarters of the hour.

1 Like

@jure01
There are static intervals. (Fixed at .00, .15, .30 …)
That’s how it looks in Grafana:

@jure01 and @tpehant,
Do you have any specific questions?