I’ve basically gone with the same kind of hacky way you have to end up with 2 sensors, one for each (potential) bin that is to be collected, so sometimes I end up with the ‘unknown’ 2nd sensor too and they aren’t centred in my lovelace card anymore so my OCD doesn’t like it lol.
I’ve been trying to do something with my local authority (Bradford Council) but they seem to have there data is some kinda strange database backend (eb). This is the end point they use:
I’ve tried a couple of web scraping options but the data needs to be searched first (via postcode) and that doesn’t seem to be acheable which the sites I’ve used.
like i said a few days ago, save yourselve the trouble from trying to find a way to scrape it.
collect the data once a year, put it in an ical file and use that for your automations.
That sounds like a good solution, however there are a few limitations I can see:
My local authority only release their schedule for a few months ahead not an entire year. The above method also doesn’t take into account any changes/cancellations of the collection.
i dont know how its at your place but if its anything like here they change very little.
we get a new schedule every year, but i now before the schedule is there which dates it will be.
does it happen regularly that they change or cancel?
we never had a cancelation in 13 years. (and even if they did noone would know in advance)
i dont think there is an elevenst but an eleventh?
or am i wrong about that
@apt i know that you can use vars (or in this case a dict) but i think you need to search the forum to find examples.
the code i gave works, but it can be simplefied.
it gives st when the day is 1, nd when the day is 2 and rd when the day is 3
i replaced (as_timestamp(states.calendar.waste_collection.attributes.start_time)|timestamp_custom("%d")|int) with 1 and then it gives st
of course th is default, that applies to 90% from all dates.
Thanks for all your help. I managed however (via another thread) to work out how to perform what I wanted via a Jinja2 macro, See below for the full sensor:
waste_collection_date:
friendly_name: 'Collection Date'
value_template: >
{%- macro suffix(d) %}
{%- set sfx = {1:'st',2:'nd',3:'rd'} %}
{{- 'th' if 11 <= d <= 13 else sfx.get(d%10, 'th') }}
{%- endmacro %}
{% set day = as_timestamp(states.calendar.waste_collection.attributes.start_time) | timestamp_custom('%A') %}
{% set date = as_timestamp(states.calendar.waste_collection.attributes.start_time) | timestamp_custom('%d') |int %}
{{ day }} {{ date }}{{ suffix(date) }}
icon_template: mdi:calendar-star