Script Template condition not working

Hi all,
I just don’t get the following script to work:

if:
  - condition: template
    value_template: |-
      "{{ (states('input_number.poolpump_running_time_today') | int) <
        (states('input_number.poolpump_running_time_threshold') | int) }}"
    then: 
      ...

The condition is always returning false, however the template returns true as expected when using the template debugger in the developer tools.

Just a guess, but does it have to be:

    value_template: >
      "{{ (states('input_number.poolpump_running_time_today') | int) <
        (states('input_number.poolpump_running_time_threshold') | int) }}"

or just in a single line:

    value_template: "{{ (states('input_number.poolpump_running_time_today') | int) < (states('input_number.poolpump_running_time_threshold') | int) }}"

Thanks! I don‘t fully understand it, but it works when just using a single line.

On a single line you have to use quotes. With the multiline options you should omit the wrapping quotes, so the multiline solution should be:

    value_template: >
      {{ (states('input_number.poolpump_running_time_today') | int) <
        (states('input_number.poolpump_running_time_threshold') | int) }}

To understand the various multiline options better, look here: https://yaml-multiline.info/.

2 Likes