CJNE / ha-myenergi

Home Assistant integration for MyEnergi devices
MIT License
147 stars 33 forks source link

Zappi charged today #153

Open olej24 opened 2 years ago

olej24 commented 2 years ago

Hi

I’m not getting any data for the Zappi_charged_today. The charge per session sensor is working, but this resets when the charger is unplugged, so if I had two charges in a day they do not aggregate. Also, what is the green energy today sensor meant to show as this appears to be less than the total charge added via the Zappi, I’ve checked and it isn’t the amount of charge added via solar.

G6EJD commented 2 years ago

I think it’s an API issue because if you conduct multiple charges you’ll note on the Zappi display it resets to zero at the start of each charge and it’s that field being reported and used here, so when the MyEnergi app displays the total charge for the day, it must conduct a query from 00:00 until the query time to get the accumulated charge amount. I’m going to investigate the fields as I have conducted multiple charges today.

olej24 commented 2 years ago

Here are my outputs today: Total charge today: 0 kWh Total charge this session: stayed at around 5kwh carried over from yesterday until a new session started at 8:30am this added 3.93kwh and then stopped as car had reached max charge. I would therefore expect total charge today and green energy today to match this as the charge was done on eco+ mode via solar Green energy today: 3.71kwh followed the same timings as the session but was less (I presumed due to switch over from grid or minor interruptions. But it then carried on rising after car was fully charged. 25E20F5E-B560-4B75-8425-A5AD355F0C66 3BA47F83-55A8-4857-97B0-8D029F8F3ED8 569AD009-1E32-4B0D-808B-A043D63194EC 68191C1F-E6E6-4DB8-B9D6-47633CFFB9CD

olej24 commented 2 years ago

Not sure if it helps but the same issue occurs with my eddi. session and green energy are both the same and tie to the app as expected. Total Eddi energy used today is always zero. could it be a setup issue with the hardware? The app works fine so I don’t particularly want to start messing with the settings my installer entered.

G6EJD commented 2 years ago

I found the field "pwm": 5300 is the total charge power for a day.

G6EJD commented 2 years ago

The Zappi entity I use to track charge added over time ends in 'Charge added session' The Eddi entity I use to track energy used over time ends in 'Energy consumed session'

alexespencer commented 1 year ago

I also have the field "myenergi Zappi ct internal load today" showing as 0 kwh all the time. Can this be looked into? Happy to send logs as needed.

alexespencer commented 1 year ago

In addition - is there a "charge added - total (kwh)", this would play nicely with the Home Assistant Energy Dashboard

LeiChat commented 1 year ago

In my experience, the charge added figure displayed on the zappi and in the myenergi app accumulates across multiple charging sessions/days if the zappi is not disconnected from the EV.

I have opted to calculate my own charging sessions and daily totals based on the h1b (boosted) and h1d (diverted) values from the API's cgi-jday response.

Gnarfoz commented 9 months ago

Could you elaborate on how to do that, @LeiChat?

LeiChat commented 9 months ago

Could you elaborate on how to do that, @LeiChat?

I store the data from the rows returned by the API in a collection of log item objects and generate a collection of charging session objects based on the presence of h1b or h1d values, using the hr (hour) and min values for start and end times of each session.

{ "imp": 651660,"gen": 480,"h1b": 421800,"pect1": 651600,"nect2": 480,"nect3": 185460,"v1": 2326, "frq": 5002,"yr": 2024,"mon": 1,"dom": 28,"dow": "Sun","min": 23 }, { "imp": 649620,"gen": 480,"h1b": 421800,"pect1": 649620,"nect2": 480,"nect3": 185520,"v1": 2320, "frq": 5002,"yr": 2024,"mon": 1,"dom": 28,"dow": "Sun","min": 24 },

There will be gaps in the data sometimes, where it has not synchronised to myenergi's servers. In the myenergi app I understand they interpolate values for any missing rows. I don't bother trying to do that as it will generally only be a few rows missing from the 1440 you would expect for a day.

I'm in the UK so, to deal with DST, I use either midnight or 23-00 from the previous day when calling the API. e.g. sXX.myenergi.net/cgi-jday-Z99999999-2023-06-01-23-00 for 24 hours of data for 2nd June, from 23:00 on the 1st.

The unit of the h1b and h1d value is Watt Seconds so I divide by 3600000 when calculating totals to display in kWh.

Here's my C# ViewModel snippet for the zappi charging sessions:

public List<DeviceSession> ZappiSessions
        {
            get
            {
                List<DeviceSession> listCS = new List<DeviceSession>();
                double lastH1 = 0;
                DeviceSession ds = new DeviceSession();
                foreach (LogItemZappi li in LogItemsZappi)
                {
                    if ((li.h1b > 0 || li.h1d > 0) && lastH1 <= 0)
                    {
                        ds = new DeviceSession();
                        ds.Start = new DateTime(li.yr, li.mon, li.dom, li.hr, li.min, 0);
                        if (isDST) { ds.Start = ds.Start.AddHours(1); }
                        ds.WattSecondsBoosted = li.h1b;
                        ds.WattSecondsDiverted = li.h1d;
                        ds.NumLogs++;
                    }
                    else if (li.h1b > 0 || li.h1d > 0)
                    {
                        ds.WattSecondsBoosted += li.h1b;
                        ds.WattSecondsDiverted += li.h1d;
                        ds.NumLogs++;

                        // -- keep updating end time
                        // -- because API data may be missing rows cannot guarantee identifying final minute of a charging session
                        ds.End = new DateTime(li.yr, li.mon, li.dom, li.hr, li.min, 0);

                        // -- handle currently charging
                        if (li.Equals(LogItemsZappi.Last()))
                        {
                            if (isDST) { ds.End = ds.End.AddHours(1); }
                            listCS.Add(ds);
                        }
                    }
                    else if ((li.h1b <= 0 && li.h1d <= 0) && lastH1 > 0)
                    {
                        ds.End = new DateTime(li.yr, li.mon, li.dom, li.hr, li.min, 0);
                        if (isDST) { ds.End = ds.End.AddHours(1); }
                        listCS.Add(ds);
                    }
                    lastH1 = li.h1b + li.h1d;
                }
                return listCS;
            }
        }

Since we had a storage battery installed (gave up waiting for the libbi) the API data will often report some h1d (diverted) energy during a scheduled boost, I presume the zappi is assuming some of the battery discharge measured by the myenergi CT is being diverted to the EV. Someone else might opt to bundle those h1d values as part of the h1b values and consider it all sourced from grid import. I do not have a precise way to calculate the split of grid and battery being used by the zappi. Someone with a libbi might be able to advise if myenergi are able to do better or if that suffers similar complication.

image

Gnarfoz commented 9 months ago

Thanks, @LeiChat! Whew, that looks a lot more complicated than I had thought... I had assumed it was something you did within Home Assistant.