Template in tap action

Currently it is not possible to use templates in a tap action, for example in an URL.

For some purposes it can be very useful to use attributes of an entity inside a URL.

Most core dashboard cards do not support templating.

You can call a script with your tap action where you can template all the things.

2 Likes

Yes I’m familiar with the script workarround. But it doesn’t work if you want to open an URL outside Home Assistant. Isn’t it?

I think templating inside a tap action is something that wouldn’t benefit a lot of people, sorry to say. And with my little knowledge I wouldn’t be sure, if that isn’t a security problem as well… :slight_smile:

Nonetheless, is it just a link you want to template? Than use the markdown-card. Fully templatable and works like a charme. :slight_smile:

Like this:

- type: markdown
  content: >
    {% set mylink = "https://home-assistant.io" %}
    [My templatable link]({{mylink}})

You get the idea, I only set mylink as an example. You’d just template the link with whatever you want to set in the link. :slight_smile:

1 Like

Thank you for your reply!

I don’t see a reason why this can be a security risk, it’s just a simple link with a variable inside. With tools like PowerShell or other scripting language, this is normal behavior. For efficiency you will use variables much as possible.

I was already familiar with the Markdown workarround. Thanks!

1 Like

Yeah, as I said, I’m not sure, but using templates in some kind of action just doesn’t feel right. :laughing:

1 Like

Any luck with this? I am trying something similar with my card that is supposed to return what is for dinner that night.

show_state: true
show_name: true
camera_view: auto
type: picture-entity
entity: sensor.mealie_todays_meal
name: Dinner Tonight
camera_image: camera.camera_mealie_todays_meal_image
tap_action:
  action: url
  url_path: '[[[ return states["sensor.mealie_todays_meal_navigation_url"].state; ]]]'
card_mod:
  style: |
    ha-card {
    max-height: 100px !important;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    }