Displaying a variable number of entities on Lovelace

Dear All,
I am wondering how to display the data from a sensor that returns a variable number of data (as a list).

As an example, take the emscrss integration. It returns a number of earthquakes as a list:

earthquakes:
  - title: 'ML 2.6  DODECANESE ISLANDS, GREECE'
    magnitude: 2.6
    time: '2021-02-10T08:37:59+02:00'
    distance: 290
    link: 'https://www.emsc-csem.org/Earthquake/earthquake.php?id=947538'
  - title: 'ML 2.9  CRETE, GREECE'
    magnitude: 2.9
    time: '2021-02-10T08:35:26+02:00'
    distance: 313
    link: 'https://www.emsc-csem.org/Earthquake/earthquake.php?id=947537'
  - title: ML 2.6  NEAR THE COAST OF WESTERN TURKEY
    magnitude: 2.6
    time: '2021-02-10T07:45:57+02:00'
    distance: 235
    link: 'https://www.emsc-csem.org/Earthquake/earthquake.php?id=947526'
  - title: ML 3.3  IONIAN SEA
    magnitude: 3.3
    time: '2021-02-10T06:25:51+02:00'
    distance: 265
    link: 'https://www.emsc-csem.org/Earthquake/earthquake.php?id=947508'
  - title: ML 2.0  WESTERN TURKEY
    magnitude: 2
    time: '2021-02-10T05:27:50+02:00'
    distance: 301
    link: 'https://www.emsc-csem.org/Earthquake/earthquake.php?id=947525'
friendly_name: Earthquakes
icon: 'mdi:alert'

I can extract the contents of it using this template:

Earthquakes: 
{% for quake in state_attr('sensor.earthquakes','earthquakes') %}
{{ quake.time }} - {{ quake.title }} - {{ quake.magnitude }} - {{ quake.distance }} - {{ quake.link }}
{% endfor %}

However, I would like to create a separate UI element for each item in the list.

Which Lovelace element would you use to display the contents? Should I simply use an HTML page to do this? I’m sure a more civilized way exists!

Thanks for any pointers!

This one:

Awesome, exactly what I had in mind! Thanks, @tom_l!

1 Like

Hi! can you show code how you organized this card please?

I’m afraid I don’t have that any more, but this is how I have it at the moment (using a markdown card):

# Earthquakes
  - type: markdown
    title: Recent Earthquakes
    content: |
      {% if state_attr('sensor.earthquakes','earthquakes') | length > 0 -%}
        {% for quake in state_attr('sensor.earthquakes','earthquakes') %}
        {{ quake.magnitude }}: [{{ quake.title }}]({{ quake.link }}) {{ quake.distance }}km
        {{ quake.time.strftime("%b %d %X")}}
        {% endfor %}
      {% else %}
        No significant earthquakes ( > M4.0 ) have occured in the past 6 hours.
      {%- endif %}

Wow, nice, thank you!
You decided not to use list-card?

Yep, but I can’t rememer why… :slight_smile: