Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: sbazv_de Not working anymore #2870

Open
5 of 7 tasks
reentier opened this issue Oct 18, 2024 · 14 comments
Open
5 of 7 tasks

[Bug]: sbazv_de Not working anymore #2870

reentier opened this issue Oct 18, 2024 · 14 comments

Comments

@reentier
Copy link

I Have A Problem With:

The integration in general

What's Your Problem

I only receive an error-Message from this Integration singe today.

image

While trying to reconfigure and double-checking with website of the provider it seems that they have changed the requested paramaters for the API-Call. In the past there asked for City, Part of the City and Street. But now there are asking for City, Street and Number of the House.

image

If there is any more Information i should provide to solve this issue, please ask.

Thanks in advance for looking into this.

Source (if relevant)

Sbazv_de

Logs

No response

Relevant Configuration

No response

Checklist Source Error

  • Use the example parameters for your source (often available in the documentation) (don't forget to restart Home Assistant after changing the configuration)
  • Checked that the website of your service provider is still working
  • Tested my attributes on the service provider website (if possible)
  • I have tested with the latest version of the integration (master) (for HACS in the 3 dot menu of the integration click on "Redownload" and choose master as version)

Checklist Sensor Error

  • Checked in the Home Assistant Calendar tab if the event names match the types names (if types argument is used)

Required

  • I have searched past (closed AND opened) issues to see if this bug has already been reported, and it hasn't been.
  • I understand that people give their precious time for free, and thus I've done my very best to make this problem as easy as possible to investigate.
@maxgisel
Copy link

+1

@reentier
Copy link
Author

The provider has completely changed the way in which the data can be retrieved. Instead of city, district and street, a location ID is now required. You can then use additional parameters to specify which waste you want to retrieve. You can choose between residual waste, paper, yellow bags, leaf bags and Christmas trees.
The URL for the query has also changed completely. The URL for the address from the example in the data now looks like this:
https://fahrzeuge.sbazv.de/WasteManagementSuedbrandenburg/WasteManagementServiceServlet?ApplicationName=Calendar&SubmitAction=sync&StandortID=1448162001&AboID=495&Fra=P;R;WB;L;GS

I have temporarily solved the problem for myself by hard-coding the URL for the query at my address in the sbazv_en.py module. For the moment it works again, but I hope that the changes will soon be included in the official part.

regards

@frankrehfeld
Copy link

I have temporarily solved the problem for myself by hard-coding the URL for the query at my address in the sbazv_en.py module. For the moment it works again, but I hope that the changes will soon be included in the official part.

regards

Can you provide a quick and dirty hack to get the integration working again until it is fixed?

@reentier
Copy link
Author

Go to the Website of sbazv, Look for your personal ics-file and copy the provided link.

use this link in file sbazv_de.py and enter this in line 53. do Not forget to delete the additional Parameters in the line.

start HA afterwards and everything should be working, ar least for the Moment.

@cpohli
Copy link

cpohli commented Oct 21, 2024

Thank you @reentier, it works again (for now and as a workaround at least).

But not only the way the data is retrieved changed, also the wording of the entries.
For instance "Papier" has become "Papier 0240 04-wöchentl."
If you use templates for icons and so on, you'll have to change all the templates as well.
If this persists, there should be an truncate involved for the " 0240 ..." parts.

EDIT: Die "new" naming seems to only affect "Papier" and "Restmüll".

@rmi1974
Copy link

rmi1974 commented Oct 21, 2024

Thank you @reentier, it works again (for now and as a workaround at least).

But not only the way the data is retrieved changed, also the wording of the entries. For instance "Papier" has become "Papier 0240 04-wöchentl." If you use templates for icons and so on, you'll have to change all the templates as well. If this persists, there should be an truncate involved for the " 0240 ..." parts.

EDIT: Die "new" naming seems to only affect "Papier" and "Restmüll".

Confirmed. I had to change my templates:

waste_collection_schedule:
  sources:
    - name: ics
      args:
        url: https://fahrzeuge.sbazv.de/WasteManagementSuedbrandenburg/WasteManagementServiceServlet?ApplicationName=Calendar&SubmitAction=sync&StandortID=xxx&Fra=P;R;WB;L;GS
      calendar_title: "Müllabfuhr"
      customize:
        - type: Restmüll 0240 02-wöchentl.
          alias: restmuell
          icon: mdi:trash-can
        - type: Gelbe Säcke
          alias: gelbersack
          icon: mdi:recycle-variant
        - type: Papier 0240 04-wöchentl.
          alias: papier
          icon: mdi:package-variant
        - type: Laubsäcke
          alias: laub
          icon: mdi:leaf

While this fixes my "next event" sensors (it displays the next date where each type of waste is collected), the calendar itself doesn't work for me.

"Events for calendar could not be retrieved" -> calendar doesn't display any items.

This doesn't make sense because the sensors can obviously display valid data which means that event data has been parsed from the received .ics

I'm a bit stumped. I've changed sbazv_en.py as suggested (same URL as in the template) but for unknown reasons calendar remains empty with the error message in web UI.

Is there a way to debug/log the parsing within python module?
I've tried to reuse some logger.debug code from other modules but it doesn't work, the output goes to narnia?

import logging
from datetime import datetime

import requests
from waste_collection_schedule import Collection  # type: ignore[attr-defined]
from waste_collection_schedule.service.ICS import ICS

_LOGGER = logging.getLogger(__name__)

...

TITLE = "Südbrandenburgischer Abfallzweckverband"
DESCRIPTION = "SBAZV Brandenburg, Deutschland"
...
_LOGGER = logging.getLogger(__name__)
    def fetch(self):
        args = {
            "city": self._city,
            "district": self._district,
            "street": self._street,
        }

        _LOGGER.debug("before fetch")
        # get ics file
        # https://www.sbazv.de/entsorgungstermine/klein.ics?city=Wildau&district=Wildau&street=Miersdorfer+Str.
        r = requests.get(
            "https://fahrzeuge.sbazv.de/WasteManagementSuedbrandenburg/WasteManagementServiceServlet?ApplicationName=Calendar&SubmitAction=sync&StandortID=xxx&Fra=P;R;WB;L;GS"
        )

        # parse ics file
        dates = self._ics.convert(r.text)
        _LOGGER.debug("after ics convert")
        entries = []
        for d in dates:
            waste_type = d[1].strip()
            _LOGGER.debug("Waste Type: %s", waste_type)
            next_pickup_date = d[0]

@cpohli
Copy link

cpohli commented Oct 21, 2024

While this fixes my "next event" sensors (it displays the next date where each type of waste is collected), the calendar itself doesn't work for me.

"Events for calendar could not be retrieved" -> calendar doesn't display any items.

Calendar seems fine here and works as expected.
The only things i changed was the URL and the customization for the two renamed entries "Papier" and "Restmüll".

@Fiiti
Copy link

Fiiti commented Oct 26, 2024

My Solution

As written before:
The SBAZV waste collection schedule integration for Home Assistant stopped working due to a change in the SBAZV API. The previous ICS endpoint (https://www.sbazv.de/entsorgungstermine/klein.ics) now returns a 404 error, making it impossible to fetch collection dates.
SBAZV uses a new syntax/URI for working. See some steps below, how you get these parametrs for you.

The Solution-Steps:

I've updated the sbazv_de.py script directly with an editor in Home Assistant (config/custom_components/waste_collection_schedule/waste_collection_schedule/source/sbazv_de.py) to use a new URL that works with StandortID and AboID parameters. This new approach uses the current URL format to retrieve ICS files, maintaining compatibility with the waste collection service.

Steps for Workaround

1. Edit sbazv_de.py

Use an editor such as "VS Code Server" in Home Assistant and completely replace the script with the provided updated version.

import requests
from waste_collection_schedule import Collection  # type: ignore[attr-defined]
from waste_collection_schedule.service.ICS import ICS

TITLE = "Südbrandenburgischer Abfallzweckverband"
DESCRIPTION = "SBAZV Brandenburg, Deutschland"
URL = "https://www.sbazv.de"
TEST_CASES = {
    "Wildau": {"standort_id": "1448192001", "abo_id": "2978"},
    # Additional test cases can be added here
}

ICON_MAP = {
    "Restmülltonnen": "mdi:trash-can",
    "Laubsäcke": "mdi:leaf",
    "Gelbe Säcke": "mdi:sack",
    "Papiertonnen": "mdi:package-variant",
    "Weihnachtsbäume": "mdi:pine-tree",
}

class Source:
    def __init__(self, standort_id, abo_id):
        self._standort_id = standort_id
        self._abo_id = abo_id
        self._ics = ICS()

    def fetch(self):
        url = "https://fahrzeuge.sbazv.de/WasteManagementSuedbrandenburg/WasteManagementServiceServlet"
        params = {
            "ApplicationName": "Calendar",
            "SubmitAction": "sync",
            "StandortID": self._standort_id,
            "AboID": self._abo_id,
            "Fra": "P;R;WB;L;GS"
        }

        # GET request to retrieve ICS file
        r = requests.get(url, params=params)
        
        # Check if the response is successful
        if r.status_code != 200:
            raise ValueError(f"Error fetching ICS data. Status code: {r.status_code}")

        # Parse ICS data
        dates = self._ics.convert(r.text)

        entries = []
        for d in dates:
            waste_type = d[1].strip()
            next_pickup_date = d[0]
            # Remove duplicates
            if any(
                e.date == next_pickup_date and e.type == waste_type for e in entries
            ):
                continue
            entries.append(
                Collection(
                    date=next_pickup_date,
                    t=waste_type,
                    icon=ICON_MAP.get(waste_type),
                )
            )

        return entries

2. Remove Manual Configuration

Remove any manually added entries for Waste Collection Schedule from configuration.yaml, if available.

3. Restart Home Assistant

Restart Home Assistant to apply the changes.

4. Find StandortID and AboID

a. Visit https://www.sbazv.de/entsorgungstermine/restmuell-papier-gelbesaecke-laubsaecke-weihnachtsbaeume/

b. Fill in "Ort", "Straße", and "Hausnummer", then click "Weiter".

c. Click "Kalenderexport".

d. Scroll down and click "URL anzeigen". You will see a URL like: https://fahrzeuge.sbazv.de/WasteManagementSuedbrandenburg/WasteManagementServiceServlet?ApplicationName=Calendar&SubmitAction=sync&StandortID=1383362001&AboID=3001&Fra=P;R;WB;L;GS

e. Note StandortID and AboID from the URL.

5. Add Integration

Add the "Waste Collection Schedule" integration in Home Assistant and start the assistant. You will now see fields for StandortID and AboID. Enter the values noted in Step 4e.

6. Proceed with Configuration

Complete the remaining configuration steps as before.

This workaround is working well on my setup. I hope it will be helpful to all of you. If agreed by mampfes, it could also be included in the main code.

Maybe someone else can investigate whether it's possible to find an API that builds the StandortID directly from the address details. So far, I haven’t found anything suitable for that.

Fiiti

@MarioHeininger
Copy link

MarioHeininger commented Oct 27, 2024

Hmm that seems not fixing all for me

how get i back my Sensors ?

` - platform: waste_collection_schedule
name: "Nächste Abholung"
#value_template: '{% if value.daysTo == 0 %} Heute{% elif value.daysTo == 1 %} Morgen{% else %} in {{value.daysTo}} tagen{% endif %}'
value_template: '{{value.types|join(", ")}}{% if value.daysTo == 0 %} Heute{% elif value.daysTo == 1 %} Morgen{% else %} in {{value.daysTo}} tagen{% endif %}'#value_template: '{{value.types|join(", ")}}{% if value.daysTo == 0 %} Heute{% elif value.daysTo == 1 %} Morgen{% else %} in {{value.daysTo}} tagen{% endif %}'

Nächste Restmüll-Abholung

  • platform: waste_collection_schedule
    name: "Restmüll"
    value_template: '{% if value.daysTo == 0 %} Heute{% elif value.daysTo == 1 %} Morgen{% else %} in {{value.daysTo}} tagen{% endif %}'
    types:
    • Restmülltonnen

Nächste gelber-Sack Abholung

  • platform: waste_collection_schedule
    name: "Gelber Sack"
    value_template: '{% if value.daysTo == 0 %} Heute{% elif value.daysTo == 1 %} Morgen{% else %} in {{value.daysTo}} tagen{% endif %}'
    #value_template: '{{value.types|join(", ")}}{% if value.daysTo == 0 %} Heute{% elif value.daysTo == 1 %} Morgen{% else %} in {{value.daysTo}} tagen{% endif %}'
    types:
    • Gelbe Säcke

Nächste Papiermüll Abholung

  • platform: waste_collection_schedule
    name: "Papier"
    value_template: '{% if value.daysTo == 0 %} Heute{% elif value.daysTo == 1 %} Morgen{% else %} in {{value.daysTo}} tagen{% endif %}'
    types:
    • Papiertonnen

`

@dirkzt
Copy link

dirkzt commented Oct 27, 2024

My Solution

As written before: The SBAZV waste collection schedule integration for Home Assistant stopped working due to a change in the SBAZV API. The previous ICS endpoint (https://www.sbazv.de/entsorgungstermine/klein.ics) now returns a 404 error, making it impossible to fetch collection dates. SBAZV uses a new syntax/URI for working. See some steps below, how you get these parametrs for you.

The Solution-Steps:

I've updated the sbazv_de.py script directly with an editor in Home Assistant (config/custom_components/waste_collection_schedule/waste_collection_schedule/source/sbazv_de.py) to use a new URL that works with StandortID and AboID parameters. This new approach uses the current URL format to retrieve ICS files, maintaining compatibility with the waste collection service.

Steps for Workaround

1. Edit sbazv_de.py

Use an editor such as "VS Code Server" in Home Assistant and completely replace the script with the provided updated version.

import requests
from waste_collection_schedule import Collection  # type: ignore[attr-defined]
from waste_collection_schedule.service.ICS import ICS

TITLE = "Südbrandenburgischer Abfallzweckverband"
DESCRIPTION = "SBAZV Brandenburg, Deutschland"
URL = "https://www.sbazv.de"
TEST_CASES = {
    "Wildau": {"standort_id": "1448192001", "abo_id": "2978"},
    # Additional test cases can be added here
}

ICON_MAP = {
    "Restmülltonnen": "mdi:trash-can",
    "Laubsäcke": "mdi:leaf",
    "Gelbe Säcke": "mdi:sack",
    "Papiertonnen": "mdi:package-variant",
    "Weihnachtsbäume": "mdi:pine-tree",
}

class Source:
    def __init__(self, standort_id, abo_id):
        self._standort_id = standort_id
        self._abo_id = abo_id
        self._ics = ICS()

    def fetch(self):
        url = "https://fahrzeuge.sbazv.de/WasteManagementSuedbrandenburg/WasteManagementServiceServlet"
        params = {
            "ApplicationName": "Calendar",
            "SubmitAction": "sync",
            "StandortID": self._standort_id,
            "AboID": self._abo_id,
            "Fra": "P;R;WB;L;GS"
        }

        # GET request to retrieve ICS file
        r = requests.get(url, params=params)
        
        # Check if the response is successful
        if r.status_code != 200:
            raise ValueError(f"Error fetching ICS data. Status code: {r.status_code}")

        # Parse ICS data
        dates = self._ics.convert(r.text)

        entries = []
        for d in dates:
            waste_type = d[1].strip()
            next_pickup_date = d[0]
            # Remove duplicates
            if any(
                e.date == next_pickup_date and e.type == waste_type for e in entries
            ):
                continue
            entries.append(
                Collection(
                    date=next_pickup_date,
                    t=waste_type,
                    icon=ICON_MAP.get(waste_type),
                )
            )

        return entries

2. Remove Manual Configuration

Remove any manually added entries for Waste Collection Schedule from configuration.yaml, if available.

3. Restart Home Assistant

Restart Home Assistant to apply the changes.

4. Find StandortID and AboID

a. Visit https://www.sbazv.de/entsorgungstermine/restmuell-papier-gelbesaecke-laubsaecke-weihnachtsbaeume/

b. Fill in "Ort", "Straße", and "Hausnummer", then click "Weiter".

c. Click "Kalenderexport".

d. Scroll down and click "URL anzeigen". You will see a URL like: https://fahrzeuge.sbazv.de/WasteManagementSuedbrandenburg/WasteManagementServiceServlet?ApplicationName=Calendar&SubmitAction=sync&StandortID=1383362001&AboID=3001&Fra=P;R;WB;L;GS

e. Note StandortID and AboID from the URL.

5. Add Integration

Add the "Waste Collection Schedule" integration in Home Assistant and start the assistant. You will now see fields for StandortID and AboID. Enter the values noted in Step 4e.

6. Proceed with Configuration

Complete the remaining configuration steps as before.

This workaround is working well on my setup. I hope it will be helpful to all of you. If agreed by mampfes, it could also be included in the main code.

Maybe someone else can investigate whether it's possible to find an API that builds the StandortID directly from the address details. So far, I haven’t found anything suitable for that.

Fiiti

Thank you very much, it worked. I followed the instructions and created a new integration. There you can also rename the "Restmüll" and "Papier". The "value_template" can also be inserted so that you have a display like “Morgen” again.
2024-10-27 18 43 02 dna-adler de 688482b05385

@MarioHeininger
Copy link

@rmi1974 thank you - that's fixing all my problems with sensors and so on ... still working again everything as before !

@marci227
Copy link

marci227 commented Nov 11, 2024

image

Since i updated the sbazv_de.py , i got the error "Unknown error occurred" and nothing helps. Before the configuration update like you said, i had no errors.
Option "Generic" is okay.

image

@ReneNulschDE
Copy link
Contributor

What other custom components do you have installed? I assume you made an update of ics_calendar to version 5.0.4? if yes, check here

@marci227
Copy link

yes i have ics_calendar 5.0.4 since 2 months. Changed the sbazf_de.py and GUI of WCS is not working anymore.
I will be waiting of new version of ics

Maddimax pushed a commit to Maddimax/hacs_waste_collection_schedule that referenced this issue Nov 15, 2024
The "api" of SBAZV has changed (see mampfes#2870). I used @rmi1974
solution and changed it so the user can simply enter the URL
he copied from the Website.
Maddimax pushed a commit to Maddimax/hacs_waste_collection_schedule that referenced this issue Nov 16, 2024
The "api" of SBAZV has changed (see mampfes#2870).
Since its a simple url with ics data, we can use the ics source.
5ila5 pushed a commit that referenced this issue Nov 18, 2024
The "api" of SBAZV has changed (see #2870).
Since its a simple url with ics data, we can use the ics source.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants