Template not entering multi line mode

I tried to use the following template. Works perfectly fine when used with quotes as a single line statement but I am unable to have it as a multi-line Statement. Any Suggestions?

action: climate.set_preset_mode
data:
  preset_mode: > 
  {% if (states('sensor.absolute_outside_humidity') > states('sensor.absolute_humidity_sensor')) or (state_is('alarm_control_panel.alarmo', 'armed_vacation')) and state_attr('climate.living_room','humidity') < 61 %}
  "Off"
  {% else %}
  "ManualHeatRecovery"
  {% endif %}
target:
  device_id: c63d42c3ca71df249274b1e55cf91c71

What does it do as a multiline? Give the wrong response?

It really should not be any different between the two.

But I see a couple things. These things should be handled the same between single line and multiline. Not sure why you get different results.

  • states are type string. If the two values in your first condition have a different number of digits, this will not work as expected. You should cast both of those to int.
  • I am assuming your if is meant to be if (condition 1) or (condition 2 and condition 3). If my assumption is correct, you need to move the last parenthesis before the and to the end.
or (state_is('alarm_control_panel.alarmo', 'armed_vacation') and state_attr('climate.living_room','humidity') < 61)

Again, neither of those should cause it to work differently. Just what I saw.

It just is not entering multiline mode i.e. it treats the whole statement as invalid and does not allow me to safe the automation :man_shrugging:

You are totally correct about the if statements parentheses. Problem has been solved, the template part was missing one white space for correct indentation
Working Solution is below

action: climate.set_preset_mode
data:
  preset_mode: >
    {% if (states('sensor.absolute_outside_humidity') >
    states('sensor.absolute_humidity_sensor')) or
    (state_is('alarm_control_panel.alarmo', 'armed_vacation') and
    state_attr('climate.living_room','humidity') < 61) %} Off {% else %}
    ManualHeatRecovery {% endif %}
target:
  device_id: c63d42c3ca71df249274b1e55cf91c71