I set up a sensor to sum up the values of other sensors. Once running I get a lot of “template loop detected” messages. I thought I was doing things right by looping all sensors and then having a second if statement to eliminate the current one. But in reading the response by @123 on this thread I can see why I get that message: I’m still selecting ALL sensors in the condition and then filtering below it, the actual select is throwing the message.
So I understand that, and am trying to correct it by performing the filter directly in the selection itself but can’t seem to find the right syntax.
Here is the original syntax that throws the error (simplified by using Dev Tools):
{% for s in states.sensor | selectattr('attributes.device_class', 'equalto', 'power') | list %}
{% if int(s.state, 0) > 0 %}
{% if not 'current in use wattage' in s.name.lower() %}
{% if not 'current in use kilowatts' in s.name.lower() %}
... (code goes here)
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
And here is my start to trying to filter directly in the initial condition but it still returns the name of the “current in use wattage” sensor even though I think I’m filtering it out with the if statement (but obviously am not):
{% for s in states.sensor | selectattr('attributes.device_class', 'equalto', 'power') | list if s.name.lower not in ['current in use wattage', 'current in use kilowatts'] %}
{{ s.name }}
{% endfor %}
I know I just have the Jinja2 if statement improperly formatted, can someone give me an example of that which is properly formatted?
Thank you!