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
trigger:
- platform: time
at: "00:00:01"
enabled: true
action:
- service: input_text.set_value
target:
entity_id: input_text.events
data:
value: >-
{{ '' }}
- repeat:
sequence:
- service: calendar.get_events
target:
entity_id:
- calendar.ecoharmonogram
data:
start_date_time: >
{{ strptime(states('sensor.date'), '%Y-%m-%d') + timedelta(days=repeat.index-1) }}
duration:
hours: 23
response_variable: incoming
- service: input_text.set_value
target:
entity_id: input_text.events
data:
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 %}
until:
- 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:
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:
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
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
What might be wrong here? Any suggestions how to get this fixed?