I’m looking for help with creating a formatted Markdown card. I have tried searching the form (several similar questions since 2022 that are never answered by anyone) and four different AIs… I spent an hour trying them, nothing worked.
I simply want to set the column size so that no matter what the text is, the columns are always wide enough. they dont look good right now…
here’s the YAML, appreciate if someone has the knowledge to share please do. I’d like to learn by a real world example - thank you.
type: markdown
content: >-
{% set input_minutes = 1440 %}
{% set hours = (input_minutes // 60) %} {% set minutes = input_minutes % 60 %}
{% set display_time = '' %} {% if hours > 0 %}
{% set display_time = display_time ~ hours | int ~ ' hr' ~ ('s' if hours > 1 else '') %}
{% endif %} {% if minutes > 0 %}
{% set display_time = display_time ~ ' ' ~ minutes | int ~ ' min' %}
{% elif hours == 0 %}
{% set display_time = '0 min' %}
{% endif %}
{% set ns = namespace(sensor_name_time=[]) %}
{% for entity in states.binary_sensor %}
{% if 'binary_sensor.alarm_' in entity.entity_id %}
{% if ('door' in entity.name | lower or
(entity.attributes.device_class is defined and
entity.attributes.device_class == 'door')) %}
{% set name_without_door = entity.name
| replace(" Door", "")
| replace(" Sensor", "")
| replace("Door ", "")
| replace("Sensor ", "") %}
{% set time_diff = (now() - entity.last_changed).total_seconds() %}
{% set hours = (time_diff // 3600) | int %}
{% set minutes = ((time_diff % 3600) // 60) | int %}
{% set time_display = '' %}
{% if hours > 0 %}
{% set time_display = time_display ~ hours ~ ' hr' ~ ('s' if hours > 1 else '') %}
{% endif %}
{% if minutes > 0 %}
{% set time_display = time_display ~ ' ' ~ minutes ~ ' min' %}
{% elif hours == 0 %}
{% set time_display = '0 min' %}
{% endif %}
{% set ns.sensor_name_time = ns.sensor_name_time + [{
"name": name_without_door,
"time": time_display,
"state": entity.state,
"last_changed": entity.last_changed
}] %}
{% endif %}
{% endif %}
{% endfor %}
{% set myList = ns.sensor_name_time | sort(attribute='last_changed',
reverse=true) %}
{% if myList | count > 0 %}
## Door Activity
| | Last Change | |
|:-----------|------------------:|:----------:|
{%- for each in myList %}
| {% if each.state == 'on' %}<font color="yellow">{{ each.name }}</font>{% else %}{{ each.name }}{% endif %} | {% if each.state == 'on' %}<font color="yellow">{{ each.time }}</font>{% else %}{{ each.time }}{% endif %} | {% if each.state == 'on' %}<ha-icon icon="mdi:door-open" style="color: blue;"></ha-icon>{% endif %} |
{%- endfor %}
{% else %}
## <ha-icon icon="mdi:door-open"></ha-icon> Door Activity
No activity in the last {{ display_time }}
{% endif %}