Weblink is part of standard lovelace enities card.
Iāve used the weblink in an entities card before, but you need to use it as an option under the entities collection on the entities card, you canāt use it as a card in its own right.
I donāt think youāll be able to recreate your mockup with just the card-templater and entities cards.
I went another route and made a ācustom:html-template-cardā
Yes thats the one.
Super customizable
Hi,
Great card ! Iām trying to template the state of a CO2 sensor entity (unit of measurement is ppm). I want it to display āvery goodā, āgoodā, ānormalā and ābadā depending of the different values (state) of the sensor. I thought your card will be useful to do so BUT it will still display the unit of measurement next to the string (see the attached picture). Is there any way to get rid of it ?
My yaml :
- type: custom:card-templater
card:
type: entities
title: 'Bedroom'
show_header_toggle: false
entities:
- entity: sensor.netatmo_bedroom_co2
name: "Air quality"
entities:
- entity: sensor.netatmo_bedroom_co2
state_template: >-
{% if states('sensor.netatmo_bedroom_co2')|int >= 1000 %}
Bad
{% else %}
Good
{% endif %}
Also, is it possible to template the secondary_info of an entity ? That would be greatly useful.
Iāve just released a Beta version (0.0.6b1) which allows setting attributes as well as the state of the entity.
This can be used like this (without using a template):
type: 'custom:card-templater'
card:
...
entities:
- entity: sensor.my_sensor
state_template: >
{{ "One" if states.sensor.my_sensor.state == "1" else "Not One" }}
attributes:
unit_of_measurement: "Testing"
or like this (using a template):
type: 'custom:card-templater'
card:
...
entities:
- entity: sensor.my_sensor
state_template: >
{{ "One" if states.sensor.my_sensor.state == "1" else "Not One" }}
attributes:
unit_of_measurement_template: >
{{ states.sensor.my_sensor.state }}
Great addition, thank you so much !
Any chance to be able to icon_template ? I can see that I am able to define an icon using the without template method, but when tried to use icon_template with the template method, it didnāt workā¦ ?
edit. actually, it seems like the template method (I tried with unit_of_measurement_template) is not working ? Did I do something wrong?
edit-2. OK got it, we must add the state_template line in order to get the attributes working, right ? What if I only need to change the attributes and not the state ?
Iāve just deployed 0.0.6b2, which allows templaing attributes without the state.
Incidentally, you mentioned templating the icon. This can actually be templated without using using state templating at all. Just do it like this (using a temperature sensor as an example):
type: 'custom:card-templater'
card:
type: entities
entities:
- entity: sensor.bedroom_temperature
icon_template: |
{{ "mdi:" + "home" }}
entities:
- entity: sensor.bedroom_temperature
This is perfect ! Thank you Steven, you rock!
I have this beef with Home Assistant as a whole, but surely, there is not a reason why we can only have templates in attributes that end in "_template"
. Why even distinguish? If weāre using the ācard-templaterā, then surely weāre using templates. And even if weāre not, a string or a number is a valid template on its own.
Is there some technical reason why itās useful to identify templatable attributes by their names with "_template"
?
Iād done it like this since you may not want to template every option of the card you are wrapping in card-templater. Since this card needs to call the API to process the templates, it is more efficient to only do that for those properties which have templates. The only other way to identify these would be to parse the value of each property to see if it is a template, which would be harder (and more prone to error) than using the name of the property to determine this.
This makes sense. For something running browser-side, it makes sense to be able to avoid a round-trip to the server. However, I still have the issue with Home Assistant proper.
Iām running into a simple getting started problem that I canāt get over. Hope someone has some ideas.
Using version 0.0.5 (HA 0.103.2).
I have the following:
- type: entities
title: Covers
show_header_toggle: false
entities:
- entity: cover.my_test_blind1
- type: 'custom:card-templater'
card:
type: entities
title: Covers
show_header_toggle: false
entities:
- entity: cover.my_test_blind1
The ordinary entities card works as expected.
The second one using templater has the card displaying fine but says Entity not available: cover.my_test_blind1
[EDIT] Solved. Didnāt notice I needed to add the entities: for the templater itself.
- type: 'custom:card-templater'
card:
type: entities
title: Covers
show_header_toggle: false
entities:
- entity: cover.my_test_blind1
entities:
- cover.my_test_blind1
Iām trying to use this to change an icon based on state.
I can get this to work using the following (Iām using custom icons tlo:xxx
)
- type: 'custom:card-templater'
card:
type: entities
title: 'Covers - custom Card Templater'
show_header_toggle: false
entities:
- entity: cover.my_test_blind1
name: Test Blind Icon state
icon_template: >
{{ "tlo:tilt-blind-close" if is_state("cover.my_test_blind1","closed") else "tlo:tilt-blind-open" }}
However, when I change the icon_template to the following, the icon is missing whether the icon is encapsulated in quotes or not:
icon_template: >-
{% if is_state("cover.my_test_blind1","closed")-%}
"tlo:tilt-blind-close"
{% else -%}
"tlo:tilt-blind-open"
{% endif %}
Your second example works for me if I remove the quotes around the icon names (not using the custom icons, since I donāt have those). Here is an example that worked for me:
icon_template: |-
{% if is_state("device_tracker.my_phone","home")-%}
mdi:home
{% else -%}
mdi:map-marker
{% endif %}
The only difference was that it has icon_template: |-
rather than icon_template: >-
(I actually entered it as the latter and the GUI editor changed it to the former).
If it still doesnāt work, try changing the opening {% for your if, else, and endif to {%- (hyphen after the percent symbol). This will drop any leading newlines which may cause issues (you are already using -%} to close them (which drops trailing newlines).
Its working nowā¦Thanks!!
Perhaps beyond scope, but wanted to ask, for the āmore-infoā pop up card is there a way to template the icon for the pop up card? For example, for the blinds icon templating that was discussed above, when I click on the my_test_blind1 entity, the more-info pop up card is displayed, but it is displaying the HA native window open/closed icon instead of my custom icon.
In the latest beta version I expanded the state templating support so you can use it to template attributes. You should be able to do what you want by doing this:
type: 'custom:card-templater'
card:
type: entities
title: 'Covers - custom Card Templater'
show_header_toggle: false
entities:
- entity: cover.my_test_blind1
name: Test Blind Icon state
entities:
- entity: cover.my_test_blind1
attributes:
icon_template: |-
{%- if is_state("cover.my_test_blind1","closed")-%}
tlo:tilt-blind-close
{%- else -%}
tlo:tilt-blind-open
{%- endif %}
This is basically moving the templating of the icon from the card configuration to the state templating, so it should affect both the display on the card and the more-info popup.