rianadon/timer-bar-card

Templateable Name

Closed this issue · 5 comments

Hi,

First off, thanks for this fantastic card.

Would you consider making the name property templateable? My use case would be showing the current duration on the card. For example, I use this card with an esphome heating controller. The timer is configurable in an additional entity. I would like to show what is is currently set to.

image

Hey! That's an interesting idea!

I don't know if there's easy any ways to render templates inside of a card. Template evaluation typically happens on the Home Assistant server rather than the frontend.

I hate to tell you to make some new template entities, but this seems like a great use case of a template entity since you can template the name in those.

Since you'd like to show the duration (one of the entity attributes) on the card, I feel like maybe having an option that takes a list of attribute values to append to the card name might be enough to do what you're looking for. Perhaps these could be separated by some kind of line or enclosed in a different colored box to make them distinct from the entity name.

However, this is a bit of work for something very niche, so I suggest you use templates until a few others 👍 this.

Thanks for your response.

I accept this is pretty niche, so feel free to close this for now. I'll probably go with a template entity - as you suggested.

In case it's of interest, here's a pretty simple plugin that does include a templatable name: https://github.com/thomasloven/lovelace-template-entity-row/

The custom button card does as well, although that does a lot and is obviously more complex.

I won't have time to in the near-future, but if I attempted to implement something along these lines, would you consider a PR?

Just to add to my previous message, the card tools dependency adds support for this.

Oh awesome! I didn't know card tools had support for this.

I've thought about this and came to the conclusion that if I added template support for the entity name, it would also make sense to make the entity icon and other card attributes template-able.

That would require a lot of changes to the card, and since there are other cards which can apply templates (such as config-template-card), I don't think it would be worth adding templates to the card.

Here's how you could change the name with config-template-card:

type: custom:config-template-card
variables:
  TEMP: states['sensor.upstairs_temperature'].state
entities:
  - timer.alarm_three
  - sensor.upstairs_temperature
card:
  type: custom:timer-bar-card
  icon: mdi:laser-pointer
  entities:
    - entity: timer.alarm_three
      name: ${'It is ' + TEMP + ' degrees'}

Unfortunately the template syntax of the config-template-card uses JavaScript. I also just found this one that uses the same templating langauge (jinja2) as Home Assistant. I'm going to add an example to the README with this card.