kalkih / mini-graph-card

Minimalistic graph card for Home Assistant Lovelace UI
MIT License
2.97k stars 232 forks source link

Aggregate functions calculate wrong values? #711

Closed emign closed 2 years ago

emign commented 2 years ago

Hallo,

I believe, that the data source for the aggregate functions does not reflect the correct data. I found, that mini-graph gives different results for the aggregate functions than comparable queries on the influxdb data for the same time-intervals.

I use this wonderful card for displaying statistics for my Heatpump COP. I will explain the issue with example data of January 27. 2022.

Collected sensor sensor.cop_ohne_dhw

Mini graph card configuration

type: custom:mini-graph-card
entities:
  - entity: sensor.cop_ohne_dhw
    aggregate_func: avg
    name: Avg
    color: blue
name: COP
hours_to_show: 168
group_by: date

Visualisation

Home-Dashboard - Home Assistant 2022-01-29 17-08-55

What I want to achieve Display the average COP for each day.

Problem The values in mini-graph differ from the correct values (see this google spreadsheet which contains all values from Jan 27 and Jan 28. There I also show other aggregate functions) extracted with this influx query:

SELECT "value" AS "mean_value" FROM "haDatabase"."autogen"."state" WHERE time > '2022-01-27T00:00:00Z' AND time < '2022-01-27T23:59:59Z' AND "entity_id"='cop_ohne_dhw'
Home-Dashboard - Home Assistant 2022-01-29 17-10-53

Question Am I overlooking something? Is it maybe a timezone problem?

R5fan commented 2 years ago

I have the same problem. I think the average is calculated per data point or something? However, my sensors dont update if there is no change in data, so some power sensors may be at 0W for many hours (and with no or very little updates) and then some spikes, and the average is completely wrong. As an example running my microwave for 4 mins:

image

I installed the sensor 4-5 hours earlier, mini-graph card gives me an average of 590W !

jlsjonas commented 2 years ago

Sounds like a duplicate of #618, thanks for the extra insights though!

We'll hopefully be able to tackle this sometime soon, but after the configuration update.