I think this should do it. Not sure if you have several months worth of data, but in Grafana you should be able to display the monthly totals in a Bar Chart.
from(bucket: "home_assistant/autogen")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "Wh")
|> filter(fn: (r) => r["_field"] == "value")
|> filter(fn: (r) => r["domain"] == "sensor")
|> filter(fn: (r) => r["entity_id"] == "bkw_yieldday")
|> filter(fn: (r) => r["friendly_name"] == "BKW YieldDay")
|> filter(fn: (r) => r["source"] == "HA")
|> aggregateWindow(every: 1d, fn: max, createEmpty: false) // calculates the amount per day using the max value from the day
|> aggregateWindow(every: 1mo, fn: sum, createEmpty: false) // sums each of the amounts per day and aggregates by month
|> yield(name: "monthly data")
The error message you received ("500 Internal Server Error: {"error":"panic: runtime error: invalid memory address or nil pointer dereference"} appears to happen on older versions of Influx. I was using v2.5 when I successfully used the same query with your sample data. Can you please check and advise?
So I believe I have seen this happen in the past, whereby HomeAssistant installs some old version of InfluxDB. There is no Version 5.0.0 of InfluxDB (go ahead and ask them, but you’ll probably have to wait until 2027 or so).
Maybe someone who has deeper familiarity with HomeAssistant and its add-ons can chime in here on how to update InfluxDB to the most current version.
First of all, I would like to apologize for responding only now. Unfortunately, something came up in my personal life, and I couldn’t get to it. I hope you can still help me.
A few days ago, I set up a completely new InfluxDB in Home Assistant, and I believe I am now a step further. There aren’t many data points yet, but it should be sufficient for the start.
This code should actually display calendar months, right? All the data is from July. However, the graph is displayed differently. Am I still doing something wrong here?
And that’s what i got
That seems to be only partially correct to me. It might possibly display the time until August 1st. That might be the reason why the bar starts in August.
A query returned too many datapoints and the results have been truncated at 9311 points to prevent memory issues. At the current graph size, Grafana can only draw 931. Try using the aggregateWindow() function in your query to reduce the number of points returned.
And in the table I got this. This is just a section of the data.
What happens if you replace your aggregateWindow statement with these two?
|> aggregateWindow(every: 1d, fn: max, createEmpty: false) // calculates the amount per day using the max value from the day
|> aggregateWindow(every: 1mo, fn: sum, createEmpty: false) // sums each of the amounts per day and aggregates by month
So it gives you correct result if you have data only for July (i.e. one value dated 2024-08). You can set timeSrc to _start in your aggregation if you want to get 2024-07 for July:
|> aggregateWindow(every: 1mo, fn: sum, createEmpty: false, timeSrc: "_start") // sums each of the amounts per day and aggregates by month using _start column for the output timestamps