Can't have markdown card formatting my table

Hello,
Using HA 2024.2.5.
I have a simple table to be formatted. I went through multiple articles markdown-related. But without success : the table remains unformatted.
So I turn to the community for some help.

The code is here :

type: markdown
entity: sensor.arrosage_history_check
title: Dernières programmations d'arrosage
content: >
  |Time of run|Comment| |---|---| {% set myList =
  states.sensor.arrosage_history_check.attributes.history %}

  {% for each in myList %} |{each.timestamp}}|{{each.Param}}|   {% endfor %}

Thanks, B.

I think the issue is whitespaces from the loop… try the following:

type: markdown
entity: sensor.arrosage_history_check
title: Dernières programmations d'arrosage
content: >
  {% set myList = states.sensor.arrosage_history_check.attributes.history %}
  |Time of run|Comment|
  |---|---|
  {%- for each in myList %} 
  |{each.timestamp}}|{{each.Param}}|
  {%- endfor %}

Thanks, but doesn’t improve the result…

Try based on this:

content: |
  {% set myList = states.zone -%}
  Time of run|Comment
  ---|---
  {% for each in myList -%}
  {{each.entity_id}}|{{each.name}}
  {% endfor %}

Just replace with your list & element’s members.

You were close, just some small issues.

This one works and may be a place to start.

      - type: markdown
        content: >
          Domain | Count 
            :---|---:
          {% for d in states | groupby('domain') %} {{ d[0].replace('_', ' ') |
          title }} | {{ states[d[0]] | count  }}

          {% endfor %}
        title: Domain Counts

This one works :

It works by adding a ‘-’ just after ‘{%’ …
Can someone explain this ?

Thanks,

W/o that “-” it is same as

content: |
  {% set myList = states.zone -%}
  Time of run|Comment
  ---|---

  {% for each in myList -%}
  {{each.entity_id}}|{{each.name}}
  {% endfor %}

i.e. adds an extra line - which breaks the formatting.
I would suggest to use MY variant -

  ---|---
  {% for each in myList -%}

i.e with “-” in another place, it does same but more logical.

Also, no need to use “outer |” as you do - check this:

And to your formatting problem, then you are missing a { in front of each.timestamp.
You could also use an HTML table in the markdown card.

type: markdown
entity: sensor.arrosage_history_check
title: Dernières programmations d'arrosage
content: >
  <table width=100% border=1>
  <tr><td align=right>Time of run</td><td align=right>Comment</td></tr>
  {% set myList = states.sensor.arrosage_history_check.attributes.history %}
  {% for each in myList %} 
    <tr><td align=left>{{each.timestamp}}</td><td align=right>{{each.Param}}</td></tr>
  {% endfor %}
  </table>

Great support from the community !!
Big thanks.

I’m trying to follow this guide, but with somehow limited success…
So, I have an input_text helper, that holds set of information about incoming events. It is a bit overdone automation that pulls this info from several calendars, so if needed I can somehow change the output format. Unformatted string with necessary information look like that:

<font color="#3BCC64"> Wed, Apr 24: Glass </font><br><font color="#57A0FF"> Fri, Apr 26: Paper </font><br><font color="#A252E3"> Wed, May 1: Labor Day / May Day </font><br><font color="#A252E3"> Thu, May 2: Day of the Flag </font>

It contains addditional info about formatting, so it can be used directly in markdown card. Output of such card look like:

Screenshot 2024-04-21 at 17.05.30

Now I’d like to use discussed trick to make a bit nicer formatting of text in markdown, so that garbage activity or holiday name is properly tabulated. To achieve this I first changed all
tags in my sensor state to just * (so it can be used as list separator) and slightly changed color tags, so it spans properly across all cells of the table:

<font color="#3BCC64"> Wed, Apr 24</font>:<font color="#3BCC64"> Glass </font>*<font color="#57A0FF"> Fri, Apr 26</font>: <font color="#57A0FF"> Paper </font>*<font color="#A252E3"> Wed, May 1</font>: <font color="#A252E3">Labor Day / May Day </font>

and then created template to generate proper code for markdown:

{% set myList = states('input_text.events').split('*') %}
|Date|Event|
|---|---|
{%- for each in myList -%}
{% set myEvent = each.split(':') %}
|{{ myEvent[0]}}:|{{ myEvent[1] }}|
{%- endfor -%}

This template generates following output:

So it looks, like pretty good code to be used in markdown to create table. Unfortunately there is something wrong here… Preview shows what I expect, but I can’t save the card, there is endlesly spinning wheel instead of Save button

BTW, if I put template editor output as such directly into markdown card (instead of template) I get the same situation. So there is something wrong with generated code, but I can’t figure it out. Any hints, please?

EDIT: resoleved… seems that was some browser caching, or so. After just returning to this a bit later it works as expected. A bit finetuning and here is the final result:
Screenshot 2024-04-21 at 19.52.07