Waste Collection Notifications in Home Assistant

I am struggling to create the templates he did in this video.

I used the Waste Collection Schedule integration. I had to use static setup as my local council does not have iCal, and the website provider is broken.

I have 4 sensors for the 4 bins, and they are all working:

  • sensor.grey_bin
  • sensor.burgundy_bin
  • sensor.green_bin
  • sensor.beige_bin

I’m following the guide in this video:
Setup Waste Collection Notifications in Home Assistant - TUTORIAL by Smart Home Junkie.

Please, where am I going wrong in my template, as the states are showing unavailable?

I want a sensor that shows which bin is being collected today and one for tomorrow.

Desired Image Logic:

  • If no bins are being collected today or tomorrow, I want an indication saying ‘None’ and to show the image /local/waste/not_bin_day.png.
  • If more than one of the 4 bins is collected, show the image /local/waste/multiple_bins.png.
  • Each of the single bins already has images like /local/waste/burgundy_bin.png.

Here is the YAML for my template sensors:

#  Waste Collection TODAY 
      - name: "Waste Collection Today"
        unique_id: waste_collection_today
        state: >
          {% set waste_sensors = [
            'sensor.beige_bin',
            'sensor.burgundy_bin',
            'sensor.grey_bin',
            'sensor.green_bin'
          ] %}
          {% set ns = namespace(found_types=[]) %}
          {% for s in waste_sensors %}
            {# CRASH FIX 1: Use default(99) for daysTo lookup robustness #}
            {% if state_attr(s, 'daysTo') | default(99) | int == 0 %}
              {% set bin_types = state_attr(s, 'types') %}
              {# CRASH FIX 2: Ensure 'types' is a non-empty list before accessing [0] #}
              {% if bin_types is defined and bin_types is not none and bin_types | length > 0 %}
                {% do ns.found_types.append(bin_types[0]) %}
              {% endif %}
            {% endif %}
          {% endfor %}
          {% if ns.found_types | length > 0 %}
            Today: {{ ns.found_types | join(', ') }}
          {% else %}
            None
          {% endif %}
        attributes:
          date: >
            {% for s in [
              'sensor.beige_bin',
              'sensor.burgundy_bin',
              'sensor.grey_bin',
              'sensor.green_bin'
            ] %}
              {% if state_attr(s, 'daysTo') | default(99) | int == 0 %}
                {{ state_attr(s, 'date') }}
                {% break %}
              {% endif %}
            {% endfor %}
          picture: >
            {% set waste_types = states('sensor.waste_collection_today') %}
            {% if 'None' in waste_types %}
              /local/waste/not_bin_day.png
            {% elif ',' in waste_types or 'Today:' not in waste_types %}
              /local/waste/multiple_bins.png
            {% else %}
              {% set bin_type = waste_types | regex_replace(find='Today: ', replace='', ignorecase=false) %}
              /local/waste/{{ bin_type | lower | replace(" ", "_") }}.png
            {% endif %}

---

      # --- Waste Collection TOMORROW 
      - name: "Waste Collection Tomorrow"
        unique_id: waste_collection_tomorrow
        state: >
          {% set waste_sensors = [
            'sensor.beige_bin',
            'sensor.burgundy_bin',
            'sensor.grey_bin',
            'sensor.green_bin'
          ] %}
          {% set ns = namespace(found_types=[]) %}
          {% for s in waste_sensors %}
            {# CRASH FIX 1: Use default(99) for daysTo lookup robustness #}
            {% if state_attr(s, 'daysTo') | default(99) | int == 1 %}
              {% set bin_types = state_attr(s, 'types') %}
              {# CRASH FIX 2: Ensure 'types' is a non-empty list before accessing [0] #}
              {% if bin_types is defined and bin_types is not none and bin_types | length > 0 %}
                {% do ns.found_types.append(bin_types[0]) %}
              {% endif %}
            {% endif %}
          {% endfor %}
          {% if ns.found_types | length > 0 %}
            Tomorrow: {{ ns.found_types | join(', ') }}
          {% else %}
            None
          {% endif %}
        attributes:
          date: >
            {% for s in [
              'sensor.beige_bin',
              'sensor.burgundy_bin',
              'sensor.grey_bin',
              'sensor.green_bin'
            ] %}
              {% if state_attr(s, 'daysTo') | default(99) | int == 1 %}
                {{ state_attr(s, 'date') }}
                {% break %}
              {% endif %}
            {% endfor %}
          picture: >
            {% set waste_types = states('sensor.waste_collection_tomorrow') %}
            {% if 'None' in waste_types %}
              /local/waste/not_bin_day.png
            {% elif ',' in waste_types or 'Tomorrow:' not in waste_types %}
              /local/waste/multiple_bins.png
            {% else %}
              {% set bin_type = waste_types | regex_replace(find='Tomorrow: ', replace='', ignorecase=false) %}
              /local/waste/{{ bin_type | lower | replace(" ", "_") }}.png
            {% endif %}

I am using a different approach which will not be helpful for your problem, but did you try to test only parts of the code.

When you remove the picture attribute, you could identify if the error is in this part or in the remaining part, just an idea.

You can also put part of your code into the Template-Editor where it’s easier to debug.

One more hint: I know that AI is hallucinating a lot of wrong code for HA, but I do get valuable hints how to create more robust code if I provide some of my code snippeds, but you should not just take over any proposal without checking it on your own.

The append list method is not supported.

Wherever possible it is best to use the built-in filters instead of using loops and namespaces.

#  Waste Collection TODAY 
      - name: "Waste Collection Today"
        unique_id: waste_collection_today
        state: >
          {%- set waste_sensors = [
            'sensor.beige_bin',
            'sensor.burgundy_bin',
            'sensor.grey_bin',
            'sensor.green_bin'
          ] %}
          {%- set today_list = waste_sensors | select('is_state_attr', 'daysTo', 0) | list %}
          {%- set typed = today_list | map('state_attr', 'types') | reject('in', ['None', none]) | list %}
          {%- if typed | count > 0 %}
            Today: {{ typed | join(', ') }}
          {%- else %}
            Not Bin Day
          {%- endif %}
        attributes:
          picture: >
            {%- set waste_types = this.state %}
            {%- if waste_types == 'Not Bin Day' %}
              /local/waste/not_bin_day.png
            {%- elif ',' in waste_types or 'Today:' not in waste_types %}
              /local/waste/multiple_bins.png
            {%- else %}
              {%- set bin_type = waste_types | replace('Today: ', '') %}
              /local/waste/{{ bin_type | slugify }}.png
            {%- endif %}

I would avoid using “None” as a state.

What is the purpose of the date attribute? As you had it, all it would ever tell you is the current date or None… which is kind of a useless thing to calculate.