Seems kind of fundamental, but how do you simply display the result of a template?
Example: I just want to view the results? I know an entities card can do this but I’d like to use templates.
The only one I know is ‘markdown’
EDIT: but since you are filtering, I think you can also use the flex-table card
I saw that but can’t figure out how to add the template. It’s only good for fixed text.
I can give you an example that picks up a lot of sensors and creates a table out of them
type: markdown
content: |+
<table>
{% for x in (states.sensor
|rejectattr('entity_id', 'search', '_updated|test')
|rejectattr('entity_id', 'eq', 'unavailable')
|selectattr('attributes.device_class', 'defined')
|selectattr('entity_id', 'search', 'station')
|rejectattr('state', 'search', 'unavailable')
|sort(attribute='entity_id',reverse=true)) %}
<tr>
{% if x %}
{%- set name = x.name %}
{%- set state = x.state %}
{%- set time = x.last_changed.timestamp()|timestamp_custom('%H:%M:%S', true, now() ) %}
{%- set time2 = x.last_updated.timestamp()|timestamp_custom('%H:%M:%S', true, now() ) %}
<td>{{name}}</td><td>{{state}}</td><td>{{time}}</td><td>{{time2}}</td>
{% else %} ERROR
{% endif %}
</tr>
{% endfor %}
card_mod:
style:
.: |
ha-card ha-markdown {
padding:0px
}
ha-markdown $: |
h1 {
font-weight: normal;
font-size: 24px;
}
div {
background-color:rgb(100, 100, 100);
padding: 12px 12px;
color:white;
font-weight:normal;
font-size:1.2em;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
table{
border-collapse: collapse;
font-size: 0.9em;
font-family: Roboto;
width: auto;
outline: 0px solid #393c3d;
margin-top: 10px;
} caption {
text-align: center;
font-weight: bold;
font-size: 1.2em;
} td {
padding: 5px 5px 5px 5px;
text-align: left;
border-bottom: 0px solid #1c2020;
}
tr {
border-bottom: 0px solid #1c2020;
}
tr:nth-of-type(even) {
background-color: rgb(54, 54, 54, 0.3);
}
tr:last-of-type {
border-bottom: transparent;
}
mark {
background: lightgreen;
color: #222627;
border-radius: 5px;
padding: 5px;
}
span {
background: orange;
color: #222627;
border-radius: 5px;
padding: 5px;
}
span {
padding: 5px;
}
tr:nth-child(n+2) > td:nth-child(2) {
text-align: left;
}
btw…the part with card-mod I am not using here so you could skip that section
Thank you! I’m getting this error:
Configuration errors detected:
can not read a block mapping entry; a multiline key may not be an implicit key (9:1)
6 | |selectattr('attributes.device_c …
7 | {{name}}
8 | {% endfor %}
9 |
-----^
type: markdown
content: |+
<table>
{% for state in states.sensor
| selectattr('attributes.device_class','defined')
|selectattr('attributes.device_class','==','temperature') %}
<td>{{name}}</td>
{% endfor %}
The card is a bit sensitive at times…try to indent as per my example
And … leaving for the day… {{name}} does not work as it is not defined…
example on yours
type: markdown
content: |
<table>
<tr>
{% for state in states.sensor
| selectattr('attributes.device_class','defined')
|selectattr('attributes.device_class','==','temperature') %}
<td>{{state}}</td>
<tr>
{% endfor %}
Yes, thank you, formatting is important. No errors now but it prints nothing; developer tools shows my results but none in markdown:
type: markdown
content: >-
<table>
{% for state in states.sensor|selectattr('attributes.device_class','defined')
|selectattr('attributes.device_class','==','temperature') %}
<tr>
{{state.name}}
</tr>
{% endfor %}
title: test template
Wait I’m wrong-- you don’t see the results in the editor, only after you save it! I get results!
You are the man, thank you!