Sensor template if condition

Hi all, I’m trying to put a condition inside a template.
Can you help me with the code?
For now I wrote this:

- platform: template
  sensors:
    orario_accensione_irrigazione:
      value_template: >
      {% if states('input_boolean.avvio_irrigazione_alba') == 'on' %}
        '{{ as_timestamp(states.sun.sun.attributes.next_rising) + states.input_number.delta_minuti_accensione_irrigazione | timestamp_custom("%H:%M") }}'
      {% elif states('input_boolean.avvio_irrigazione_tramonto') == 'on' %}
        '{{ as_timestamp(states.sun.sun.attributes.next_setting) + states.input_number.delta_minuti_accensione_irrigazione | timestamp_custom("%H:%M") }}'      
      {% elif states('input_boolean.avvio_irrigazione_orario_fisso') == 'on' %}
        '{{ as_timestamp(states.sun.sun.attributes.next_rising) + states.input_number.delta_minuti_accensione_irrigazione | timestamp_custom("%H:%M") }}'
      {% endif %}

I get the syntax wrong, but I don’t know where
Thansk

:thinking:

'

You should remove the single quotes around the timestamp values

...
{{ as_timestamp(states.sun.sun.attributes.next_rising) + states.input_number.delta_minuti_accensione_irrigazione | timestamp_custom("%H:%M") }}
...

As the warning at the end of the State templating docs states, it is best to use the states(), state_attr(), and is_state() functions instead of the state object method.

- platform: template
  sensors:
    orario_accensione_irrigazione:
      value_template: >
        {% set min_acc = states('input_number.delta_minuti_accensione_irrigazione') | int(0) %}
        {% if is_state('input_boolean.avvio_irrigazione_alba','on') or
        is_state('input_boolean.avvio_irrigazione_orario_fisso','on') %}
          {{ state_attr('sun.sun','next_rising')|as_datetime + timedelta(minutes=min_acc) }}
        {% elif is_state('input_boolean.avvio_irrigazione_tramonto','on') %}
          {{ state_attr('sun.sun','next_setting')|as_datetime + timedelta(minutes=min_acc) }}      
        {% endif %}

Thanks for the replies.
The code I posted is a copy and paste, I don’t know the code and I’m going to experiment.
My idea was to give a “time” value to orario_accensione_irrigazione, based on 3 options in the interface.
1 - if avvio_irrigazione_alba is selected then the orario_accensione_irrigazione value must be the dawn time + delta_minuti_irrigazione;
2 - if avvio_irrigazione_tramonto is selected then the value of orario_accensione_irrigazione must be the sunset time + delta_minuti_irrigazione;
3 - if avvio_irrigazione_orario_fisso is selected then the value of orario_accensione_irrigazione must be equal to orario_avvio_irrigazione (datetime entity)

In the first post I made a mistake in the third option.