Text with template in lovelace

Tags: #<Tag:0x00007f73974d8868>

Easy question.
Is there any way I can write text with template in lovelace cards?

Example:
The temperature is {{ sensor.temp }}°C and the humidity is {{ sensor.hum }}%.
Will be:
The temperature is 25°C and the humidity is 20%.

Preferred within a entity card

1 Like

Place a markdown card inside the entities card as an hui row item. Markdown cards accept templates. You’ll need to look up the ‘under-the-hood’ name for the markdown card to add is as a row. It might be custom:hui-markdown-card or custom:hui-markdown.

I got this working as a markdown card:

type: markdown
content: >-
  The temperature is {{ states("sensor.temp") }}°C and the
  humidity is {{ states("sensor.hum") }}% 
title: Template dev

But I dont manage to get it in the entities card.
Can you give me an example of formating?

type: entities
title: Template dev
entities:
- type: custom:hui-markdown-card
  content: >-
    The temperature is {{ states("sensor.temp") }}°C and the
    humidity is {{ states("sensor.hum") }}% 

It works :slight_smile:

type: entities
title: Template dev
entities:
- entity: light.zigbee_soverom
- type: custom:hui-markdown-card
  content: >-
    The temperature is {{ states("sensor.zigbee_10_temperature") }}°C and the
    humidity is {{ states("sensor.zigbee_10_humidity") }}% 

image

Also, if you use card-mod, you can get rid of the shadows.

This?

thanks :slight_smile: I will try

Yep. Once installed your config for the card should be:

type: entities
title: Template dev
entities:
- entity: light.zigbee_soverom
- type: custom:hui-markdown-card
  style: |
    ha-card { 
      --paper-card-background-color: 'rgba(0, 0, 0, 0.0)';
      --ha-card-background: "rgba(0, 0, 0, 0.0)";
      --ha-card-box-shadow: 'none';
    }
  content: >-
    The temperature is {{ states("sensor.zigbee_10_temperature") }}°C and the
    humidity is {{ states("sensor.zigbee_10_humidity") }}% 

There were some changes in the frontend in Home Assistant 0.106 (see #4984 and especially #4984 (comment)) so the above does not work anymore without slight alteration:

- type: entities
  title: Template dev
  entities:
    - entity: light.zigbee_soverom
    - type: custom:hui-element
      card_type: markdown
      style: |
        ha-card { 
          --ha-card-box-shadow: 'none';
        }
        ha-markdown.no-header {
          padding-left: 1px;
          padding-right: 1px;
        }
      content: >-
        The temperature is {{ states("sensor.zigbee_10_temperature") }}°C and the
        humidity is {{ states("sensor.zigbee_10_humidity") }}% 

Edit: Fix some side-effects in previous example