Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If a point with a zero value is selected - then a wrong state is displayed #805

Closed
DamianosS opened this issue Jun 28, 2022 · 32 comments
Closed
Labels
bug Something isn't working released on @dev released

Comments

@DamianosS
Copy link

My weather station measures the amount of rain with a rain counter, which sums up the continuous amount of rain.
For showing the daily rain, I've configured the following card:

type: custom:mini-graph-card
name: Daily Rain
entities:
  - entity: sensor.weather_station_rain_counter
show:
  graph: bar
hours_to_show: 168
aggregate_func: delta
group_by: date
hour24: true
line_color: '#15317E'
labels: true 

The result seems correct:
mgc 01
27.4 mm is the total amount so far.

When hovering over the particular days, the card shows the correct value unless on that day there was no rain. Than it shows the total amount. However, IMHO it should show "0":
mcg06

Is my configuration wrong, or is it a card issue?

Thanks!

@pleasereset
Copy link

Chiming in to say that I can reproduce the issue with a simple graph, no aggregation

type: custom:mini-graph-card
entities:
  - entity: sensor.master_bathroom_illuminance
    name: Lux
line_color: '#e3d5ca'
line_width: 8
font_size: 75
points_per_hour: 2

@bartoszkaminski
Copy link

bartoszkaminski commented Aug 23, 2022

@tomkessler
Copy link

I have a similar issue where it's not just 0 values that don't update the number displayed, it's also "small values". I used 0.55 hours of A/C on Saturday 3 Sept, but the number won't indicate that.

Here's the config of the card:

type: custom:mini-graph-card
entities:
  - entity: sensor.hvac_cooling_today
    name: A/C
    color: '#595BBD'
    show_state: true
show:
  graph: bar
  labels: true
  legend: false
hours_to_show: 196
lower_bound: 0
group_by: date
aggregate_func: max
name: Daily A/C Usage
icon: mdi:air-conditioner

The current value is 1.96 hr, yet mousing over the bar which should show 0.55 hr doesn't cause an update.

image

@Ascathon
Copy link

It just shouldn't show any bar at all when 0. First I thought chart was wrong with the shorter bar showing a higher value than the larger bar next to it. But it was the total 24 hour value.
0, no data, no bar. In my utility meter it looks like the was power consumed during the night.

@scharmach
Copy link

Not a solution, only a workaround:

color_thresholds:
  - value: 0
    color: '#1c1c1c'
  - value: 1
    color: '#a4958b'
  • 0 = colour of the background
  • ≥ 1 = colour of the bars

grafik

@ildar170975
Copy link
Collaborator

ildar170975 commented Oct 27, 2022

Everyone who faced this issue with a line graph and w/o an aggregation - have you tried to set points_per_hour more or equal to a real scan_interval ?

@wizake
Copy link

wizake commented Nov 10, 2022

I'm also having this issue with a bar chart :(

@darynwilkinson
Copy link

I'm having the same issue with a line chart.

image

type: custom:mini-graph-card
name: Bedroom
entities:
  - entity: sensor.bedroom_temperature
    name: Current
    show_fill: false
  - entity: sensor.target_temperature_bedroom
    name: Target
    color: '#bc79f2'
    show_state: true
    show_fill: false
  - entity: sensor.heating_demand_bedroom
    show_line: false
    show_state: true
    name: Demand
    color: '#ccffcc'
    y_axis: secondary
show:
  icon: false
  labels: true
  labels_secondary: true
  average: true
  extrema: true
points_per_hour: 2
lower_bound_secondary: 0
upper_bound_secondary: 100

@ildar170975
Copy link
Collaborator

ildar170975 commented Nov 29, 2022

There is a bug here.

type: custom:mini-graph-card
entities:
  - entity: sensor.xiaomi_cg_1_co2
    show_state: true
  - entity: sensor.xiaomi_cg_1_pm25
    show_state: true
    y_axis: secondary
show:
  icon: false
  labels: true
  points: true
  name: false
  labels_secondary: true
line_width: 1
smoothing: false
aggregate_func: last
points_per_hour: 120
hours_to_show: 1
lower_bound: ~400
lower_bound_secondary: ~0

Both sensors are updated twice a minute.

When none graph is selected:
image

When a primary graph is selected (values vary from 400 ppm):
image

When a secondary graph is selected (values vary 0 .. 1 μg/m³):
for a non-zero point:
image

for a zero-point - the LAST primary sensor's value is displayed and the secondary sensor's UoM:
image

Note that the current value for the primary sensor is 689.

@ildar170975 ildar170975 changed the title Not showing zero values in bar chart when hovering over them If a point with a zero value is selected - then a wrong state is displayed Nov 29, 2022
@ildar170975 ildar170975 added the bug Something isn't working label Nov 29, 2022
@akloeckner
Copy link
Collaborator

I do not yet understand fully the logics in this card, so forgive me, if I am stupidly mistaken. I'd also test this myself. But I don't know yet, how to do that. So, here I am, trying to help "offline"...

I browsed through the code and found this line:

${this.computeState(isPrimary && tooltipValue || state)}

It looks to me, as if the tooltipValue (which I believe to be the currently hovered-over point) is only displayed if it is "truthy". But 0 is not truthy. Hence, the state is shown. Could this be the cause for this bug?

@darkenbula
Copy link

Has this fix been pushed out? I am still getting the same value with zero values showing the max value and not zero

`entities:

  • entity: sensor.skye_rainfall
    lower_bound: 0
    hours_to_show: 168
    name: Daily Rain
    line_color: '#3190de'
    aggregate_func: max
    group_by: date
    show:
    graph: bar
    labels: true
    type: custom:mini-graph-card
    `

graph

@akloeckner
Copy link
Collaborator

#880 should fix this issue. But we haven't merged it yet.

@ntzb
Copy link

ntzb commented Mar 7, 2023

@akloeckner unfortunately I don't see that it fixed the issue.
can anyone else verify?

@akloeckner
Copy link
Collaborator

Did you download the branch from#880? If that didn't help, I'll have to fix #880. If it does help, I'll just need to merge #880. (I just didn't get around to this properly...)

@ntzb
Copy link

ntzb commented Mar 7, 2023

sorry, my bad, looks like it was a cache issue, I tried in another browser and it seems to do the job, so thanks!
but I still see something strange in Chrome (which is not replicated in Firefox).

edit: just stupid cache issues

@akloeckner
Copy link
Collaborator

Hmm... Maybe, it's the same cache issue?

Because I think the fix should be the same for both primary and secondary graphs. So, if #880 fixes the zero tooltip on the primary graph, I would expect it to fix the zero tooltip for the secondary graph, too. But I might be mistaken.

(Thanks for the feedback on #880 fixing the primary tooltip at least, for you too!)

@ntzb
Copy link

ntzb commented Mar 7, 2023

yes, same cache issue, sorry about that.
okay so from my testing, your PR seems to solve the issue

@akloeckner
Copy link
Collaborator

Ok, thanks for the feedback! I'll try and merge it soon. I just want to get some guidelines straight before that...

@ntzb
Copy link

ntzb commented Apr 22, 2023

@akloeckner I see you commit on the dev branch.
is there any plan on merging dev to master? or release a dev version?
HACS doesn't list dev branch

@akloeckner
Copy link
Collaborator

Yes, my plan was to create a release, now that I have merged all the fixes. But... I will have to understand how that works. :-) That might take some more days, because I guess there is some automated way to do this...

github-actions bot pushed a commit that referenced this issue Apr 22, 2023
# [0.12.0-dev.1](v0.11.0...v0.12.0-dev.1) (2023-04-22)

### Bug Fixes

* add first datapoint tooltip for line graph ([#882](#882)) ([7576fe6](7576fe6))
* allow zero tooltip ([057a395](057a395)), closes [#805](#805)
* drop out-of-bound coords in reducer ([#881](#881)) ([527f005](527f005)), closes [#251](#251)
* **documentation:** enquote html color ([dbdeab8](dbdeab8)), closes [#872](#872)
* **stalebot:** issues should also use exemptLabels ([4d74c1f](4d74c1f))
* **workflows:** remove invalid description field ([e755e24](e755e24))

### Features

* **option:** override icon with an image URL ([#789](#789)) ([2860a09](2860a09))
@github-actions
Copy link

🎉 This issue has been resolved in version 0.12.0-dev.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@akloeckner
Copy link
Collaborator

I just gave it a try on the dev branch... Great magic. But it has worked, I think. There should be a new pre-release with the latest changes.

@ntzb
Copy link

ntzb commented Apr 23, 2023

looking good, I'm on the dev release 0.12.0-dev.2
thanks a bunch! also for reviving the dev (beta) builds

@ntzb
Copy link

ntzb commented May 1, 2023

seems like this introduced a new bug (not sure):
https://imgur.com/a9YgO2E
the entity value is ~17% for ~10 minutes, from 5:17 to 5:27 (shown in the history), but the card shows 17% going back until the first point in time.
can anyone reproduce?

@akloeckner
Copy link
Collaborator

From how I understand the current - but also the old - code, that should have happened before as well. The first point on the graph is the first data point within the history period. So, 17%. But I might miss some subtlety.

Can you check with an older version of the card, before my change?

@ntzb
Copy link

ntzb commented May 2, 2023

before I saw your post, I updated to dev.3 (from dev.2), and I don't see it anymore.
if I see it again, I'll do as you suggested and post the results

github-actions bot pushed a commit that referenced this issue Jan 27, 2024
# [0.12.0](v0.11.0...v0.12.0) (2024-01-27)

### Bug Fixes

* add first datapoint tooltip for line graph ([#882](#882)) ([7576fe6](7576fe6))
* allow zero tooltip ([057a395](057a395)), closes [#805](#805)
* cards would always assume icon_image was set ([#957](#957)) ([f376732](f376732))
* drop out-of-bound coords in reducer ([#881](#881)) ([527f005](527f005)), closes [#251](#251)
* retain the last out-of-bounds state ([#961](#961)) ([8ebe173](8ebe173)), closes [#881](#881) [#960](#960)
* **documentation:** enquote html color ([dbdeab8](dbdeab8)), closes [#872](#872)
* **stalebot:** issues should also use exemptLabels ([4d74c1f](4d74c1f))
* **workflows:** remove invalid description field ([e755e24](e755e24))

### Features

* Add support of attribute tree when available ([#996](#996)) ([9c1c31e](9c1c31e))
* pull two years worth of changes into release channel ([f5fb98d](f5fb98d)), closes [#1059](#1059)
* **option:** override icon with an image URL ([#789](#789)) ([2860a09](2860a09))
Copy link

🎉 This issue has been resolved in version 0.12.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@adamzimnyy
Copy link

I'm on release 0.12.0 and I'm still seeing this issue.

The graph is showing max value from each day:

image

image

All of the green bars except the last one are wrong, they are all showing 4.7 which is the first peak value on Mar 8 (there is no data for this sensor before March 8):

image

@akloeckner
Copy link
Collaborator

I think, your seeing a different issue with similar symptoms. Since there is no data before March 8, the code just uses the earliest (I believe) data point also for the missing points in time. That makes sense for continuous data, because the home assistant history only stores data when the state changes. So, it's reasonable to assume the state hasn't changed if there is no data in a given interval. (Although we seem to do this after aggregating over the day, while we should actually do it before aggregating.)

While I acknowledge the result is not correct in your case, it's maybe ok to ignore for now. When - in 11 days - there's enough data, the issue should go away and not come back. 😉

@ildar170975
Copy link
Collaborator

There could be another explanation, we probably need more details like a m-g-c code, real db content.
We are trying to investigate the issue by comparing with a standard history-graph.
In general this is correct - but since 2024.3 the history-graph is broken and can show wrong results - for instance, for periods where:
-- the entity has no changes
-- the entity was not created yet
-- the entity's changes were not recorded
i.e. personally me cannot consider history-graph now as a 100% correct proof.

@lottor
Copy link

lottor commented Mar 30, 2024

I'm having a similar problem with a water flow graph. The sensor sends updates every 10 seconds but the graph often seems to ignore the zero data. That long flat part in the graph to the right was zero that whole time but it gets graphed at the last non-zero value instead. I've verified the sensor was sending zeros the whole time.

wf2

@akloeckner
Copy link
Collaborator

I'm having a similar problem with a water flow graph.

I suggest you open a new issue for this, as it seems not the same as the original issue here. It's likely the same issue as adamzimnyy sees.

For troubleshooting, try to set points per hour really high, at least 360. (The aim should be for the first zero value to be in its own averaging time window. The average zero should then carry over to the following period.)

github-actions bot pushed a commit to motorlatitude/mini-graph-card that referenced this issue Dec 15, 2024
# 1.0.0 (2024-12-15)

### Bug Fixes

* add first datapoint tooltip for line graph ([kalkih#882](https://github.com/motorlatitude/mini-graph-card/issues/882)) ([7576fe6](7576fe6))
* allow zero tooltip ([057a395](057a395)), closes [kalkih#805](https://github.com/motorlatitude/mini-graph-card/issues/805)
* cards would always assume icon_image was set ([kalkih#957](https://github.com/motorlatitude/mini-graph-card/issues/957)) ([f376732](f376732))
* display a warning if entity is not available ([kalkih#545](https://github.com/motorlatitude/mini-graph-card/issues/545)) ([a334b84](a334b84)), closes [kalkih#487](https://github.com/motorlatitude/mini-graph-card/issues/487)
* drop out-of-bound coords in reducer ([kalkih#881](https://github.com/motorlatitude/mini-graph-card/issues/881)) ([527f005](527f005)), closes [kalkih#251](https://github.com/motorlatitude/mini-graph-card/issues/251)
* Fix undefined variable introduced by [kalkih#545](https://github.com/motorlatitude/mini-graph-card/issues/545) ([9e923f5](9e923f5))
* icon will properly follow entity's device_class [[kalkih#484](https://github.com/motorlatitude/mini-graph-card/issues/484)] ([2f9e0a7](2f9e0a7))
* retain the last out-of-bounds state ([kalkih#961](https://github.com/motorlatitude/mini-graph-card/issues/961)) ([8ebe173](8ebe173)), closes [kalkih#881](https://github.com/motorlatitude/mini-graph-card/issues/881) [kalkih#960](https://github.com/motorlatitude/mini-graph-card/issues/960)
* Support for `fire-dom-event` ([c29f55f](c29f55f)), closes [kalkih#563](https://github.com/motorlatitude/mini-graph-card/issues/563)
* tooltip interval start could be after end ([kalkih#1065](https://github.com/motorlatitude/mini-graph-card/issues/1065)) ([930ee39](930ee39)), closes [kalkih#181](https://github.com/motorlatitude/mini-graph-card/issues/181)
* **config:** Remove entity config error [kalkih#592](https://github.com/motorlatitude/mini-graph-card/issues/592) ([kalkih#593](https://github.com/motorlatitude/mini-graph-card/issues/593)) ([53d923a](53d923a))
* **documentation:** enquote html color ([dbdeab8](dbdeab8)), closes [kalkih#872](https://github.com/motorlatitude/mini-graph-card/issues/872)
* **log:** color_thresholds render incorectly with logaritmic on ([kalkih#542](https://github.com/motorlatitude/mini-graph-card/issues/542)) ([b704885](b704885)), closes [kalkih#531](https://github.com/motorlatitude/mini-graph-card/issues/531)
* **stalebot:** issues should also use exemptLabels ([4d74c1f](4d74c1f))
* **workflows:** remove invalid description field ([e755e24](e755e24))
* Time would sometime display 24:xx instead of 00:xx [[kalkih#536](https://github.com/motorlatitude/mini-graph-card/issues/536)] ([7c7d921](7c7d921))

### Features

* Add support of attribute tree when available ([kalkih#996](https://github.com/motorlatitude/mini-graph-card/issues/996)) ([9c1c31e](9c1c31e))
* Interpolate color threshold stops ([kalkih#596](https://github.com/motorlatitude/mini-graph-card/issues/596)) ([3826c0d](3826c0d))
* pull two years worth of changes into release channel ([f5fb98d](f5fb98d)), closes [kalkih#1059](https://github.com/motorlatitude/mini-graph-card/issues/1059)
* **attribute:** Retrieve an attribute instead of the state ([kalkih#564](https://github.com/motorlatitude/mini-graph-card/issues/564)) ([708bfde](708bfde)), closes [kalkih#411](https://github.com/motorlatitude/mini-graph-card/issues/411) [kalkih#245](https://github.com/motorlatitude/mini-graph-card/issues/245) [kalkih#501](https://github.com/motorlatitude/mini-graph-card/issues/501)
* **graph:** Add median aggregate function ([kalkih#521](https://github.com/motorlatitude/mini-graph-card/issues/521)) ([57219bd](57219bd))
* **option:** override icon with an image URL ([kalkih#789](https://github.com/motorlatitude/mini-graph-card/issues/789)) ([2860a09](2860a09))
* Format numbers according to selected language [[kalkih#495](https://github.com/motorlatitude/mini-graph-card/issues/495) [kalkih#509](https://github.com/motorlatitude/mini-graph-card/issues/509)] ([5785bd8](5785bd8))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released on @dev released
Projects
None yet
Development

No branches or pull requests