CJNE / ha-myenergi

Home Assistant integration for MyEnergi devices
MIT License
137 stars 30 forks source link

green_energy_today increasing instead of energy_used_today #60

Open Ulrar opened 2 years ago

Ulrar commented 2 years ago

Version of the custom_component

Latest from HACS

Configuration

Used the UI

Describe the bug

I've just plugged the hub in and added the integration. The green_energy_today is increasing, even though I do not have any generation and it shows 0 in the android app. The energy_used_today is staying at 0, even though it's increasing in the android app.

Any chance these are reversed, somehow ? Surely green should be 0 and used today should correlate with the grid CT readouts.

Debug log

No logs from this integration.

G6EJD commented 2 years ago

I’ve just checked mine and the green value is tracking / equivalent to the Eddi readings, so definitely a problem.

albenex commented 2 years ago

too here

CJNE commented 2 years ago

Thanks for this, it's probably mixed up, will take a look!

apbarratt commented 2 years ago

This is a problem for me too. The only MyEnergi Kit I have is the Zappi2 and the hub that came with it. My Energy dashboard only shows the car charge usage as "Green Energy today". When this is fixed, it would be helpful to understand how the fix is done here so we can prepare for it in such a way that we don't lose our existing data :) Let me know if there's anything I can share on my side if you need data/testing or point me to the relevant code if I find myself with a bit of free time that you don't have right now :)

apbarratt commented 2 years ago
Screenshot 2022-07-20 at 15 21 03
markruys commented 1 year ago

"Green Energy today" (energy_green) is computed from h1d + h2d + h3d, which is supposed the diversion charge (hence the 'd'). It is green in the sense it's used for charging instead of being exported to the grid. "Energy used today" (energy_total) is computed from h1b + h2b + h3b, which is boosted charge (hence the 'b').

I think you need to add these two values to obtain the actual energy charged. It's not swapped, but the naming is really confusing.

Ulrar commented 1 year ago

I have no generation so nothing is getting diverted, it's 100% imported energy

markruys commented 1 year ago

Naming here is confusing/incorrect. The myenergy API labels all non-boosted charge as diversion. It isn't necessarily green and could be very well be imported from the grid.

But I also observed that energy_green isn't computed correctly. Looking at the source I think it doesn't account for local time zone (the myenergy API is in UTC), and because it uses hourly resolution which isn't accurate to get today's data.

G6EJD commented 1 year ago

The idea of GitHub is also to offer a solution to the issues found by analysing the code and finding an error, then correcting that error through revised code, then if the author agrees, they incorporate the change. All I see recently is criticism for all the hard work that Johan put into this integration without which we’d have nothing.

markruys commented 1 year ago

Lol, I am working on a PR. But first we need to understand the problem. I might be wrong after all.