#Did I find an undocumented Markdown card feature...?

1 messages · Page 1 of 1 (latest)

sand raft
#

was experimenting a bit, and because of the use of anchors, I simply tried this, without knowing it is not documented or checking the docs:

notice the use of entity in the markdown, and its subsequent use in the content, and in the card_mod templates.
It works as hoped for, and then I checked the docs for Markdown which mentions entity_id as a list https://www.home-assistant.io/dashboards/markdown/#entity_id

          - type: horizontal-stack
            cards:
              - type: markdown
                entity: sensor.pollen_onkruid_concentratie
                <<: &md
                  card_mod:
                    style: |
                      ha-card {
                        background: rgb(128,193,177,0.8);
                        color:
                          {% set level = states(config.entity) %}
                          {% set color =
                            {'Laag':'green','Gemiddeld':'orange',
                             'Hoog':'darkorange','Zeer Hoog':'maroon'} %}
                          {% set level_color = color.get(level,'gray') %}
                          {{level_color}};
                        font-weight: 800;
                        text-align: center;
                      }
                  content: >
                    {{states(config.entity)}}
              - type: markdown
                entity: sensor.pollen_gras_concentratie
                <<: *md
              - type: markdown
                entity: sensor.pollen_bomen_concentratie
                <<: *md

just so you see this actually works:

Home Assistant

The Markdown card is used to render Markdown

knotty bramble
#

What about this surprises you, that config.entity resolves?

sand raft
#

no, that I can use:

type: markdown
entity: sensor.my_sensor

because that config option is not documented at all

knotty bramble
#

A special template variable - config is set up for the content of the card. It contains the configuration of the card.

#

I think you could have used literally any string in place of entity and it would work the same way

#

setting entity doesn't do anything, but config has the entire configuration in it, including extra made up variables

sand raft
#

well that is completely unclear tbh.... and config in that example uses the entities in the entities option of the entity-filter card?

#

and, it does work because how else would my 3 markdown cards in the OP get their own values, if not based on the entity I set there

knotty bramble
#

All I'm saying is that this would work as well. There's no special magic to entity, it's just a key that you made up.

              - type: markdown
                zzzzzz: sensor.pollen_onkruid_concentratie
                content: >
                  {{states(config.zzzzzz)}}
sand raft
#

changing the contents to```
content: >
{{states(config.entity)}}
{{state_attr(config.entity,'friendly_name')}}

sand raft
#

however, the fact we could also use zzzz is rather remarkable.

knotty bramble
#

I'm still not getting what you think is undocumented here

#

The documentation says that anything in the card config is available in the config object

#

so it seems documented to me

sand raft
#

but how can it be available, if it doesnt exist as a documented variable?

knotty bramble
#

I'm not sure what else to say about it.

sand raft
#

well, it could at least be correctly documented with a markdown example. currently the example config (the configuration of the card) is not from the markdown, but from an entity-filter config. the actual markdown config in that example holds nothing but content.

#

but I can indeed confirm that this also works

              - type: markdown
                pol: sensor.pollen_onkruid_concentratie
                <<: &md
                  card_mod:
                    style: |
                      ha-card {
                        background: rgb(128,193,177,0.8);
                        color:
                          {% set level = states(config.pol) %}
                          {% set color =
                            {'Laag':'green','Gemiddeld':'orange',
                             'Hoog':'darkorange','Zeer Hoog':'maroon'} %}
                          {% set level_color = color.get(level,'gray') %}
                          {{level_color}};
                        font-weight: 800;
                        text-align: center;
                      }
                  content: >
                    {{states(config.pol)}}
                    {{state_attr(config.pol,'friendly_name')}}