{% set depth = states('sensor.airmar_depth') | float %} {% if depth < 3 %} {% set ratio = 7 %} {% elif depth < 5 %} {% set ratio = 5 %} {% elif depth < 7 %} {% set ratio = 4 %} {% elif depth < 10 %} {% set ratio = 3.5 %} {% else %} {% set ratio = 3 %} {% endif %} {% set chain_length = depth * ratio %} {% set final_value = chain_length if chain_length >= 15 else 15 %} {{ final_value | round(0, 'ceil') }}