Energy consumption current hour vs. hour with highest consumption within current month

First some background.

In Norway the amount of NOK that you are invoiced on your energy bill is a factor of many components. One of these components is a called an “max power component”. This is calculated based on the one hour within each month that you consumed the most amount of energy (kWh). This means that one very energy intense hour within a month can ruin a whole month, even if all other hours have very light energy usage. The obvious solution to minimize the “max power component” is to have all hours being equal, which is also the incentive by having this “max power component”.

So what I want to create is a graph that shows the aggregated energy consumption within the current hour and compare it to the most energy intense hour within the current month. Se the desired end result below

This will allow you to track your accumulated energy usage within current hour and compare it o the hour with the most intense energy usage and gauge of you are on track to exceed the most intense hour or not.

The energy data is stored in an influxDB with aggregated energy consumption logged every 10s. This aggregation resets at the start of every hour.

To solve this, a lot of things needs to happen that I have partly solved individually, but not put together yet.

  1. Find the hour with the highest energy consumption within the current month and record the value.

I’ve solved this part. Following influxQL query gets this max value. Relative time is set to “now/M” (This month so far).

SELECT max(“max”) FROM (SELECT max(“value”) FROM “full_resolution”.“tibberData” WHERE (“name” = ‘Energy’) AND $timeFilter GROUP BY time(1h) fill(null))

Inner select statement gets the max value per hour and groups then in 1h intervals.
Outer select statement gets the value from the hour with the highest value

  1. The value found in step 1 needs to be put on a graph at time 59m59s (point A in picture above) and needs to be linear filled from an point with value 0 at time 0m0s. This should create the red line seen in the picture above.

  2. Plot the green line. The query for this is not to difficult.

SELECT last(“value”) FROM “full_resolution”.“tibberData” WHERE (“name” = ‘Energy’) AND $timeFilter GROUP BY time($__interval) fill(null)

The key to get this to work is to keep the time range at “from now/h to now/h” (this hour).

In conclusion I need to solve the following:

a) Figure out step 2 above and put that into “query A” in a graph panel
b) Figure out how to override the timerange for said graph panel so that only the graph panel is “from now/h to now/h” and not the whole dashboard
c) Set step 3 above as “query B” in the same graph panel

So, I managed to solve point 2. I basically made a new measurement in the influxDB where I inserted a “0” value at the start of every hour and the max value from point 1 at 59:59 of current hour. Then graphed this in grafana.

Next. How can you replicate the “from now/h to now/h” in a single panel?