Local calendar, odd/even weeks

Hi,
I use an old removed HACS integration to notify and keep track of garbage pickup.
Since it is removed and gives me an error in logs everytime i restart i was looking to change to local calendar as suggested in HACS.
But there is one choice missing in the recurring part of local calendar, Odd or Even week numbers.
I would like to suggest to add those in the same list as the picture shows, the repeat section:


As of now when i have every 2 weeks it will of course work until the week number counter resets from week 53 to 1. Obviously i can change manually everytime this happens, but that might be after i have missed this once which i rather would not like to happen since we have to pay even if we don’t put our bins in the right place.

So i’m hoping for this to be added so i can keep track using supported functions instead of HACS integrations.

Thanks in advance :slight_smile:

You could possibly use a template sensor to indicate even odd weeks. strftime has two ways to calculate week number:

%U		Week number of the year (Sunday as the first day of the week) as a zero padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 0.	00, 01, …, 53
%W		Week number of the year (Monday as the first day of the week) as a decimal number. All days in a new year preceding the first Monday are considered to be in week 0.	00, 01, …, 53

Because Jan 1 was on a Monday this year, that means that %U will always be one behind %W except on Sundays. To create an is_odd_week template binary sensor, the template might look like:

{{ now().strftime("%W") | int % 2 }}

From your post, it sounds like you might need to count weeks from one instead of zero. That might look like

{{ (now().strftime("%W") | int + 1) % 2 }}

Or maybe you need some other definition of counting weeks than is provided here. You might be able to do a custom calculation based on the day of year values that strftime can provide – %j.

For example, counting the first seven days of the year (regardless of which day of week was first) as week 1, then the next seven as week 2, etc. for an is_odd_week binary sensor would look like:

{{ ((now().strftime("%j") | int / 7) | round(0,'floor') + 1) % 2 }}

Thanks for suggestion. :slight_smile:

my thought was to make the local calender easy to use and not require templating for repeated things to remember where week number is part.

also HACS message says functionality is in core, which it really is not, not the odd vs even weeks choice. so i thought it might get added.

i think i will keep using the custom component for the time being, it is working even thou hacs gives warning message in logs.

I can add how my template look like in one of the automations i have to get the boolean test that it is an odd week:

{{ now().isocalendar()[1] % 2 == 1 }}

I also have a sensor with this:

{{ as_timestamp(now()) | timestamp_custom('%V') }}

Exactly my problem. I think it’s nice to have a sensor that shows how many days too next collection.

Some cities have API’s with dates.
Look for that first since that will be a much more robust solution