kalkih / mini-graph-card

Minimalistic graph card for Home Assistant Lovelace UI
MIT License
2.89k stars 233 forks source link

100 times bigger values for some entities #959

Open lubosramo opened 1 year ago

lubosramo commented 1 year ago

For some entities my graphs show incorrect value - it shows 100 times bigger value.

In this graph - last bar value shows 1 952 408W, but correct value is 19 524,08W. image

Only correct value is showed for current value (126W): image

Here is my card definition:

type: custom:mini-graph-card
entities:
  - entity: sensor.power_house_net_consumption_w
name: House consumption daily last 7 days - values problem
hours_to_show: 168
aggregate_func: sum
group_by: date
decimals: 0
value_factor: 0
hour24: true
show:
  graph: bar

If I use "value_factor: -2" - values for graph bars are correct: image

But then current value is 100 times lesser (it shows 1W instead of 126W).

If I use the same card for temperature, everything is ok.

The entity I use in card is calculated this way:

 power_house_net_consumption_w:
        friendly_name: "Active house consumption (W)"
        unit_of_measurement: 'W'
        value_template: "{{ (((states('sensor.inverter_active_power')|int - states('sensor.power_meter_active_power')|int) if (states('sensor.power_meter_active_power')|int > 0) else (states('sensor.inverter_active_power')|int - states('sensor.power_meter_active_power')|int)|abs ) ) | int }}"

Any help, what is the reason for such problem?

akloeckner commented 1 year ago

Just a quick guess: you have aggregate function sum. So, the bar will show the sum of all states occurred during one day. If you have 100 changes per day, that might be the issue.

lubosramo commented 1 year ago

Thanks for the tip. But I do not think it is relevant. Function "sum" is only one which can sum energy for one hour. At least I do not see any other possible aggregate function in documentation. And also - the problem is not "100" as an absolute number, but my values are 100 times bigger (e.g. 20 000W instead of 200W). So there must be some code which recalculates energy by coeficient 100. But I have no clue why such code should even exists ...

ildar170975 commented 1 year ago

Try to SIMPLIFY your issue to localize a possible bug: -- do not use grouping, -- do not use sum, -- create a test template sensor with similar random values.

lubosramo commented 1 year ago

Thanks, so I have tried this:

image

type: custom:mini-graph-card
entities:
  - entity: sensor.power_house_net_consumption_w
name: House consumption testing
hours_to_show: 4
points_per_hour: 4
hour24: true
show:
  graph: bar

Now it seems that units are ok (no 100 times multiplying). But I do not know what is result (interpretation) of such graph, it looks like max value per interval, but I can not proove it.

In my graph above there are 15 minutes intervals like 17:06-17:20. How can I achieve intervals like 17:00-17:15, 17:15-17:30 ... so starting from whole hour?

I did several tests and it seems that the problem is "aggregate func: sum". It calculates "good results", but with wrong decimal point - 100 times bigger values than they are in reality. If I use e.g. min or max function, everything is ok.