DarwinsBuddy / WienerNetzeSmartmeter

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

API change to get statistic data #197

Closed MatthiasRei closed 7 months ago

MatthiasRei commented 7 months ago

Version: 1.3.2

Since 07.11.2023 I will not get any statitistic updates in HA.

Debug logs from HA: 2023-11-09 13:25:45.793 DEBUG (MainThread) [custom_components.wnsm.statistics_sensor] {'optIn': False, 'consumptionAverage': 0, 'consumptionMinimum': 0, 'consumptionMaximum': 0} 2023-11-09 13:25:45.793 ERROR (MainThread) [custom_components.wnsm.statistics_sensor] No values in API response! This likely indicates an API error. Original response: {'optIn': False, 'consumptionAverage': 0, 'consumptionMinimum': 0, 'consumptionMaximum': 0}

I compared the request with the request from "https://smartmeter-web.wienernetze.at/#/verbrauchsdarstellung" and it looks like they changed the API request. Instead of zaehlpunkt it is necessary to use the customer number:

Old: https://api.wstw.at/gateway/WN_SMART_METER_PORTAL_API_B2C/1.0/messdaten/zaehlpunkt/AT.....

New: https://api.wstw.at/gateway/WN_SMART_METER_PORTAL_API_B2C/1.0/messdaten/120184xxxx/AT...

I tried both requests with powershell (generate the command with the dev tools from chrome). With your request I will receive the same response as in the HA logs {'optIn': False, 'consumptionAverage': 0, 'consumptionMinimum': 0, 'consumptionMaximum': 0}: Screenshot 2023-11-09 134210

With the new request: Screenshot 2023-11-09 134636

donkristo commented 7 months ago

Same here.

markwien commented 7 months ago

Same here

salzrat commented 7 months ago

Same here. would be great to address #140 as well when fixing that in order to recover the lost data...

reox commented 7 months ago

Can confirm, no data since 07.11. In theory, if we fix this, the import should resume from 07.11. onwards. The issue with #140 is really only if data between two dates is missing.

Right now, I cannot really look into this - have to prepare many things for my day job right now :(

salzrat commented 7 months ago

So a quick fix would be to replace the string "zaehlpunkt" with the actual "Kundennummer" in client.py wherever it appears in "/zahlpunkt/AT..."? Could somebody try?

MatthiasRei commented 7 months ago

Tested and it works. You need to change in /wnsm/api/client.py the line 304: endpoint = f"messdaten/zaehlpunkt/{zaehlpunkt}/verbrauch"

Just repleace zaehlpunkt with your customer number.

salzrat commented 7 months ago

and what about line 278? (in verbrauchRaw)?

MatthiasRei commented 7 months ago

For me it was enough to change line 304 to get statistic data.

salzrat commented 7 months ago

Amazing, it works! I changed both instances, just to be on the safe side :)

W-M-B commented 7 months ago

Hello, same issue here.. unfortunately I could not apply the fix properly: what I did is I changed line 304 endpoint = f"messdaten/zaehlpunkt/{12xxxxx}/verbrauch" and rebooted HA. The code changed is there but there is no data for the days after Nov 7. Am I not waiting long enough for the data loading? thanks for your Help!

MatthiasRei commented 7 months ago

Hello, same issue here.. unfortunately I could not apply the fix properly: what I did is I changed line 304 endpoint = f"messdaten/zaehlpunkt/{12xxxxx}/verbrauch" and rebooted HA. The code changed is there but there is no data for the days after Nov 7. Am I not waiting long enough for the data loading? thanks for your Help!

You have to keep {zaehlpunkt}. It has to look like: endpoint = f"messdaten/12xxxxxx/{zaehlpunkt}/verbrauch"

markwien commented 7 months ago

it works

     if zaehlpunkt is None:
            zaehlpunkt = self._get_first_zaehlpunkt()
        endpoint = f"messdaten/fillinhereyourcustomernumber/{zaehlpunkt}/verbrauch"
        query = const.build_verbrauchs_args(
            dateFrom=self._dt_string(date_from),
            dayViewResolution=resolution.value,
        )
        return 

after reboot and missing data shows up

W-M-B commented 7 months ago

yes it works. thank you for the fast feedback and clarification @markwien @MatthiasRei

DarwinsBuddy commented 7 months ago

fixed in https://github.com/DarwinsBuddy/WienerNetzeSmartmeter/commit/21f3fe7a461b1656b08f657176002b0c1b79712a

reox commented 7 months ago

@DarwinsBuddy thanks for fixing! I pulled the latest version and data was immediately synced.

DarwinsBuddy commented 7 months ago

I thought I'll give it a try today. Nice to know that it's working. ☺️