Condition to check if even or uneven weeks

Hey, im trying to create and automation that will check if its an even week and based on this make a Lovelace card to show when my garbage is pick up. However im stuck at trying to make it have condition to if its even or uneven weeks.

I searched much but most post seems to be from 2020 and the code won’t work anymore. I Tried

    value_template: {{(now().strftime('%U') | int % 2) == 1}}

and many other but it just gives me error that the value template is wrong.

Does anyone know any way to do it or a way to point me in the right direction.

Kind reagrds

You need quotes around it:

value_template: "{{(now().strftime('%U') | int % 2) == 1}}"

But there are times when this will not trigger every other week.
Like week 53 → 1

A shorter way to do it:

    value_template: "{{ now().isocalendar()[1] % 2 == 0 }}"

Another way to do it is use this great HACS addon

Gives me this…

1 Like

1 character shorter

    value_template: "{{ not now().isocalendar()[1] % 2 }}"
2 Likes

Same length, improved legibility.

      value_template: "{{ now().isocalendar()[1] is even }}"

2 Likes