Sensor template compare expected date with today

I’m goin mad. I have an imput_datetime where the last run is registered. Also have an input_number to store the expected date duration in days for the next time run. I’d line to make a template sensor, which swows the next run date if the last run date + elapse days is later than today and shows today it the last run+elapse days is earlier or equals today.
The code below gives alwasy today’s date. What I do wrong?

I have this:

      next_run:
        value_template: >-
        {% if (states('input_datetime.last_run') | as_datetime | as_local + timedelta(days= (states('input_select.elapse') | int(0)) )).date() < now().date() %}
          {{ states('sensor.date') }}
        {% else %}
          {{ (states('input_datetime.last_run) | as_datetime | as_local + timedelta(days= (states('input_select.elapse') | int(0)) )).date() }}
        {% endif %}

Pop this in the template editor and tell us what you get:

{{ states('input_datetime.last_run') }}
{{ states('input_select.elapse') }}

2022-07-20 04:09:51
1

OK, those numbers should result in today’s date, as the condition evaluates as true (at the moment, won’t for those joining us later!). Upping the elapse number to 2 evaluates as False for me (second line):

{{ ("2022-07-20 04:09:51" | as_datetime | as_local + timedelta(days=("1"|int(0)) )).date() < now().date() }}
{{ ("2022-07-20 04:09:51" | as_datetime | as_local + timedelta(days=("2"|int(0)) )).date() < now().date() }}

You should be able to put the entire template into the editor and play around with it. I had no issues with getting the condition to change from true to false as expected.

You seem to be using the old template sensor format. Try the new way?