I am using grafana 10.4.1 as part of home assistant on a raspi 4 together with influxdb 1.8.10.
I want to have a cumulative sum in a graph of my savings from my solar panels. That is easy in my eyes as long a the kWh cost remains constant. I do have a metric with the sum of the self-used kWh and this can be multiplied by some constant kWh cost.
But now I do have 2 kWh cost changes in fast succession and I want that cumulative sum still to be correct.
So I introduced a new metric with the kWh cost to move away from that constant kWh cost.
Now I do see 2 approaches which both failed up to now:
Create a grafana visualization with 3 series
a) the kWh cost
b) the daily sum of self used kWh
c) a) and b) multiplied (using a math expression) for the daily savings
Now I do want another expression/transformation/whatever to build a cumulative sum (and graph that) on the results of c), but I can’t find a way to do that.
Do all the math not in grafana but in influxdb. But I read that infuxql does not support joins of different series (e.g. how to join two measurement of influxdb - Stack Overflow) and all I tried failed. At least influxql has the cumulative_sum function to archieve similar stuff, but due to the lack of joins I have no better idea. Only fluxql does seem to have join support, but can’t be used from grafana, right? And is fluxql even capable of a cumulative_sum as well?
SELECT max(“value”) - min(“value”) FROM “kWh” WHERE (“friendly_name”::tag = ‘Solar_selbst_verbraucht_Summe’) AND $timeFilter GROUP BY time(1d) fill(previous)
Query to get series for cost of kWh:
SELECT mean(“value”) FROM “EUR” WHERE (“friendly_name”::tag = ‘Strom_Preis_pro_kWh’) AND $timeFilter GROUP BY time(1d) fill(previous)
And here is one of my influxql ideas which did not work out:
select
CUMULATIVE_SUM( SUM(self_used_kwh * cost_kwh) )
from
(
SELECT max("value") - min("value") as self_used_kwh FROM "kWh" WHERE ("friendly_name"::tag = 'Solar_selbst_verbraucht_Summe') AND $timeFilter
),
(
SELECT mean("value") as cost_kwh FROM "EUR" WHERE ("friendly_name"::tag = 'Strom_Preis_pro_kWh') AND $timeFilter
)
GROUP BY time(1d)
fill(previous)
Error is:
failed to execute query [C]: expected field argument in sum()