How to map state to correct type (|float)

ok, getting closer:

{% set threshold = states('input_number.power_threshold')|float %}
{% for s in states.sensor
 |selectattr('entity_id', 'search', '_actueel')
 if s.state|float > threshold %}
{{s.entity_id}}
{% endfor %}

fear I need another namespace template though, because above wont render a correct list. right, finally I made it…

        filter:
          template: >
            {% set threshold = states('input_number.power_threshold')|float %}
            {% set ns = namespace(above_threshold=[]) %}
            {% for s in states.sensor
             |selectattr('entity_id', 'search', '_actueel')
             if s.state|float > threshold %}
            {% set ns.above_threshold = ns.above_threshold + [s.entity_id] %}
            {% endfor %}
            {{ns.above_threshold}}
1 Like