Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template loop detected #14

Open
hauseroliver opened this issue Dec 28, 2023 · 4 comments
Open

Template loop detected #14

hauseroliver opened this issue Dec 28, 2023 · 4 comments

Comments

@hauseroliver
Copy link

Thanks for the great work! Your configuration works great, but sometimes i get the following error in HA logs:

2023-12-28 08:19:05.687 WARNING (MainThread) [homeassistant.components.template.template_entity] Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.e3dc_battery_charge_power, old_state=<state sensor.e3dc_battery_charge_power=39.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2023-12-28T08:19:05.598125+01:00>, new_state=<state sensor.e3dc_battery_charge_power=36.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2023-12-28T08:19:05.608402+01:00>>, skipping template render for Template[{% set power = states('sensor.e3dc_battery_power') | float(0) %} {% if power >= 0 %}
{{ power }}
{% else %}
{% set charge_power = states('sensor.e3dc_battery_charge_power') | float(0) + power %}
{{ charge_power if charge_power > 0 else 0 }}
{% endif %}]

Any idea?

@MrIceman11
Copy link
Owner

Hello!

Thanks for the report!

Yes, I have an idea. Please replace the following in the sensors.yaml. But make sure that the indentations are correct. Would be nice if you could give me some feedback.

      e3dc_battery_charge_power:
         unique_id: e3dc_battery_charge_power
         friendly_name: E3DC Battery Charging Power
         unit_of_measurement: W
         device_class: power
         value_template: >
           {% set power = states('sensor.e3dc_battery_power') | float(0) %}
           {% if power >= 0 %}
             {{ power }}
           {% else %}
             {% set charge_power = states('sensor.e3dc_battery_charge_power') | float(0) %}
             {% if charge_power + power > 0 %}
               {{ charge_power + power }}
             {% else %}
               0
             {% endif %}
           {% endif %}

Please do not forget to reload the config.

@hauseroliver
Copy link
Author

Hi,
thanks for your help!
I changed the code yesterday and restartet HASS.
Today i got even more error messages:

Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:412
Integration: Template (documentation, issues)
First occurred: 09:01:03 (23 occurrences)
Last logged: 12:37:06

Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.e3dc_battery_charge_power, old_state=<state sensor.e3dc_battery_charge_power=1107.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2023-12-31T11:08:49.955934+01:00>, new_state=<state sensor.e3dc_battery_charge_power=1011.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2023-12-31T11:08:49.958292+01:00>>, skipping template render for Template[{% set power = states('sensor.e3dc_battery_power') | float(0) %} {% if power >= 0 %} {{ power }} {% else %} {% set charge_power = states('sensor.e3dc_battery_charge_power') | float(0) %} {% if charge_power + power > 0 %} {{ charge_power + power }} {% else %} 0 {% endif %} {% endif %}]
Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.e3dc_battery_charge_power, old_state=<state sensor.e3dc_battery_charge_power=1656.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2023-12-31T11:09:29.967116+01:00>, new_state=<state sensor.e3dc_battery_charge_power=1644.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2023-12-31T11:09:29.969746+01:00>>, skipping template render for Template[{% set power = states('sensor.e3dc_battery_power') | float(0) %} {% if power >= 0 %} {{ power }} {% else %} {% set charge_power = states('sensor.e3dc_battery_charge_power') | float(0) %} {% if charge_power + power > 0 %} {{ charge_power + power }} {% else %} 0 {% endif %} {% endif %}]
Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.e3dc_battery_charge_power, old_state=<state sensor.e3dc_battery_charge_power=2550.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2023-12-31T12:33:40.979210+01:00>, new_state=<state sensor.e3dc_battery_charge_power=2379.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2023-12-31T12:33:40.982206+01:00>>, skipping template render for Template[{% set power = states('sensor.e3dc_battery_power') | float(0) %} {% if power >= 0 %} {{ power }} {% else %} {% set charge_power = states('sensor.e3dc_battery_charge_power') | float(0) %} {% if charge_power + power > 0 %} {{ charge_power + power }} {% else %} 0 {% endif %} {% endif %}]
Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.e3dc_battery_charge_power, old_state=<state sensor.e3dc_battery_charge_power=2688.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2023-12-31T12:35:15.996274+01:00>, new_state=<state sensor.e3dc_battery_charge_power=2655.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2023-12-31T12:35:16.000575+01:00>>, skipping template render for Template[{% set power = states('sensor.e3dc_battery_power') | float(0) %} {% if power >= 0 %} {{ power }} {% else %} {% set charge_power = states('sensor.e3dc_battery_charge_power') | float(0) %} {% if charge_power + power > 0 %} {{ charge_power + power }} {% else %} 0 {% endif %} {% endif %}]
Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.e3dc_battery_charge_power, old_state=<state sensor.e3dc_battery_charge_power=111.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2023-12-31T12:37:06.014497+01:00>, new_state=<state sensor.e3dc_battery_charge_power=66.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2023-12-31T12:37:06.016818+01:00>>, skipping template render for Template[{% set power = states('sensor.e3dc_battery_power') | float(0) %} {% if power >= 0 %} {{ power }} {% else %} {% set charge_power = states('sensor.e3dc_battery_charge_power') | float(0) %} {% if charge_power + power > 0 %} {{ charge_power + power }} {% else %} 0 {% endif %} {% endif %}]

@MrIceman11
Copy link
Owner

Ok Sorry,

try this:

        e3dc_battery_charge_power:
          unique_id: e3dc_battery_charge_power
          friendly_name: E3DC Battery Charging Power
          unit_of_measurement: W
          device_class: power
          value_template: >
            {% set power = states('sensor.e3dc_battery_power') | float(0) %}
            {% set charge_power = states('sensor.e3dc_battery_charge_power') | float(0) %}
            
            {% if power >= 0 %}
              {{ power }}
            {% else %}
              {% set total_power = charge_power + power %}
              {{ total_power if total_power > 0 else 0 }}
            {% endif %}

@hauseroliver
Copy link
Author

Thank you, tried it but again:

Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:412
Integration: Template (documentation, issues)
First occurred: 09:31:21 (14 occurrences)
Last logged: 15:40:02

Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.e3dc_battery_charge_power, old_state=<state sensor.e3dc_battery_charge_power=438.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2024-01-03T14:43:05.708230+01:00>, new_state=<state sensor.e3dc_battery_charge_power=330.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2024-01-03T14:43:05.713051+01:00>>, skipping template render for Template[{% set power = states('sensor.e3dc_battery_power') | float(0) %} {% set charge_power = states('sensor.e3dc_battery_charge_power') | float(0) %} {% if power >= 0 %} {{ power }} {% else %} {% set total_power = charge_power + power %} {{ total_power if total_power > 0 else 0 }} {% endif %}]
Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.e3dc_battery_charge_power, old_state=<state sensor.e3dc_battery_charge_power=177.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2024-01-03T14:43:10.710567+01:00>, new_state=<state sensor.e3dc_battery_charge_power=24.0; unit_of_measurement=W, device_class=power, friendly_name=E3DC Battery Charging Power @ 2024-01-03T14:43:10.715554+01:00>>, skipping template render for Template[{% set power = states('sensor.e3dc_battery_power') | float(0) %} {% set charge_power = states('sensor.e3dc_battery_charge_power') | float(0) %} {% if power >= 0 %} {{ power }} {% else %} {% set total_power = charge_power + power %} {{ total_power if total_power > 0 else 0 }} {% endif %}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants