Group energy demand by daytime and nighttime (sunrise/sunset-based)

Hi guys,

I struggle with my data formatting as described below. It’s about summarising energy demand during day- and nighttime (see “What”).

  • What Grafana version and what operating system are you using?
    Grafana v9.3.2, runs on a RPi 4 in combination w/ InfluxDB v1.8.10

  • What are you trying to achieve?
    Basically, I track continuously (10s raster) the energy consumption to derive the best-fitting battery size (based on the data) that covers my energy consumption during the night.
    Therefore, I would like to group my time series by two different intervals, representing day- and nighttime. In theory, I want to “group by” intervals (1) from sunrise to sunset and (2) from sunset to sunrise dynamically.
    A more “static” approach would be fine as well e.g., fixed intervals (1) from 8am to 5pm and (2) 5pm to 8am.

  • How are you trying to achieve it?
    See config below.

  • Can you copy/paste the configuration(s) that you are having problems with?

    SELECT difference(last("Energy_Demand")) FROM "smartMeter" WHERE $timeFilter GROUP BY time(12h,5h)
    

This configuration works only, in case I use 12h/12h intervals (I also know how to shift them).
Any idea, how it works with 15h/9h interval from (1) 8am to 5pm and (2) 5pm to 8am?

@grant2 can you please take a look and also decide if this is more of a influxdb query question or really related to Time-Series panel?

Thanks

Hi @usman.ahmad and @jonets

My understanding is that goal here is to have a query that only return results during specified hours of the day. The Flux hourSelection function returns only data with time values in a specified hour range, but acc. to this, InfluxQL does not support this type of function.

The GROUP BY time(time interval) function in InfluxQL determines how InfluxDB groups query results over time. For example, a time_interval of 12h groups query results into 12-hour time groups across the time range specified in the WHERE clause.