Template: TypeError: can only concatenate list (not "str") to list

thought I finally had it using this template for my auto-entities in a type: map

        filter:
          template: >
            {%- set ns = namespace(quakes_near=[]) %}
            {% set km = states('input_number.quakes_near')|float %}
            {% set location = states('input_select.quakes_near') %}
            {% for s in states.geo_location|selectattr('attributes.source','eq','usgs_earthquakes_feed')
                 if distance(s.entity_id,location) < km %}
                  {% set ns.quakes_near = ns.quakes_near + s.entity_id %}
            {% endfor %}
            {{ns.quakes_near}}

however, the maps shows, but without any quakes…

in template editor, this error shows: TypeError: can only concatenate list (not "str") to list

but my eyes don’t spot the error, so please have a look for me what is wrong?

this:

          {% set km = states('input_number.quakes_near')|float %}
          {% set location = states('input_select.quakes_near') %}
          {% for s in states.geo_location|selectattr('attributes.source','eq','usgs_earthquakes_feed')
             if distance(s.entity_id,location) < km %}
          {{- s.entity_id -}}{{',' if not loop.last else ''}}
          {% endfor %}

does show the correct entity, and it shows in Map too now, but I am not sure if this produces the correct and expected list, when more entities are to be displayed

EDIT
btw, yes it does

1 Like
{% set ns.quakes_near = ns.quakes_near + [s.entity_id] %}

perfect! thank you very much. I’ve been staring at this for so long now…

can confirm it to show the correct entities in the map too :wink:

great, now got 2 options for that.

1 Like