alverman
(Alberto)
1
Good morning,
why this code always returns the same value to me ‘Automatic’
Where am I wrong?
Thanks, Alberto
# 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 %}
petro
(Petro)
2
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 %}
123
(Taras)
3
Two things:
- What petro said, the template is invalid.
- 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 %}