Template Syntax to change input_number value

I am trying to do something that should be simple as pie but I consistently struggle with templating syntax.

I have been successful formating some sensor values using conditional statements in the value_template of the sensor, such as east_alcove_time_stamp, below.

I am trying to do the same thing with another sensor, but trying to save its current value to a input_number, not just the state change.

The following code in my configuration.yaml shows one working sensor (sensor.east_alcove_time_stamp), and the one I am having great difficulty with (sensor.furnace_temp_min), Should I not be able to set an input_number to the value of sensor?

        east_alcove_time_stamp:
        friendly_name: East Alcove Time Stamp
        unit_of_measurement: ' '
        value_template: >
          {% if is_state('binary_sensor.east_alcove_motion', 'on') %}
          {{ as_timestamp(now())| timestamp_custom('%H:%M') }}
          {% else %}
          {{ as_timestamp(states.binary_sensor.east_alcove_motion.last_changed) | timestamp_custom('%H:%M') }}
          {% endif %} 
          
       furnace_temp_min:
        friendly_name: Furnace Temp Min
        device_class: temperature
        unit_of_measurement: '°F '
        value_template: >
          {% if {{ states('sensor.furnace_temp') |int }} > {{states('input_number.test_min_temp') | int }} %}
          "{{ states('sensor.furnace_temp') }}"
          {% else %}
          "{{ states('input_number.test_min_temp') | int }}"
          {% endif %} 

Many thanks for any guidance . . .

Basically, it’s the double-quotes you used within the template that caused the problem. Within a multi-line template, anything between single or double quotes is treated as a string (i.e. is treated verbatim and there’s no attempt to interpret anything within the curly braces).

Here’s another way to write it that uses variables to help make the logic more legible.

        furnace_temp_min:
          friendly_name: Furnace Temp Min
          device_class: temperature
          unit_of_measurement: '°F '
          value_template: >
            {% set ft = states('sensor.furnace_temp') | int %}
            {% set tmt = states('input_number.test_min_temp') | int %}
            {% if ft > tmt %}
              ft
            {% else %}
              tmt
            {% endif %} 

Alternately, you streamline it by using an inline if statement.

        furnace_temp_min:
          friendly_name: Furnace Temp Min
          device_class: temperature
          unit_of_measurement: '°F '
          value_template: >
            {% set ft = states('sensor.furnace_temp') | int %}
            {% set tmt = states('input_number.test_min_temp') | int %}
            {{ ft if ft > tmt else tmt }}

Absolutely brilliant. Works like a charm.

You just answered a hundred template questions for me.

1 Like

Glad to hear it.

Please consider marking my post (above) with the Solution tag. It will automatically add a check-mark to the topic’s title which signals to other users that this topic has an accepted solution. This help users find answers to similar questions.