HVAC_modes template return ever same value

Good morning,
why this code always returns the same value to me ‘Automatic’
Where am I wrong?
Thanks, Alberto

Cattura

# usato in floorplan
  - platform: template
    sensors:
      hvacmode_p1:
        friendly_name: Modo riscaldamento p1
        value_template: >-
          {% if is_state_attr('climate.house_thermostat_1', 'hvac_modes', 'off') %}
            Spento
          {% if is_state_attr('climate.house_thermostat_1', 'hvac_modes', 'heat') %}
            Manuale
          {% if is_state_attr('climate.house_thermostat_1', 'hvac_modes', 'auto') %}
            Automatico
          {% endif %}

because you have an invalid template. each if statement needs an endif. If you want to check all 3, then you need to use elif (else if).

          {% if is_state_attr('climate.house_thermostat_1', 'hvac_modes', 'off') %}
            Spento
          {% elif is_state_attr('climate.house_thermostat_1', 'hvac_modes', 'heat') %}
            Manuale
          {% elif is_state_attr('climate.house_thermostat_1', 'hvac_modes', 'auto') %}
            Automatico
          {% endif %}

Two things:

  1. What petro said, the template is invalid.
  2. It is using the wrong attribute.

The attribute hvac_modes is a list of the entity’s possible states. In this example, climate.thermostat has four possible states:

Therefore this template will never report true:

is_state_attr('climate.house_thermostat_1', 'hvac_modes', 'off')

What you want is to check the entity’s state. For example, this template checks if the entity’s current state is heat:

# usato in floorplan
  - platform: template
    sensors:
      hvacmode_p1:
        friendly_name: Modo riscaldamento p1
        value_template: >-
          {% if is_state('climate.house_thermostat_1', 'off') %}
            Spento
          {% elif is_state('climate.house_thermostat_1', 'heat') %}
            Manuale
          {% else %}
            Automatico
          {% endif %}

use @123’s solution.

Grazie 123 !!
Funziona :smiley:

1 Like