Just in case it matters, the data comes from a Current Cost Envir device, and represents the current power consumption in Watts.
It is then sent to Home Assistant through MQTT.
Home Assistant writes it into Influxdb, and then Grafana uses this influxdb as data source.
Now, all looks good and reasonable to me apart from the “Totals” in the legend.
For example, the fact that the whole house used 1.3KW on average for the past 6 hours, seems very reasonable.
The “Total” though, displays 2.8MW!?!
I think it should be more something like 7.8KW (the average 1.3KW x 6 hours).
Can anyone help me figuring out what I am doing wrong please?
Your query needs to return the sum for each time interval , the legend values are calculated based on what your query returns. Avg and total cannot be both correct at the same time (if your query contains any aggregation using avg for example).
If you want correct total you need to adjust your query aggregation to sum
It is? Did you sum all the values returned by your query? I highly doubt that grafana total is wrongly calculated.
Maybe your values in InfluxDB are already averaged (and cannot be used to get a total) without some math?
Of course, if you change the aggregation function from mean to sum all the legend values will change.if have mean function in query only avg,and current in legend will always correct (depends on time range).
If you need max in legened to be correct you need max aggregation function in your query