Very n00b question: I am trying to use a specific attribute of an entity as the name of the entity in a card in my dashboard. The code I’m using is working in templates but not when I’m trying to use it in the card itself.
I used
> {{state_attr('climate.main_floor', 'preset_mode') | string}}
but still no luck.
Two things:
First, in YAML, this is an object/dictionary:
object: {"field": "value"}
It’s identical to this:
object:
field: value
It’s less readable so you don’t see it much but its still an object. Hence the problem, you’ve set name
to an object since the value starts with a {
. If the text value includes brackets or other special yaml characters it must be wrapped in quotation marks like this so YAML treats it like a string:
name: "{{state_attr('climate.main_floor', 'preset_mode') | string}}"
Or use yaml multiline string syntax like this:
name: >-
{{state_attr('climate.main_floor', 'preset_mode') | string}}
Then it won’t make it an object.
Second, you can’t actually use templates just anywhere in the UI. In fact most fields do not support them. I’m not very familiar with mushroom cards so maybe it does. But it seems unlikely to me since I see mushroom includes an explicit template card. Therefore I would guess that random fields in other cards don’t support templates, like most cards in HA.
EDIT: Yea pretty sure about my second note. Notice how in the doc for the template card it says which fields support templates. And then notice in the climate card none of them say that.
3 Likes
Thanks Mike for your great explanation!