Binary Sensor Template Values

My community publishes our waste collection details in a few formats, one of them is a calendar which is the option I’m using.

I’ve setup a few binary sensors that pull our the required information from the ‘calendar.waste_collection’ entity and present the details on my HA frontend.

Now most of the time things run smoothly, I get the date of pickup, how many bags were allowed each week (a few weeks of the years we get 2), and whether it’s grey box or blue box pickup.

Now I’ve discovered an issue this week. I went to check to see if pickup was Grey or Blue box this week and that part was missing. I went looking at the Attributes for the ‘calendar.waste_collection’ entity and noticed that it showed “Grey box”.
So I then checked my binary sensor and it was looking for ‘grey box’. So I updated my sensor and the entry was back on the card.
Then yesterday I looked again and noticed it was gone again. Checked the Attributes and it was now ‘grey box’.

I don’t know why case changes are happening. It could be on the City’s side with someone different doing updates, on HA side on how it pulls the data.

I am wondering if this change would work.

current binary sensor:

  - platform: template
    sensors:
      grey_box:
        entity_id:
          - calendar.waste_collection
        value_template: '{{"grey" in state_attr("calendar.waste_collection", "message")}}'

What I’m thinking of implimenting:

  - platform: template
    sensors:
      grey_box:
        entity_id:
          - calendar.waste_collection
        value_template: >-
          {{ "grey" in state_attr("calendar.waste_collection", "message")
             or  "Grey" in state_attr("calendar.waste_collection", "message") }}

I don’t know if that would work as the example offered is using “is_state” for a sensor value.

Just use the filter | lower to convert your received data to lower case and look for a match with “grey”.

value_template: '{{"grey" in state_attr("calendar.waste_collection", "message") | lower }}'

Well that’s way easier

…and now you have to account for when someone gets a wild hare and spells it “Gray”. :slight_smile: