How to add a template entity to an exsiting card

I have an auto-discovered MQTT device which has multiple entities:

I need to convert the ‘distance_mm’ measurement into a volume (I jave a jinja template to do this). I would like to use a sensor template to do that, but then the value ends up on a separate ‘sensors’ card instead of on the ‘Oil Tank’ card.

I found a work-around, which is to create a yaml-entry:

mqtt:
  sensor:
    - name: "Level"
      state_topic: "/OilTank/distance_mm/state"
      unit_of_measurement: "gal"
      device_class: volume
      unique_id: OilTank_level
      device:
        identifiers: "OilTank"
        name: "OilTank"
      value_template: >-
        {# Convert distance to tank volume (meas in cm, output in gal) #}
        {% set distance = value %}
        ....

This works because I specified the ‘device’ parameter which is the same as the auto-detected entities, but I was trying not to have to configure mqtt manually (which is why I have everything setup with discovery), so I was hoping to solve this using a template sensor. But those do not support the ‘device’ attrbutes.

So how do I add an arbitrary sensor entity to a pre-existing card?

Unless you’re solely using the auto-generated default dashboard, you can simply edit any card to display whatever sensor(s) you want.

For something withing the card you have this
gadgetchnnel/lovelace-card-templater: Custom Lovelace card which allows Jinja2 templates to be applied to other cards (github.com)
or

iantrich/config-template-card: :memo: Templatable Lovelace Configurations (github.com)

I found the second one better responding but am still using the first one too

plus auto-entities card with “template” option.