ksheumaker / homeassistant-apsystems_ecur

Home Assistant custom component for local querying of APSystems ECU-R Solar System
Apache License 2.0
166 stars 42 forks source link

Weird spikes in the data #31

Closed Roald28 closed 2 years ago

Roald28 commented 2 years ago

Hi,

I am having weird spikes, as you can see in HA there is more than 9.5Kw of energy produced this day.

Schermafbeelding 2022-01-17 om 15 37 42

But the total lifetime is not more than 8.5Kw

Schermafbeelding 2022-01-17 om 15 38 24

How can this be explained? Where do I have to look for a solution?

ksheumaker commented 2 years ago

What sensor do you have under Solar Panels in your energy dashboard, it should be sensor.ecu_lifetime_energy? and what does the graph look like if you view the history of that sensor inside HA?

Roald28 commented 2 years ago

This is the only sensor I see. So I think it is the right one?

Schermafbeelding 2022-01-17 om 19 05 28

I have set the scan_interval at 180 because the ECU crashes otherwise. (Can maybe at 120 but I don't think it is necessary)

ksheumaker commented 2 years ago

Yes, it's the correct sensor. What if you go to the history page in the sidebar, and then select sensor.ecu_lifetime_energy and pick the last day, what does that show?

Roald28 commented 2 years ago

Got a weird drop, around the same time the energy dashboard peaks looks like it. I already have set the scan_interval at 180 because the ECU crashes otherwise. Has it something to do with this?

Schermafbeelding 2022-01-17 om 19 11 53
HAEdwin commented 2 years ago

I noticed the screendump from the EMA site. The integration does not modify the ECU data (or buffer) but only reads it. It is therefore striking that the ECU did not send correct data to the EMA site. At night, when the inverters are not working, the ECU makes sure that the internal data buffer is checked again against the EMA data that has been pushed during the day. Did you not do a new ECU or reinstall of the ECU?

Roald28 commented 2 years ago

Hi @HAEdwin,

Thanks for the info! Didn't know that.

It is exactly the same ECU, did a powercycle because the ECU was not reporting.

For now it is doing well the last 4 days. Did put the scan_interval on 300.

HAEdwin commented 2 years ago

Great to hear that it is running well for four days, what kind of ECU model and firmware to you own? You mentioned spikes (more than ones), does it occur more often?

n0liver commented 2 years ago

I've experienced the same issue today, and had it happened also on jan 11. The symptom is that the sensor value changes to 0 and then jumps back up to the total generated value (and in my case twice in quick succession apparently). See screenshots: Energy panel: image The sensor image ECU's webpage ( [ECU-IP]/index.php/realtimedata/energy_graph ) image

As for my setup:

Would love to help in any way possible to fix this issue, and happily provide more info if necessary!

ksheumaker commented 2 years ago

What do the other sensors from the integration report during the 0 reporting period? Like sensor.ecu_current_power or sensor.ecu_today_energy?

n0liver commented 2 years ago

sensor.ecu_current_power seems normal, ecu_today_energy appears to show the same drop. I also noticed that this seems to go paired with a signal loss, but maybe that could be because of bad/failed parsing of ECU data? image

edit: had a quick check on other inverter data, but sensor.inverter_408000XXXXXX_power_ch_1 for example does not seem to reset to 0

ksheumaker commented 2 years ago

Didn't mean to close this, but I created a new version which will attempt to fix this by detecting a '0' value for ecu_lifetime_energy and throw an exception, which causes the integration to pull it's last cached value. Hopefully this will fix the issue, it also will log the raw data to the HA log so we can see what was returned.

n0liver commented 2 years ago

Awesome, I have updated and will keep an eye on this :+1:

Roald28 commented 2 years ago

I have updated it as well! Thanks for your time!

renini commented 2 years ago

Sorry to bump this issue, not sure if completely related, but shouldn't the other two sensor's get the right right stateclass? And not use lifetime_energy, but actually today_energy or the current_power options to calculate solar production with the current version of Home Assistant.

so in sensor.py:

     sensors = [
         APSystemsECUSensor(coordinator, ecu, "current_power",
             label="Current Power", unit=POWER_WATT,
-            devclass=DEVICE_CLASS_POWER, icon=SOLAR_ICON),
+            devclass=DEVICE_CLASS_POWER, icon=SOLAR_ICON, stateclass=STATE_CLASS_MEASUREMENT),
         APSystemsECUSensor(coordinator, ecu, "today_energy",
             label="Today Energy", unit=ENERGY_KILO_WATT_HOUR,
-            devclass=DEVICE_CLASS_ENERGY, icon=SOLAR_ICON),
+            devclass=DEVICE_CLASS_ENERGY, icon=SOLAR_ICON, stateclass=STATE_CLASS_TOTAL_INCREASING),
         APSystemsECUSensor(coordinator, ecu, "lifetime_energy",
             label="Lifetime Energy", unit=ENERGY_KILO_WATT_HOUR,
             devclass=DEVICE_CLASS_ENERGY, icon=SOLAR_ICON, stateclass=STATE_CLASS_TOTAL_INCREASING),

This way in the energy configuration you can use the sensor.ecu_today_energy and not get the error: "The following entities do not have the expected state class:" on the Energy configuration page.

ksheumaker commented 2 years ago

These state classes are is a newish feature and were not around when the integration was first made, so yes these sensors probably do need to be updated with additional flags on them. I'll do that in the next release, or feel free to submit a pull request for the change.

If you read the docs here for STATE_CLASS_TOTAL_INCREASING: https://developers.home-assistant.io/blog/2021/08/16/state_class_total/ it will consider the meter reset whenever it goes down in value. In the end it won't really matter if you pick the lifetime or the today as the energy panel looks at the difference between the last value and the current value to figure out the energy. That's the point of the STATE_CLASS_TOTAL_INCREASING flag.

The current power sensor on the other hand is the total power being generated at the moment, so that number will fluctuate depending on the position of the sun, clouds, etc. So this is not the correct value to be used in the energy panel.

ksheumaker commented 2 years ago

This should be addressed in the recently released v1.1.2. It will not allow for a 0 value in the sensor.ecu_lifetime_energy so we shouldn't see the graphs go crazy. ecu_today_energy is also available as to the energy panel if you prefer to use that sensor.