M1ke
April 18, 2021, 5:15pm
1
Hey guys,
I’m trying to create a markdown table for a mealplan - unfortunately it’s only working almost perfectly.
Important to me is the following:
alignment (always the same gap between weekdays and meals)
hide the weekdays, where there is no meal planned (yet)
start the week on Tuesday
weekday in bold & meal normal
custom text, if no meals are set
I’ve recently came across a thread containing some info regarding markdown tables and came up with the following spaghetti code:
content: >-
|
:---|:---
{% if is_state('input_text.essen_dienstag', '') %}{% else %}
**Dienstag:** | {{
states.input_text.essen_dienstag.state }} {% endif %} {% if
is_state('input_text.essen_mittwoch', '') %}{% else %}
**Mittwoch:** | {{
states.input_text.essen_mittwoch.state }} {% endif %} {% if
is_state('input_text.essen_donnerstag', '') %}{% else %}
**Donnerstag:** | {{
states.input_text.essen_donnerstag.state }} {% endif %} {% if
is_state('input_text.essen_freitag', '') %}{% else %}
**Freitag:** | {{
states.input_text.essen_freitag.state }} {% endif %} {% if
is_state('input_text.essen_samstag', '') %}{% else %}
**Samstag:** | {{
states.input_text.essen_samstag.state }} {% endif %} {% if
is_state('input_text.essen_sonntag', '') %}{% else %}
**Sonntag:** | {{
states.input_text.essen_sonntag.state }} {% endif %} {% if
is_state('input_text.essen_montag', '') %}{% else %}
**Montag:** | {{
states.input_text.essen_montag.state }} {% endif %}
{% if is_state('input_text.essen_montag', '') and
is_state('input_text.essen_dienstag', '') and
is_state('input_text.essen_mittwoch', '') and
is_state('input_text.essen_donnerstag', '') and
is_state('input_text.essen_freitag', '') and
is_state('input_text.essen_samstag', '') and
is_state('input_text.essen_sonntag', '') %}
Essensplan erstellen! {% else %} {% endif %}
style:
.: |
ha-card {
background: {% if is_state('input_boolean.essen', 'on') %} #444444 {% endif %};
}
ha-markdown:
$: |
th {
display: none;
}
table {
border-spacing: 0px;
}
type: markdown
Here’s how it looks like, when everyday is set:
So far, so good… but when sunday is the first non-empty one, the table does not get recognized as such and looks like that:
I know this is very specific, but I hope someone might still be able to help out.
Thank you very much in advance!
M1ke
April 18, 2021, 11:38pm
2
Finally got it working - rewrote the whole thing. If anyone has a similar project, here’s the code:
content: >-
|
:---|:---
{% if states('input_text.essen_dienstag') != "" %} **Dienstag:**
|
{{states.input_text.essen_dienstag.state }}
{% endif %}{% if states('input_text.essen_mittwoch') != "" %}
**Mittwoch:** |
{{states.input_text.essen_mittwoch.state }}
{% endif %}{% if states('input_text.essen_donnerstag') != "" %}
**Donnerstag:** |
{{states.input_text.essen_donnerstag.state }}
{% endif %}{% if states('input_text.essen_freitag') != "" %}
**Freitag:** |
{{states.input_text.essen_freitag.state }}
{% endif %}{% if states('input_text.essen_samstag') != "" %}
**Samstag:** |
{{states.input_text.essen_samstag.state }}
{% endif %}{% if states('input_text.essen_sonntag') != "" %}
**Sonntag:** |
{{states.input_text.essen_sonntag.state }}
{% endif %}{% if states('input_text.essen_montag') != "" %}
**Montag:** |
{{states.input_text.essen_montag.state }} {% endif %}
{% if is_state('input_text.essen_montag', '') and
is_state('input_text.essen_dienstag', '') and
is_state('input_text.essen_mittwoch', '') and
is_state('input_text.essen_donnerstag', '') and
is_state('input_text.essen_freitag', '') and
is_state('input_text.essen_samstag', '') and
is_state('input_text.essen_sonntag', '') %} Essensplan erstellen! {% endif %}
style:
.: |
ha-card {
background: {% if is_state('input_boolean.essen', 'on') %} #444444 {% endif %};
}
ha-markdown:
$: |
th {
display: none;
}
table {
border-spacing: 0px;
}
type: markdown
I think, the important part is where to put the line breaks. Or else the unused line breaks accumulate too much and break the table.
123
(Taras)
April 19, 2021, 2:16am
3
If you want to add spacing between markdown table columns, you can simply use blank columns instead of repeated non-breaking spaces
etc. It’s much neater and easier to use. There’s an example of its use here:
Goal
Display a list (in the UI) of all automations, sorted by last_triggered in reverse-chronological order (i.e. the most recently triggered automation appears first). Each row should display the automation’s name and the elapsed time since it was triggered (showing days, hours, and minutes).
Previous Solution
In the past I used the Auto-Entities Card to easily achieve the goal. A minor drawback is that the appearance is a bit cluttered because each row also shows an automation icon and a to…
3 Likes
M1ke
April 19, 2021, 5:20pm
4
That’s a lot better indeed - thank you very much!
This used to work, but seems like since 2022.6, has this broken for anyone and no longer displays anything?
Has anyone found a solution for current HA versions
It’s been 2 years. What’s your specific issue?
1 Like