Delay does not work in automation

Hi everyone, i’m trying to make a smart automation to run my irrigation based on weather condition. I’m starting with the easiest way so i run for different periods of time based on the highest temperature recorded the day before.
This is the automation i wrote, but as soon as i check the configuration i get an error and the automation does not run… where am i wrong?

#Irrigazione Manuale Terrazzo
- id: irrigazione_terrazzo_manuale
  alias: Irrigazione Manuale Terrazzo
  description: "Se l'irrigazione smart è disattivata, irriga manualmente"
  trigger: 
  - platform: time
    at: input_datetime.inizio_irrigazione
  condition:
  - condition: numeric_state
    entity_id: input_number.pioggia_oggi
    above: '2'
  - condition: numeric_state
    entity_id: input_number.pioggia_ieri
    above: '4'
  action:
  - entity_id: switch.irrigazione_terrazzo
    service: switch.turn_on
  - delay: "{{states('input_datetime.durata_irrigazione_25')}}"
#  - delay: >
#        {% if is_state(input_number.temperatura_massima_ieri) > 20 %}
#          states('input_datetime.durata_irrigazione_20')
#        {% if is_state(input.number.temperatura_massima_ieri) > 25 %}
#          states('input_datetime.durata_irrigazione_25')
#        {% if is_state(input_number.temperatura_massima_ieri) > 30 %}
#          states('input_datetime.durata_irrigazione_30')
#        {% else %}
#          states('input_datetime.durata_irrigazione_default')}}
#        {% endif %}
  - entity_id: switch.irrigazione_terrazzo
    service: switch.turn_off
  - service: notify.mobile_app_iphone_christian
    data:
      title: >
        {{ "\U0001FAB4" }} Irrigazione terrazzo
      message: "Attivata per 1 minuto"

As soon as i hit the check button i get this error in the log:

Logger: homeassistant.config
Source: config.py:443 
First occurred: 20 luglio 2021, 23:51:48 (5 occurrences) 
Last logged: 20 luglio 2021, 23:56:21

Invalid config for [automation]: offset {% if is_state(input_number.temperatura_massima_ieri) > 20 %} (input_datetime.durata_irrigazione_20) {% if is_state(input.number.temperatura_massima_ieri) > 25 %} (input_datetime.durata_irrigazione_25) {% if is_state(input_number.temperatura_massima_ieri) > 30 %} (input_datetime.durata_irrigazione_30) {% else %} (input_datetime.durata_irrigazione_default) {% endif %} should be format 'HH:MM', 'HH:MM:SS' or 'HH:MM:SS.F' for dictionary value @ data['action'][2]['delay']. Got None. (See ?, line ?).
Invalid config for [automation]: offset {% if is_state(input_number.temperatura_massima_ieri) > 20 %} input_datetime.durata_irrigazione_20 {% if is_state(input.number.temperatura_massima_ieri) > 25 %} input_datetime.durata_irrigazione_25 {% if is_state(input_number.temperatura_massima_ieri) > 30 %} input_datetime.durata_irrigazione_30 {% else %} input_datetime.durata_irrigazione_default {% endif %} should be format 'HH:MM', 'HH:MM:SS' or 'HH:MM:SS.F' for dictionary value @ data['action'][2]['delay']. Got None. (See ?, line ?).
Invalid config for [automation]: offset {% if is_state(input_number.temperatura_massima_ieri) > 20 %} states('input_datetime.durata_irrigazione_20') {% if is_state(input.number.temperatura_massima_ieri) > 25 %} states('input_datetime.durata_irrigazione_25') {% if is_state(input_number.temperatura_massima_ieri) > 30 %} states('input_datetime.durata_irrigazione_30') {% else %} states('input_datetime.durata_irrigazione_default') {% endif %} should be format 'HH:MM', 'HH:MM:SS' or 'HH:MM:SS.F' for dictionary value @ data['action'][2]['delay']. Got None. (See ?, line ?).
Invalid config for [automation]: offset {% if is_state(input_number.temperatura_massima_ieri) > 20 %} {{states('input_datetime.durata_irrigazione_20')}} {% if is_state(input.number.temperatura_massima_ieri) > 25 %} {{states('input_datetime.durata_irrigazione_25')}} {% if is_state(input_number.temperatura_massima_ieri) > 30 %} {{states('input_datetime.durata_irrigazione_30')}} {% else %} {{states('input_datetime.durata_irrigazione_default')}} {% endif %} should be format 'HH:MM', 'HH:MM:SS' or 'HH:MM:SS.F' for dictionary value @ data['action'][2]['delay']. Got None. (See ?, line ?).

Another question: to modify the duration of the delay i had to set 4 different input_datetime helpers… can i just set a “default” helper and multiply it based on the temperature? How can i implement it?
Thanks in advance

It looks like you haven’t configured the input_datetime or given it a default value. See the documentation for how to do that, and share your code if you think you’ve configured the input_datetime correctly.

delay: is looking for a number of minutes, not a datetime object or string representation thereof. The error messages make it appear that the part that you’ve commented out isn’t actually commented out, and it has a bunch of errors if you left it in.

This isn’t proper syntax: is_state(input_number.temperatura_massima_ieri) > 20. You want this:
states('input_number.temperatura_massima_ieri')|float > 20. Same for the others. Note the quotes that I put around the entity_id that you’ve left out.

You also have a bunch of “if” statements there one after another, which isn’t proper syntax. You can have an “if” followed by some number of “elif”, or an “if” followed by an “endif”, but not just multiple “if” statements like that.

Then, you need to enclose the “output” in {{ }}, not just states('input_datetime.durata_irrigazione_default'), but again, you need a number of minutes, not a datetime.

1 Like

Well, it would’ve been difficult to put more errors in a single automation haha.
The question then become very simple: how could i set something i could easily modify and multiply?
I mean: i would like to set a default time (like i did with that default input_datetime) i can easily modify (without needing to modify all the automation) and multiply (e.g. above 20°C is default, above 25°C is 1.5 x default etc).

Use an input_number

1 Like

Well… easier than what i thought haha, thanks! It now works smoothly