iantrich / config-template-card

📝 Templatable Lovelace Configurations
MIT License
434 stars 56 forks source link

Reference to "self" #92

Closed seanomat closed 2 years ago

seanomat commented 2 years ago

Is your feature request related to a problem? Please describe. I am using the auto-entities component and would like to create a link based on the entity. It would be great if we could have some kind of reference to the displayed entity itself to use in templates. Also without the auto-entities it could make the yaml less redundant.

Describe the solution you'd like have some kind of reference to "self" to use in templates, like

device_id(self.entity_id)

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

uvjim commented 2 years ago

There's a couple of ways of doing this already...

  1. Reference this._config.entities[0] that should get you the entity_id that was passed into the card
  2. If you are using auto-entities the following would let you use the passed in entity_id (not the quotes around this.entity_id essentially making it a string for use in JavaScript - this method relies on the hierarchy of processing to work and assumes this card is being used in the options part of the auto-entities card.
    variables:
      ID_ENTITY_PART: >
        "this.entity_id".split(".")[1].split("_").slice(0,-1).join("_")
seanomat commented 2 years ago

I managed to to reference the current entity in a config-template-card inside an auto-entities-card with your tip. Since the config-tempate-card would have to be defined in the options this would mean, that if I want to use an entities card, I would have several of them with one entity each, instead of one entities-card with several entities, right?

Also I just realized, I can't seem to achieve what I originally set out for: linking an entity to the corresponding device-page (tap-action). Since I cannot use the function "device_id(entity_id)" within the config-template-card, there is no way of associating an entity_id with the corresponding device.