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_binsensor.burgundy_binsensor.green_binsensor.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 %}
