Unresolved template/markdown mystery :-O

Never before I was so puzzled as this time…
I have automation that reads data from iCalendar created by Waste Collection Schedule integration into input_text helper, in specific format. Here is the code of this automation:

  - alias: Get Calendars
    id: get_calendars
      - platform: time
        at: "00:00:01"
        enabled: true
      - service: input_text.set_value
          entity_id: input_text.events
          value: >-
            {{ '' }}
      - repeat:
            - service: calendar.get_events
                  - calendar.ecoharmonogram
                start_date_time: >
                  {{ strptime(states('sensor.date'), '%Y-%m-%d') + timedelta(days=repeat.index-1) }}
                  hours: 23
              response_variable: incoming
            - service: input_text.set_value
                entity_id: input_text.events
                value: >-
                  {{ states('input_text.events') }}
                  {% for event in incoming["calendar.ecoharmonogram"]["events"] %}
                    {% if event.summary == 'METALE I TWORZYWA SZTUCZNE' %} <font color="#FFDB1A">:{{ as_timestamp(event.start) | timestamp_custom('%a, %b %-d') }}:Plastic*
                    {% elif event.summary == 'BIO' %} <font color="#AB6D09">:{{ as_timestamp(event.start) | timestamp_custom('%a, %b %-d') }}:Bio* 
                    {% elif event.summary == 'ODPADY ZMIESZANE' %}<font color="#888888">:{{ as_timestamp(event.start) | timestamp_custom('%a, %b %-d') }}:Mixed* 
                    {% elif event.summary == 'PAPIER' %} <font color="#57A0FF">:{{ as_timestamp(event.start) | timestamp_custom('%a, %b %-d') }}:Paper*
                    {% elif event.summary == 'SZKŁO' %} <font color="#3BCC64">:{{ as_timestamp(event.start) | timestamp_custom('%a, %b %-d') }}:Glass* 
                    {% endif %}
                  {% endfor %}

            - condition: template
              value_template: >
                {{ repeat.index >=13 }}

    mode: single

This automation reads all events for 13 consecutive days and based on response fills helper with text formatted into list of events in specific format [color, event_date, event_type]. I use ‘*’ to separate events and’:’ to separate fields in record. It works as intended, below is sample output I get in helper, as it is expected:

<font color="#FFDB1A">:Fri, May 10:Plastic* <font color="#AB6D09">:Wed, May 15:Bio* <font color="#888888">:Fri, May 17:Mixed*

Before I started to use this integration I used several separate calendars on Synology NAS and used slightly modified automation (but with exactly same principles) to create the same output. And here mistery comes. Previously , with EXACTLY te same output stored in helper and the same card I use to display this calendar was working perfectly fine:
Screenshot 2024-05-07 at 14.34.12
Now the with the same data in helper, outcome is different, looks like markdown card is not able to recognize properly table it should display. Only very first line is diplayed properly, for second and following both date and event type are going to the first column of table:
Screenshot 2024-05-07 at 14.33.53

Here is code I use for this card (just markdown/template part):

              - type: markdown
                content: >
                  {% set myList = (states('input_text.events') | trim('*')).split('*') %}



                  {%- for each in myList -%}

                  {% set myEvent = each.split(':') %}

                  |{{ myEvent[0]}}{{ myEvent[1] }}:</font>|{{ myEvent[0] }}{{ myEvent[2]}}</font>|

                  {%- endfor -%}

More over, if I go to Developer Tools → States and select helper, it is enough to click the Set State button, without any modifications in value, to get it to working state (e.g. so that card properly displays data in the table :open_mouth:

It is very consistent, repeatable behavior. I suspected some characters to use wrong codes (though looking the same), so I manaully went through whole code retyping any characters that might make differense (field and record separators), but no success… I tried to compare old and new output in text editor, but these looks exactly the same. More over, after copying helper value to Text.app (I use Mac) and then copying it back to HA display gets back to normal (same as above Set State button). In desperation I tried to add at the end of automation action that set the state of helper to its current value… but obviously this makes no difference :man_facepalming:
What might be wrong here? Any suggestions how to get this fixed?

Have you tried checking the HTML code of the page via BrowserTools (F12)? Are there any errors listed in the console, and/or is the markdown table correct?

And what comes to mind as well, are whitespaces. Markdown isn’t very forgiving, especially not the tables. And Jinja sometimes kinda messes with these.
You could work against that, if you use the “-” (dash) after the “{” for the other lines as well. Hard to explain, just look here and experiment with the different possibilities:


If this pulls up nothing, you might want to step back a little and start with very basic things, like removing the font/color, and see if it works without. In other words, do the tedious debug job… :laughing:

Good luck and let us know, how things work out for you. :slight_smile:

Well, got it working, but for sake of gods, I can’t figure out the difference…
I started from working automation for old Synology calendars, and was adding to new config code single line by one at the time… ending EXACTLY with the code I posted earlier… but this time working as expected. It has to be some strange/hidden character smuggled somehere in the code that changed how it works.

BTW, I was wrong with assumption that just clicking on the Set State button fixed issues! It was just browser cache, that kept updated content (that indeed looked the same) in the State field and applied it every time I was clicking the button, even after several changes of the page and invoking this view again. Only when I closed the browser and started again this ‘hidden functionality’ stopped to work and only started again after pasting working value into the State field.

1 Like