This is a YAML syntax, but I do think this should be addressed in the HA documentation somewhere.
Tried this…produced this:
Using this:
- title: Markdown
cards:
- type: markdown
title: Batch System
content: |
{{now().hour}}
Could someone post a lovelace config snippet they have which is working possibly?
Cheers!
When I said “Just now tested this:”
I posted an incorrect example of what I actually tested in the template editor…I actually tested:
The Batch Auto/Pause Status is
{% if is_state('binary_sensor.batch_auto_pause_status', 'on') %} ON
{% else %} OFF
{% endif %}
That executes in the template editor.
However the config for the Markdown Card does not execute at all. It merely prints a string.
Can I ask has anyone in the community actually executed template variables in a markdown card?
Could you post an example of your successful config snippet please?
Cheers?
So the big question is:
can variables / template syntax, be used in a Lovelace card??
Sure for cards that support it. e.g. the markdown card discussed above does:
content
(string)(Required)
Content to render as markdown. May contain templates.
For cards that don’t support templating there’s this:
@tom_l Thanks for posting. Is it possible for you to post a snippet that you know works for my reference please?
using the markdown card?
There are many examples in the link I posted.
EDIT: also a recent solution using it:
Yes I have tried quite a few of those examples but just to have another test I used.
- type: markdown
title: Template Example
content: >
Sensor States
Test template value example which does not execute however?
{% for state in states.sensor %}
{{ state.entity_id }}={{ state.state }},
{% endfor %}
As I expected (as I have tried this particular example and many others before) that produces this (using the markdown card):
I believe the Markdown Card may not actually support templates on the current configuration I am using?
Home Assistant
0.94.0
Installed on QNAP NAS using container station.
Working for me on Hassio NUC image v0.99.3:
It does weird things depending on the number of spaces in the padding.
Try this:
type: markdown
content: >
{% for state in states.sensor %}
{{ state.entity_id }}={{ state.state }},
{% endfor %}
title: Test
Hmmm… @tom_l I suspected this has to do with the configuration I am using.
Cheers for confirmation!
It seems I might need to make the move to a later version.
I will do that and post again what I find. May be a day or so as I have a bit on atm.
See my edit above. Depending on the padding strange things happen (different font, or not working at all).
Are you using Lovelace UI or yaml mode?
@tom_l I had someone else say that sort of thing above so I tested your example.
- type: markdown
content: >
{% for state in states.sensor %}
{{ state.entity_id }}={{ state.state }},
{% endfor %}
title: Test
which unfortunately produced this:
I use yaml mode…
Try incrementing the number of spaces. Also the middle line of your template should be 2 spaces more than the other two.
Also try this:
type: markdown
content: |2-
{% for state in states.sensor %}
{{ state.entity_id }}={{ state.state }},
{% endfor %}
title: Test
The middle part is 2 spaces but when it prints the string it does not display that way. How many spaces should I try do you think?
Haha…do these messages ever annoy you as much as they annoy me? (Pops up as I type this to reply to you)
Encourage everyone to get involved in the conversation
You’ve replied 3 times to @tom_l in this particular topic!
A great discussion involves many voices and perspectives. Can you get anybody else involved?
And don’t forget, if you’d like to continue your conversation with this particular user at length outside of public view, send them a personal message.
Yeah I figured that after I wrote it.
Yeah I just ignore those messages.
Did you try:
type: markdown
content: |2-
{% for state in states.sensor %}
{{ state.entity_id }}={{ state.state }},
{% endfor %}
title: Test
It’s what the UI editor generates.
Haha…I try but…its hard!
Tried this…
- type: markdown
content: |2-
{% for state in states.sensor %}
{{ state.entity_id }}={{ state.state }},
{% endfor %}
title: Test
No change.
What does the
do?
I have no idea.
Yes…thats the point I reached…pretty convinced its a problem with my installation config. Others can get it to work…just not me.
@tom_l An update…recently updated to 0.101.3 and just revisited the Markdown issue I was having…
I can now confirm with nothing (of consequence…some text yes) changed in my config and retest the same Markdown Card:
- title: Makdown
cards:
- type: markdown
title: Template Example
content: >
## Sensor States
Test template value example which does not execute in HA 0.94.0
Now using HA 0.101.3....
{% for state in states.sensor %}
{{ state.entity_id }}={{ state.state }},
{% endfor %}
Cheers to all who assisted me with this issue!
I am calling this solved with the issue being a problem in HA 0.94.0