Garbage Collection Days - Alternating Images

I wanted a card to show whether the current week’s garbage collection will be 3 cans or just 2 cans, as my collection service alternates on Wednesdays where recycling occurs every other week. So, one week will have yard, trash and recycling, and the next week will have just yard and trash.

Grok clued me on the code to use, in the configuration.yaml file. Here is the code where the card will appear on Mondays, Tuesdays and Wednesdays only:

template:
  - sensor:
      - name: "Recycle Wednesday"
        state: >
          {% set today = now().strftime('%A') %}
          {% set week_number = now().isocalendar().week %}
          {% if today in ['Monday', 'Tuesday', 'Wednesday'] and week_number % 2 == 0 %}
            on
          {% else %}
            off
          {% endif %}
        unique_id: recycle_wednesday
      - name: "Yard Wednesday"
        state: >
          {% set today = now().strftime('%A') %}
          {% set week_number = now().isocalendar().week %}
          {% if today in ['Monday', 'Tuesday', 'Wednesday'] and week_number % 2 == 1 %}
            on
          {% else %}
            off
          {% endif %}
        unique_id: yard_wednesday

Then I uploaded two images in the www folder, which will be used by the cards.

Then I added a Conditional card, and used a simple Picture card to show the current trash bins.

And here’s the other Conditional card.

The code uses the numeric week as a determination of even or odd, and so I’ll need to check this code after New Years to be sure the numeric weeks correspond to the collection service.

I had tried the Waste Collection Schedule integration earlier, but the results were not what I expected.

[Looking at this posting, I see now that the sensor IDs are reversed, that the ‘yard_wednesday’ contains the recycling, and should have been so named. But it is coherent to the collection service as is, and I might make the refinements later.]

1 Like