Good afternoon, I’m desperately trying to loop through binary_sensors and normal sensors at the same time. The goal is to display all my dead batteries. How can i achieve this? I’ve gotten so far… but unfortunately i don’t understand how to add two kinds of sensors in the “for” loop:
{% set result = namespace(low=[]) %}
{%- for state in states.binary_sensor if state.entity_id.endswith("_battery") -%}
{%- if state.state == "unavailable" -%}
{% set result.low = result.low + [ state.name ] %}
{%- endif -%}
e.g. this doesn’t work
for state in states.binary_sensor or state in states.sensor ....
Ofc, i can use a workaround like this, but it’s ugly
{% set result = namespace(low=[]) %}
{%- for state in states.binary_sensor if state.entity_id.endswith("_battery") -%}
{%- if state.state == "unavailable" -%}
{% set result.low = result.low + [ state.name ] %}
{%- endif -%}
{%- endfor -%}
{%- for state in states.sensor if state.entity_id.endswith("_battery") -%}
{%- if state.state == "unavailable" -%}
{% set result.low = result.low + [ state.name ] %}
{%- endif -%}
{%- endfor -%}
Thanks for your help!