having an issue in my auto-entities config I realized it might be the output of the template causing the trouble, and ask for your help to rewrite it in another format. Hence this separate thread.
Given the examples on template filter by Thomas (scroll all the way done there) I originally made:
{% 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 %}
this complains about the card needed either entities (which I believe the template above provides) or geo_location sources (which of course these are too…)
still, I’d like to give it a try and rewrite the above to this format
{%- 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}}
funny thing is I had this already:
earthquakes_near:
friendly_name: Quakes near
value_template: >
{% set km = states('input_number.quakes_near')|float %}
{% set location = states('input_select.quakes_near') %}
{% set ns = namespace(count=0) %}
{% for s in states.geo_location|selectattr('attributes.source','eq','usgs_earthquakes_feed')
if distance(s.entity_id,location) < km %}
{% set ns.count = ns.count + 1 %}
{% endfor %}
{{ns.count}}
attribute_templates:
raw_list: >
{% 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 %}
list: >
{% set km = states('input_number.quakes_near')|float %}
{% set location = states('input_select.quakes_near') %}
{% set ns = namespace(count=0) %}
{% for s in states.geo_location|selectattr('attributes.source','eq','usgs_earthquakes_feed')
if distance(s.entity_id,location) < km %}
{% set ns.count = ns.count + 1 %}
{% endfor %}
{% if ns.count == 0 %} No Quake to list within {{km|int}} km
{% else %}
Quakes near:
{% for s in states.geo_location|selectattr('attributes.source','eq','usgs_earthquakes_feed')
if distance(s.entity_id,location) < km %}
{{- s.name -}}: {{s.state|int}} km{{', \n' if not loop.last else ''}}
{% endfor %}
{% endif %}
but because the namespace() technique wasn’t necessary for the attributes templates to list the quakes, I thought I could use that same template in the auto-entities.
Must confess I don’t truly grasp why the list my earlier template creates doesn’t work in the auto-entities for Map, and this would. (can’t test it right now, because no quakes are happening thank goodness)