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

[BUG] Wrong values when total increasing sensor unavailable #128

Open
3 tasks done
mhspelt opened this issue Jul 5, 2024 · 4 comments
Open
3 tasks done

[BUG] Wrong values when total increasing sensor unavailable #128

mhspelt opened this issue Jul 5, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@mhspelt
Copy link

mhspelt commented Jul 5, 2024

Describe the bug
I have two PV inverters that report the total yield in their lifetime, but one goes offline when the voltage is too low. So at midnight, this sensor is always unavailable.

image

When I add this to the energy flow card, it assumes that the missing value is 0:
image

Expected behavior
When the value of a total increasing sensor is missing, use the last known value instead of zero.

Alternative solution
I could try to define a helper that will keep the last known value but that will only work from this moment onwards and for my several years of historical data.

Please make sure all of this applies and check the checkboxes, by writing "X" inside of them.

  • I understand that this is a channel for reporting bugs, not a support forum (If you need help configuring the card, go to: Discussions).

  • I have the latest version of the card installed.

  • I have cleared my browser cache after installing, updating and configuring the card.

@limburg11
Copy link

Same here, "day" view shows total energy from beginning to that day and not delta energy of that day only. My PV generator is also unavailable during night. In the native HA energy dashboard, it works correctly.

@udivankin
Copy link

udivankin commented Aug 24, 2024

Anything that can be done on the current project side? I've spent some time researching and it seems that no good solution exists, event defining template-sensor that preserves previous value doesn't work in all cases.
https://community.home-assistant.io/t/sensor-display-last-known-value-instead-of-unavailable/200081/30
https://community.home-assistant.io/t/preserve-last-value-of-sensor-before-becoming-unavailable/469875/8

Screenshot 2024-08-24 at 15 43 50

@mhspelt
Copy link
Author

mhspelt commented Aug 25, 2024

Anything that can be done on the current project side? I've spent some time researching and it seems that no good solution exists, event defining template-sensor that preserves previous value doesn't work in all cases. https://community.home-assistant.io/t/sensor-display-last-known-value-instead-of-unavailable/200081/30 https://community.home-assistant.io/t/preserve-last-value-of-sensor-before-becoming-unavailable/469875/8
Screenshot 2024-08-24 at 15 43 50

@flixlix @udivankin I think I may have found a cause, but I don't really have time (or skills, at the moment, to even know how to setup a component in a way I can change the code) to test if there is a viable solution.

But looking at src/energy/index.ts line 160, the comment there states

// if the start of the first value is after the requested period, we have the first data point, and should add a zero point

I think that if we check if the sensor is total_increasing, and if so, instead of a zero copy the first retrieved data point to the start, the statistics should get calculated correctly.

So something like

if (stat.length && new Date(stat[0].start) > startMinHour) {
  if (stat.sensor_type == 'total_increasing') { // <-- add this if check
      // Modified code to add a data point with correct statistics
      stat.unshift({
        ...stat[0],
        start: startMinHour.toISOString(),
        end: startMinHour.toISOString(),
        sum: stat[0].sum, // <-- use first available data point instead of 0
        state: stat[0].state,  // <-- use first available data point instead of 0
      });
  } else {     
      // The original code of line 161 - 169 to add a zero dat point
      stat.unshift({
        ...stat[0],
        start: startMinHour.toISOString(),
        end: startMinHour.toISOString(),
        sum: 0,
        state: 0,
      });
    }
}

I hope this helps you to fix this more quickly; or at the very least as a reminder for myself if I ever have time to try and code something myself.

@faspie
Copy link

faspie commented Sep 26, 2024

I can confirm this bug. Any success available? How can I define the helper as a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants