DarwinsBuddy / WienerNetzeSmartmeter

A home-assistant integration supporting WienerNetze Smartmeters as sensors
121 stars 12 forks source link

trigger reimport of data due to huge negative consumption error? #217

Closed maia closed 4 months ago

maia commented 5 months ago

I've managed to get wnsm to run two days ago after figuring out that I may not use a "Spitzname" in the Wiener Netze dashboard, as that confuses the HA integration. Finally the import worked fine and everything looked okay. But on the next day the data was completely messed up, it shows -188 kWh for that day, with only a single measurement at 12:00. The Wiener Netze dashboard looks fine.

Is there a way to trigger a reimport of the available data? Is this a common issue for the day that the integration is setup? Is there a workaround? Thanks. (I don't have any logs for that day as I rebooted HA twice since)

Bildschirmfoto 2024-01-29 um 21 03 51 Bildschirmfoto 2024-01-29 um 21 09 02 Bildschirmfoto 2024-01-29 um 21 07 01
reox commented 5 months ago

it should do a re-import of all historic data if you delete the integration and also delete the statistics, then re-install the integration.

maia commented 5 months ago

Thanks. I was hoping for something easier and I was wondering if that is an issue related to the install – because if yes, then a fresh install won't really help.

maia commented 4 months ago

I've now had a third day reporting a negative usage amount (which is impossible, as I do not generate energy), and then no new data since.

Bildschirmfoto 2024-02-03 um 17 40 49

I would like to suggest to implement a service that one can trigger to re-import the data? There must be an easier way than to uninstall, delete all sensor data manually, reboot, reinstall each time the API returns wrong data for a brief moment.

PS: This here seems to be related: https://github.com/DarwinsBuddy/WienerNetzeSmartmeter/issues/216#issuecomment-1922181563

maia commented 4 months ago

I now had another day of -3.89kWh negative consumption, with only this value set for 12:00-13:00 and no other values for the other hours for the day. Interestingly this amount is exactly the sum of my hourly usage on the prior day (which at least displays proper values for each hour from 12:00 to 24:00).

reox commented 4 months ago

This problem sounds like that the statistics sensor and the meter are reporting into the same statistics. If they do, the values cancel each other out and you see these negative records.

Do you still have the two sensors? One with _statistics appended and one without? Does you _statistics sensor has a value? It should say no value available, because otherwise the statistics module gets confused...

maia commented 4 months ago

@reox I deactivated the two sensors of the place I've moved out a few years ago and kept the two sensors for the current place I live at. And I've used the _statistics sensor in the energy panel configuration:

Bildschirmfoto 2024-02-06 um 19 29 35 Bildschirmfoto 2024-02-06 um 19 30 34

Is that a wrong setup?

reox commented 4 months ago

ah, thanks for the hint. This might be a regression of https://github.com/DarwinsBuddy/WienerNetzeSmartmeter/commit/821b76d84f148b31695e52c217a55b0249de912f

@DarwinsBuddy could that be the case? I think the problem is, if the sensor state is set to 0, the statistics module will interpret this as negative consumption.

DarwinsBuddy commented 4 months ago

Thanks @reox for mentioning me. I did not have the time to follow up on issues yet. I just looked over your conversation and I agree it has to be correlated with my latest commits.

Two things are possible:

  1. either the import of the data into our statistics sensor is wrong or
  2. the data returned by /Bewegungsdaten (which we changed to, due to some people not getting anything back from the former export endpoint) is somehow looking differently (and the smartmeter portal is compensating for that fact)

though I'd also first look into 1., but can probably earliest look into it on Sunday (if even).

@maia thank you so much for your time to report everything so clearly. it's really helpful. re: a service to trigger re-import that's possible I guess, though I'd be missing a thing right now to imagine it: @reox Is there a way (other than calling the purge entities service) to get rid of all the data of an entity programmatically managed by the recorder?

reox commented 4 months ago

@reox Is there a way (other than calling the purge entities service) to get rid of all the data of an entity programmatically managed by the recorder?

This is definitely possible via the GUI but I'm not sure if a API exists. I cannot find anything here: https://github.com/home-assistant/core/blob/dev/homeassistant/components/recorder/statistics.py

DarwinsBuddy commented 4 months ago

@reox Is there a way (other than calling the purge entities service) to get rid of all the data of an entity programmatically managed by the recorder?

This is definitely possible via the GUI but I'm not sure if a API exists. I cannot find anything here: https://github.com/home-assistant/core/blob/dev/homeassistant/components/recorder/statistics.py

Seems like there is a possibility to call services within a custom component, but there is no possibility in doing this "on upgrading the integration".

I could think of a way of enabling this via the config flow. Though it would not be much of a difference compared to what's described in the FAQs.