hass-template-climate icon indicating copy to clipboard operation
hass-template-climate copied to clipboard

Template loop detected while rendering hvac_action_template

Open sbasmanov opened this issue 1 year ago • 0 comments

The problem

I'm setting up IR controlled air conditioner, so I wanted to emulate hvac_action depending on mode and temperature. It works for a while, but when I start changing modes and temperature it stops updating, posting warning in log. After first warning it never updates hvac_ation until restart. On next changes of state/temperature it logs same warning. I'm not sure, but it seems that issue is triggering when accessing climate entity state inside template rendering. May be there is better way to get current hvac_mode and temperature ?

What version of Template Climate has the issue?

just cloned from git 28.03.2023

What version of Home Assistant are you running?

2023.4.0.dev20230328

What type of installation are you running?

Home Assistant Container

Example YAML snippet

Configuration:
climate:
  - platform: climate_template
    unique_id: kitchen_climate
    name: kitchen_climate
    current_temperature_template: "{{ states('sensor.living_room_bme280_temperature') }}"
    current_humidity_template: "{{ states('sensor.living_room_bme280_humidity') }}"
    hvac_action_template: >-
      {% set target_temp = state_attr('climate.kitchen_climate','temperature') | int %}
      {% set current_temp = states('sensor.living_room_bme280_temperature') | int %}
      {% set hvac_mode = states('climate.kitchen_climate') %}
      {% if hvac_mode == 'auto' and target_temp > current_temp %}
        heating
      {% elif hvac_mode == 'auto' and target_temp < current_temp %}
        cooling
      {% elif hvac_mode == 'auto' %}
        idle
      {% elif hvac_mode == 'heat' and target_temp > current_temp %} 
        heating
      {% elif hvac_mode == 'heat' %}
        idle
      {% elif hvac_mode == 'cool' and target_temp < current_temp %} 
        cooling
      {% elif hvac_mode == 'cool' %}
        idle
      {% elif hvac_mode == 'dry' %}
        drying
      {% elif hvac_mode == 'fan_only' %}
        fan
      {% else %} 
        off
      {% endif %}

Anything in the logs that might be useful for us?

Message in log:
WARNING (MainThread) [homeassistant.helpers.template_entity] Template loop detected while processing event: <Event state_changed[L]: entity_id=climate.kitchen_climate, old_state=<state climate.kitchen_climate=heat; hvac_modes=['auto', 'cool', 'heat', 'dry', 'fan_only', 'off'], min_temp=16.0, max_temp=30.0, target_temp_step=1.0, fan_modes=['auto', 'low', 'medium', 'high'], current_temperature=26.9, temperature=25.0, current_humidity=23.0, fan_mode=high, hvac_action=idle, friendly_name=kitchen_climate, supported_features=ClimateEntityFeature.FAN_MODE|TARGET_TEMPERATURE @ 2023-03-28T12:42:27.939280+03:00>, new_state=<state climate.kitchen_climate=heat; hvac_modes=['auto', 'cool', 'heat', 'dry', 'fan_only', 'off'], min_temp=16.0, max_temp=30.0, target_temp_step=1.0, fan_modes=['auto', 'low', 'medium', 'high'], current_temperature=26.9, temperature=27.0, current_humidity=23.0, fan_mode=high, hvac_action=idle, friendly_name=kitchen_climate, supported_features=ClimateEntityFeature.FAN_MODE|TARGET_TEMPERATURE @ 2023-03-28T12:42:27.939280+03:00>>, skipping template render for Template[...]

where [...] is copy of template from configuration.

Additional information

No response

sbasmanov avatar Mar 28 '23 10:03 sbasmanov