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?