Waste Collection Schedule Framework

Still no luck with your recommendation:

   customize:
        - type: "Gelbe Tonne, Gelber Sack "
          alias: gelbetonne
          icon: mdi:trash-can

It’s not working correctly. I tried different things and if I remember correctly, with “split_at” and only “Gelbe Tonne” I can see the correct dates but only for Gelbe Tonne/Gelber Sack, all others are unknown. There was one configuration which got me Schadstoffmobil too…

PS: I think the provider of the ICS tried to escape the comma since they are also using it in address like

LOCATION;LANGUAGE=de:August-Uhlmann-Strasse 37\, 09390 Gornsdorf

@mampfes - a little help please. :pray:

Everything is working! The integration is awesome. My city has an iCal they provide but not url. No problem though since I was able to download the iCal and integrate into my HA! :slight_smile:

My card shows the correct icon for the upcoming event and when perfectly, however I would like to add the “type” to the description. I’m sure it should go in the value_template? In the card graphic below, I’d like for it to say “Trash in 7 days” or “Bulk recycling in 7 days” or whatever the type is. I’ve seen examples using multiple sensors but I really only need the upcoming events, not a tile, icon, entity for each type. Is there a way to do this?

I should mention that sometimes there will be multiple types on the same day (i.e. Bulk recycling, glass.)

  • platform: waste_collection_schedule
    name: Trash
    details_format: upcoming
    count: 1
    leadtime: 4
    value_template: ‘{% if value.daysTo == 0 %}Today{% elif value.daysTo == 1 %}Tomorrow{% else %}{{value.daysTo}} Days{% endif %}’

waste_collection_schedule:
sources:
- name: ics
args:
file: /share/calendar/garbage.ics
regex: “Abfuhr: (.*)”
calendar_title: “Trash Pickup”
customize:
- type: “Glasabfuhr”
alias: “Glass”
icon: mdi:sack-outline
- type: “Bioabfall”
alias: “Bio”
- type: “Restmüll”
alias: “Trash”
- type: “Wertstoffsäcke”
alias: “Bulk recycling”
icon: mdi:recycle
- type: “Umweltmobil”
alias: “Recycling van”
icon: mdi:truck

@Moschi87 The following config works on my machine, including all aliases:

waste_collection_schedule:
  sources:
    - name: ics
      args:
        url: https://online-portal.za-sws.de/WasteManagementSuedwestsachsen/WasteManagementServiceServlet?ApplicationName=Calendar&SubmitAction=sync&StandortID=16459903001&AboID=80078&Fra=P;R;B;C;S;W;L
        verify_ssl: false
      customize:
        - type: "Restmuelltonne 02-woechentl."
          alias: schwarzetonne
          icon: mdi:trash-can
        - type: "Papiertonne 04-woechentl."
          alias: blauetonne
          icon: mdi:trash-can
        - type: "Biotonne 02-woechentl."
          alias: braunetonne
          icon: mdi:trash-can
        - type: "Gelber Sack, Gelbe Tonne"
          alias: gelbetonne
          icon: mdi:trash-can
        - type: "Schadstoff"
          alias: schadstoffmobil
          icon: mdi:trash-can

@fspatt Try:

value_template: '{{value.types|join(", ")}} {% if value.daysTo == 0 %}Today{% elif value.daysTo == 1 %}Tomorrow{% else %}in {{value.daysTo}} Days{% endif %}'

1 Like

Great you got it working and thanks for the update. :slight_smile:

Some more questions so I can complete my configurations. I have all of my static sensors set via the following yaml file.

waste_collection_schedule:
  sources:
    - name: static
      args:
        type: Garbage
        frequency: WEEKLY
        weekdays: {MO, TH}
    - name: static
      args:
        type: Recycle
        frequency: WEEKLY
        weekdays: WE
    - name: static
      args:
        type: Yard Waste
        frequency: WEEKLY
        weekdays: MO
    - name: static
      args:
        type: Branches
        frequency: WEEKLY
        weekdays: TU

I am confused on how to add the sensor info called out in the docs for the garbage collection card?

# configuration.yaml
sensor:
  - platform: waste_collection_schedule
    name: garbage_days
    details_format: appointment_types
    value_template: "{{ value.daysTo }}"
    types:
      - Garbage

  - platform: template
    sensors:
      garbage:
        value_template: >
          {% if states('sensor.garbage_days')|int > 2 %}
            2
          {% else %}
            {{ states('sensor.garbage_days')|int }}
          {% endif %}
        attribute_templates:
          next_date: "{{ state_attr('sensor.garbage_days', 'Garbage') }}"
          days: "{{ states('sensor.garbage_days')|int }}"

What I want is four sensors. One for each type.

Thanks.

@mampfes - works like a charm! Thanks so much!

1 Like

Thanks for your help. All waste types are correct now :slight_smile: I had an misconfiguration in my sensors.yaml from testing…

Hoping someone smarter than me can weigh in… I’m struggling to get anything working and seeing python errors in my logs:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 257, in _async_setup_component
    result = await task
  File "/config/custom_components/waste_collection_schedule/__init__.py", line 109, in async_setup
    api.add_source_shell(
  File "/config/custom_components/waste_collection_schedule/__init__.py", line 202, in add_source_shell
    SourceShell.create(
  File "/config/custom_components/waste_collection_schedule/waste_collection_schedule/source_shell.py", line 196, in create
    source = source_module.Source(**source_args)  # type: ignore
  File "/config/custom_components/waste_collection_schedule/waste_collection_schedule/source/static.py", line 95, in __init__
    self._start = parser.isoparse(start).date() if start else None
  File "/usr/local/lib/python3.10/site-packages/dateutil/parser/isoparser.py", line 37, in func
    return f(self, str_in, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/dateutil/parser/isoparser.py", line 134, in isoparse
    components, pos = self._parse_isodate(dt_str)
  File "/usr/local/lib/python3.10/site-packages/dateutil/parser/isoparser.py", line 208, in _parse_isodate
    return self._parse_isodate_common(dt_str)
  File "/usr/local/lib/python3.10/site-packages/dateutil/parser/isoparser.py", line 213, in _parse_isodate_common
    len_str = len(dt_str)
TypeError: object of type 'datetime.date' has no len()

with the following config:

# waste collection schedule
waste_collection_schedule:
 sources:
   - name: static
     args:
       type: recycling
       frequency: WEEKLY
       weekdays: TU
       interval: 2
       start: 2023-05-09
   - name: static
     args:
       type: food_waste
       frequency: WEEKLY
       weekdays: TU
   - name: static
     args:
       type: rubbish
       frequency: WEEKLY
       weekdays: TU
       interval: 2
       start: 2023-05-16

# Template for custom sensors
sensor:
 - platform: waste_collection_schedule
   name: recycling
   types:
     - recycling
   value_template: "{{ value.daysTo }}"
 - platform: waste_collection_schedule
   name: rubbish
   types:
     - rubbish
   value_template: "{{ value.daysTo }}"
 - platform: waste_collection_schedule
   name: food_waste
   types:
     - food_waste
   value_template: "{{ value.daysTo }}"

Am I being incredibly dense? At one point previously I managed to get a single sensor working and have re-installed via HACs a number of times, restarting inbetween (which often takes an age since adding WCSF).

Cheers.

The date in your sources needs to be in quotation marks, otherwise it can’t be parsed correctly. Try it like this:

waste_collection_schedule:
 sources:
   - name: static
     args:
       type: recycling
       frequency: WEEKLY
       weekdays: TU
       interval: 2
       start: '2023-05-09'

I’m sorry, didn’t notice your answer. :slight_smile:

Have you tried just setting up four sensors? You can configure the sensors in kind of a one-to-one relation to your source (aka source = paper => sensor = paper) or you can pack multiple sources in one sensor (aka source = waste collection provider => sensor = paper, garbage,…).

I’d go with the one-to-one relation, but as you have definied more than one source, you need to connect the sensor with the specific source, something like this:

sensor:
  - platform: waste_collection_schedule
    name: garbage
    source_index: 1
    details_format: appointment_types
    value_template: "{{ value.daysTo }}"
    types:
      - Garbage
  - platform: waste_collection_schedule
    name: recycle
    source_index: 2
    details_format: appointment_types
    value_template: "{{ value.daysTo }}"
    types:
      - Recycle

The basic idea, that people get confused with is the connection between sources and sensors. Sources are only to get data. What happens with this data is up to the sensors. So you can define the relationships between source and sensor in many ways, and that’s where it gets confusing. :smiley: As I said, in your case I’d go with one-to-one, just for easier setup and maintenance. :slight_smile:

Let us know, if this works for you! :slight_smile:

Thanks Patrick,

Making that change HA hung when I did a full restart (though still responded to pings). Power cycling had everything booting up and the recycling sensor shows properly… the other two are showing as unknown - any ideas?

What do the logs say? Any errors? :slight_smile:

First, look into the logs after a restart of HA (doesn’t need to be the machine, only HA), this is assuming you run HomeAssistantOS or supervised install. If that doesn’t bring up anything meaningful, set the logger to DEBUG for this integration only and restart.

See here on how to set the logger integration:

I’m running on a home assistant yellow with the yellow version of HAOS - thanks for the guide on logs!
(I do get some errors involving aiohttp.server and another set involving switchbot but I think that’s unlreated and fairly common)
Assuming

   logs:
    custom_components.waste_collection_schedule: debug

is correct… I see nothing on HAOS restart =/

Thanks. This should work. What is the source_index? No mention in the docs.

:+1: It’s not easy to find, but actually it is in the docs :slight_smile:

Great it works for you! :slight_smile:

Hmmm, have you checked if “WCSF” is really the culprit? Look under settings → system → repairs → three dots in the upper right, choose 'Integration Startup Time" and see how long it takes WCSF to start. If you’ll see another integration taking a long time, you may have the culprit there. :slight_smile:

Don’t forget to disable debug in logger. :wink:

I also have only one sensor working. sensor.next_yard_collection shows 2. The other 3 shows unknown.

My yaml:

waste_collection_schedule:
  sources:
    - name: static
      args:
        type: Garbage
        frequency: WEEKLY
        weekdays: {MO, TH}
    - name: static
      args:
        type: Recycle
        frequency: WEEKLY
        weekdays: WE
    - name: static
      args:
        type: Yard Waste
        frequency: WEEKLY
        weekdays: MO
    - name: static
      args:
        type: Branches
        frequency: WEEKLY
        weekdays: TU
sensor:
# next garbage collection
  - platform: waste_collection_schedule
    name: garbage_collection
    source_index: 0
    details_format: appointment_types
    value_template: "{{ value.daysTo }}"
    types:
      - Garbage
# next yard waste collection
  - platform: waste_collection_schedule
    name: next_yard_collection
    source_index: 1
    details_format: appointment_types
    value_template: "{{ value.daysTo }}"
    types:
      - Yard Waste
# next garbage collection
  - platform: waste_collection_schedule
    name: recycle_collection
    source_index: 2
    details_format: appointment_types
    value_template: "{{ value.daysTo }}"
    types:
      - Recycle    
# next branches
  - platform: waste_collection_schedule
    name: branches_collection
    source_index: 3
    details_format: appointment_types
    value_template: "{{ value.daysTo }}"
    types:
      - Branches

I played a little with the source index. It seems per the docs the first index is 0. I re-numbered mine and after a reboot I get two sensors now. Garbage (index 0 ) and branches (index 3). Lost yard collection after the re-numbering. I’m not understanding the docs well enough to figure how what I am doing incorrectly.

With my sensor above I get the following errors in HA:

Logger: homeassistant.components.sensor
Source: custom_components/waste_collection_schedule/waste_collection_schedule/collection_aggregator.py:17
Integration: Sensor (documentation, issues)
First occurred: 8:14:13 PM (2 occurrences)
Last logged: 8:14:13 PM

Error adding entities for domain sensor with platform waste_collection_schedule
Error while setting up waste_collection_schedule platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 455, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 731, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 844, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/waste_collection_schedule/sensor.py", line 141, in async_added_to_hass
    self._update_sensor()
  File "/config/custom_components/waste_collection_schedule/sensor.py", line 200, in _update_sensor
    upcoming1 = self._aggregator.get_upcoming_group_by_day(
  File "/config/custom_components/waste_collection_schedule/waste_collection_schedule/collection_aggregator.py", line 65, in get_upcoming_group_by_day
    self._entries,
  File "/config/custom_components/waste_collection_schedule/waste_collection_schedule/collection_aggregator.py", line 17, in _entries
    return [e for s in self._shells for e in s._entries]
  File "/config/custom_components/waste_collection_schedule/waste_collection_schedule/collection_aggregator.py", line 17, in <listcomp>
    return [e for s in self._shells for e in s._entries]
AttributeError: 'NoneType' object has no attribute '_entries'

All 4 sensors are adding the information in the HA calendar. Only the next yard waste sensor shows a value.

Hi to all. maybe someone can help me…

I defined custom sensors with

customize:

  • type: “Papiermüll”
    alias: Papier

and value_template: ‘{{value.types|join(", ")}} {% if value.daysTo == 0 %}Today{% elif value.daysTo == 1 %}Tomorrow{% else %}in {{value.daysTo}} Days{% endif %}’

to show a state like :

Papier in 2 tagen
Papier morgen

I am using a MDT Glastaster to show next waste collection an wanted to shorten the words Papier to P Restmüll to R Bio to B…
because the state on the knx device just allows 10 letters.

I don’t know how to transform this words within my template?!

I tried something like : ‘{% if {{value.types|join(", ")}} == Papier %}P{% endif %}’

but this won’t work