I’m completely new to Grafana, but I’m already feeling a bit stuck. Maybe you can help me get started so that I can dive into the topic better with some hands-on experience and assistance.
Ich hoffe ich bin hier richtig.
What Grafana version and what operating system are you using?
Grafana 9.2.2 on Homeassistant
What are you trying to achieve?
I have a small PV system and I want to display the generated electricity on a monthly basis in kWh.
My Database in Influx DB.
Here are the specific requirements:
The calendar months should be summed up (not just 30 days).
The data for the generated electricity is available on a daily basis.
It should be represented as a bar chart.
The Y-axis should be labeled in kWh.
The following is my current status.
SELECT mean("value") FROM "Wh" WHERE ("friendly_name"::tag = 'BKW YieldDay') AND $timeFilter GROUP BY time($__interval) fill(null)
Unfortunately, you have set up Grafana & Influx to use InfluxQL. If you can switch to Flux or SQL, then you can aggregate by calendar month as you desire.
The above will likely not yield the correct result, because from the graph you shared, it appears your kW value increases every 24h, then goes back to 0? There is a way using Flux to correctly use that info to calculate your monthly usage. For now, does the above query give you back a monthly graph?
In BKW Yieldday, the total yield is monitored each day. Since the value naturally increases throughout the day, the curve always trends upwards. At the end of the day, the counter is reset to 0.
When I insert the code into InfluxDB or Grafana, I receive an error message.
from(bucket: "home_assistant/autogen")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r.entity_id == "bkw_yieldday")
|> filter(fn: (r) => r.domain == "sensor")
|> filter(fn: (r) => r.friendly_name == "BKW YieldDay")
|> filter(fn: (r) => r.name == "Wh")
|> filter(fn: (r) => r.source == "HA")
|> aggregateWindow(every: 1d, fn: spread, createEmpty: false) // calculates the amount per day using the spread
|> sum() // sums the above 24-hour periods
|> yield(name: "monthly_data")
If the above still yields the same error, then I have an idea, but I would need to see your data in Influx Data Explorer with the Raw Data value toggled on (so I can see what data types you have for domain, friendly_name, name, source, etc.).
OK, so we got rid of the aggregateWindow error message, but still no data. From the Raw Data you shared, I can see the _value field seems to contain a string field called “energy”. You can try this, but I think it still will not work…
Assuming the above does not work, can you toggle Raw Data in Influx Data Explorer and show what you see when you run this query (the one you shared in the beginning of the thread that showed some data/graphs).
The code doesn’t work as expected. No data.
The _value field has multiple values.
One time it is “energy”. Then there is “total_increasing” and also the correct values as a number.
Let’s try what you suggested above, but let’s do 7 days. In Influx Data Explorer, change the time selector to Last 7 days and in the query builder put this: