Datetime and isoweekday

Hi, I have the followig action in one script that doesn't work as I want.
I want to test if the weekday of 'input_datetime.prato_next_time' is monday, wednesday or friday and in this case add one day to the same variable.
What is wrong?
Thanks in advance

- action: input_datetime.set_datetime
    target:
      entity_id: input_datetime.prato_next_time
    data:
      datetime: >
        {% set new_time = states('input_datetime.prato_next_time') %} 
        {% set new_wday = input_datetime.prato_next_time.isoweekday() %}  
        {% if is_state('new_wday', ['1', '3', '5']) %}
           {{ ('input_datetime.prato_next_time' + timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S') }}
        {% endif %}

Should be

{% set new_wday = (states(input_datetime.prato_next_time')|as_datetime).isoweekday() %}

Your template contains several errors.

  1. It attempts to use the state value of input_datetime.prato_next_time without using the states() function. tom_l has identified this mistake and offered a corrected version.

  2. It defines a variable named new_wday but makes the mistake of wrapping it in quotes 'new_wday' in the is_state() function. This makes it a string and will cause the is_state() function to fail.

  3. The input_datetime.set_datetime action will fail with an error message if new_wday is not 1, 3, or 5. That's because the template does not produce a value for datetime if new_day is 2, 4, 6, or 7.

I suggest you do it like this:

  - if:
      - condition: template
        value_template: >
          {{ (states('input_datetime.prato_next_time') | as_datetime).isoweekday()
            in [1, 3, 5] }}
    then:
      - action: input_datetime.set_datetime
        target:
          entity_id: input_datetime.prato_next_time
        data:
          datetime: >
            {% set t = states('input_datetime.prato_next_time') | as_datetime %} 
            {{ (t + timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S') }}

It executes input_datetime.set_datetime only if the isoweekday is 1, 3 or 5.

--

EDIT

Correction. Used wrong entity_id.

Thank you for your kind help.
I have implemented the correction, now I'll see at next occurence if it works.