Do you actually need a script? Your problem is categorically different than the original post… OP wanted an annual repeat that accounted for the Month, Week index, and Day of the week.
The Repeat Monthy option in the “Add Event” dialog can handle what you are trying to do, and have it repeat forever:
This is one way to perform slicing based on index number. This is a basic method used in Python and, as such, is considered outside the scope of Home Assistant documentation. In this case it selects the first 10 elements of the datetime string so it returns some like 2024-03-10
instead of something like 2024-03-10T00:00:00-05:00
. The calendar.create_event
has been updated since the start of this thread to allow datetime date objects. Slicing will still work, but it isn’t the only option.
ChatGPT is a bullshit engine… and that’s exactly what it has given you.
action: calendar.create_event
data:
summary: Papierabfuhr
start_date: >
{% from 'easy_time.jinja' import month_week_day %}
{{ month_week_day(month, 3, 5)[:10] }}
end_date: >
{% from 'easy_time.jinja' import month_week_day %}
{{ (month_week_day(month, 3, 5) | as_datetime | as_local + timedelta(days=1)).date() }}
target:
entity_id: calendar.test