kalkih / mini-graph-card

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

Changing a unit of measure of an entity is not reflected in the graphs #945

Open mfarad opened 1 year ago

mfarad commented 1 year ago

If we have an entity providing value in watts and we change his unit of measurement (by ex: in kW), the value displayed in the card is correct (kW) but the graph (+color_thresholds) is still based on the original value (watts).

Card:

  type: custom:mini-graph-card
  entities:
    - sensor.powerglobal_watts
  font_size: 100
  name: Power Global
  state_adaptive_color: true
  color: '#e6005c'
  icon: mdi:flash
  color_thresholds:
    - value: 1000
      color: '#1cf100'
    - value: 2000
      color: '#b5f100'
    - value: 5000
      color: '#f1b500'
    - value: 7000
      color: '#ff0000'
  points_per_hour: 30
  hours_to_show: 24
  hour24: true
  update_interval: 1
  align_state: center
  show:
    labels: false
    fill: true

card

Entity:

entity

ildar170975 commented 1 year ago

You told that you converted a value to kW. But according to your pictures, it was in kW (left picture) -> then became something x1000 (right picture) w/o a unit. Seems some info is clipped since you preferred to display the card with a narrow width.

ildar170975 commented 6 months ago

Anyway, see not issues here: 1) Sensor with device_class: power & UoM="W": state is shown in "W", graph is shown in "W":

image

type: custom:mini-graph-card
entities:
  - sensor.testing_device_class_power
points_per_hour: 480
hours_to_show: 0.083333
lower_bound: 0
line_width: 3
smoothing: false
show:
  labels: true

2) UoM changed to "kW": state is shown in "kW", graph is shown in "kW":

image

Ofc data in DB (numbers) are still same w/o conversion to the new UoM. The very same happens with a standard history-graph:

image

If we consider this behaviour as a bug - then we should consider a behaviour of history-graph also incorrect. https://github.com/home-assistant/frontend/issues/19468 So, let's wait for a feedback from HA dev team. If they say that this is an intended behaviour - then probably we will have to suspend this issue as well. Imho a recalculation of previous points should only be done for sensor entities with defined UoM (belonging to the device_class). For other entities & when no device_class is specified - no recalculation should be done.