Bin / Waste Collection

Evidently 2020 having 53 weeks means 2021 has swapped odd/even weeks for my council’s schedule.

image

Simple enough to swap the bin types around in the Python code though.

import datetime

today = datetime.date.today()
if today.weekday() > 3:
	# If this Thursday has passed, we only care about next week.
	today = today + datetime.timedelta((0 - today.weekday()) % 7)

# Get the ISO week number (1-52~53)
week_number = today.isocalendar()[1]

if (week_number % 2) == 0:
	# Even weeks are for Recycling
	collection_type = 'Recycling'
else:
	# Odd weeks are for Garden Waste
	collection_type = 'Garden Waste'

print(collection_type)

And just as a refresher (for those searching, and have a simple week-about schedule), these are the sensors…

sensor:
  - platform: command_line
    name: bintype
    command: "python3 /config/python_scripts/bin_week.py"
  - platform: template
    sensors:
      bincol:
        friendly_name: "This week's bin"
        value_template: '{{ states("sensor.bintype") }}'
        entity_picture_template: >
          {% if is_state('sensor.bintype', 'Recycling') %}
             /local/images/bin_yellow.png
          {% elif is_state('sensor.bintype', 'Garden Waste') %}
             /local/images/bin_green.png
          {% endif %}

… and my two bin images (just recoloured mdi-trash-can-outline)
bin_green bin_yellow

1 Like