Markdown - output of the sensor icon

Hello,
I have a new questen and I don´t find the right code.

I display the sensor if the on with the following code:
{% if is_state('binary_sensor.homematicip_fenster_2', 'on') %} ## Fenster OG Wohnzimmer ist {{ states('binary_sensor.homematicip_fenster_2') | replace("on", "offen") }}{% else %}{% endif %}

Now I would like to add in front of ## Fenster OG Wohnzimmer ist the sensor icon

I have try it with this code:
{% if is_state('binary_sensor.homematicip_fenster_2', 'on') %} <ha-icon icon="mdi:{{ states('binary_sensor.homematicip_fenster_2'') }}"/> ## Fenster OG Wohnzimmer ist {{ states('binary_sensor.homematicip_fenster_2') | replace("on", "offen") }}{% else %}{% endif %}

But with this code, I don´t get an output.

I try to sear here, but I don´t find the solution.

Can me tell anyone how must I change the code?

What icon are you trying to display ?

From what i read in your code you’re trying to display “mdi:off” or “mdi:on” which are not existing, so not displayed…

I think you overthink it :slight_smile:

My german lessons are far away now Fenster is window right ?

You could probably try something like :

{% if is_state('binary_sensor.homematicip_fenster_2', 'on') %}  
<ha-icon icon="mdi:window-open"></ha-icon>The window is opened !
{% else %}
{% endif %}

but this will render an empty markdown card when window is closed…you can avoid this by using a conditional card and get rid of templating things !

type: conditional
conditions:
  - entity: binary_sensor.homematicip_fenster_2
    state: 'on'
card:
  type: markdown
  content: |
    <ha-icon icon="mdi:window-open"></ha-icon>The window is opened !

Edit : using your entity in examples

Yes you are right, fenster is window.

Its ok, that me code make an empty markdown card. Because in this markdown card are many sensors. So it is never empty.

I would like to display the “standard” icon from the sensor. The same Icon witch are display when I take the element card.

I need this icon, because I have some sensors with lights and the “standard” icon are automaticly in the right color from the light.

One more thing. If I take this Code:

{% if is_state('binary_sensor.homematicip_fenster_und_turkontakt_mit_magnet', 'on') %} <ha-icon icon="mdi:window-open-variant"></ha-icon> ## Fenster EG Schlafzimmer ist offen{% else %}{% endif %}
the ## not uses. I don´t geht the greater letters by the Text Fenster EG Schlafzimmer ist offen

With the ## normally the text are display so:

With the code from above the text are display so:
Bildschirmfoto 2021-08-18 um 21.59.11

I hope you can understand what I want.

I understand, it seems that displaying an icon screw up the markdown in the same

To display the icon of an entity, I think the solution is to get it from the attributes of the entity. If it’s in…

I think this is not the right solution.

I’ll try to describe it again

In the elementscart is the output of the light like this:
Bildschirmfoto 2021-08-19 um 18.12.56
And the Icon color is the same as the light and changes the color to the same like the light in real.

If I now output the icon from the attributes, I think the color change is not possible.

Maybe Im not true, but I don´t find the code to get the icon from the attributes of the sensor to try ist out.

But no matter how, if I output the icon before the text is output (no matter how), the formatting with ## is no longer output but only the two ## themselves

I would linke to output linke this (in bigger letters):

If I try this code:

{% if is_state('light.mondo_wand', 'on') %} 
<ha-icon icon=hue:lightstrip></ha-icon> ## OG Wohnzimmer Mondo Wand Strips an {% else %}{% endif %}

The output is this (I have correct no now line, but the bigger letters absence):
Bildschirmfoto 2021-08-19 um 18.40.59

If I try this code:

{% if is_state('light.mondo_wand', 'on') %} 
<ha-icon icon=hue:lightstrip></ha-icon>
## OG Wohnzimmer Mondo Wand Strips an {% else %}{% endif %}

The output is this (the bigger letts are right but I have the new line):

So I have two problems:

  1. How can I output the icon of the sensor, which automatically adapts the color
  2. How can I output the icon and behind in bigger letters my text

I hope someone have an idea.

Do :
## <ha-icon icon="mdi:whatever"></ha-icon> The window is opened
image

Now about getting the color…if it’s a light you should have the color in the attributes and you can probably achieve this with card mod !

Thanks this works. With the color I must try something

Keep us posted if you manage this ! Could be helpful for others !
I’ll do some tests on my side when kids/wife/dog will let me time :smile:

content: |
  <font color="{{ '#%02x%02x%02x' % state_attr('light.bedroom', 'rgb_color') }}"> <ha-icon icon="mdi:bus"></ha-icon></font>
4 Likes

That’s pretty !

Perfekt, this is this what I search. Thanks a lot.