Week of the month

Hi, I’m trying to set a chores schedule where I need the current week of the month (1 to 5).
Looks like can’t get natively from datetime object, what would be the less intrusive / breakable way to do it? I was looking into native python scripting (would run at 12.00am and save it to a helper) and pyscript (looks more complex, but with custom modules can have nicer code using pendulum).
I’m looking mainly for stability of the set-it-and-forget-it kind.

Define “week of the month” and we can give you a template to return it.

For example, if the 1st of the month is a Wednesday, what is the first date in week 2?

As an example, if you count weeks starting on the 1st or a Monday, this returns the week number that can be up to 6:

{{ (now().day + now().weekday() - 1) // 7 + 1 }}

In that example, a month where the 1st is a Sunday has week 2 starting on Mon 2nd.

If that’s not how you want to count it, explain how you want to count it.

A macro along similar line as Troon’s template:

{% macro week_of_month(dt) %}
{% set first_day = dt.replace(day=1) %}
{% set adjusted_dom = dt.day + first_day.weekday() %}
{{ int((adjusted_dom/7.0)|round(1,'ceil')) }}
{% endmacro %}

Another option that may be applicable, is to use the week of the year:

{{ now().isocalendar().week }}

Thanks, I’m looking for the calendar row, with weeks starting on Monday, if the 1st day of the month is Sunday, that would be week 1 (or 0*) and Monday would be week 2.

*Not sure how you count on hass, in python we use to count from 0.

The template language is Jinja (main) (HA extensions), which is Python behind the scenes. You’ll see my template ends in +1 to match your “1 to 5” (actually 6) request.