Add Template Sensors to Device page

For a lot of my sensors I have to use a Template and create a virtual sensor for them. Example:

  - platform: template
      ### Clean up Aeotec Sensor status 
        device_class: window
        friendly_name: "Office Window Left"
        value_template: "{{ is_state('sensor.office_window_left_aeotec_sensor_7_access_control', '22') }}"

I would like to see these show up in the Devices page. So for the Office Window Left I would see all the Entities for this zwave device, and have a new section that would be any template sensors that reference this device. This would allow me to more easily see everything associated with a device.


What information within the Template Sensor’s configuration informs Home Assistant which Device it belongs to?

It can’t be the contents of the value_template because it may contain entities that do not belong to any Device.

I would say if an entity of a device was referenced it might show up in a template section as an option. Or have the ability to manually link a template sensor to a device…

Currently an entity belongs to a single Device. Therefore inferring the Device from the template is problematic because it may contain multiple entities.

Manually defining the Device would be the most straightforward way of making the association. The major hurdle is that there’s no easy way to refer to a Device in YAML (where Template Sensors are defined).

Take a peek inside the core.entity_registry file and you’ll see entities identify their parent Device using its device_id (not its name) which is a long-winded string.


"device_id": "ad5b16a3e66349b78b14ef4g4c1e0ea1",

If you’ve ever created a Device Automation, and looked at the code it produced, you may recognize that nomenclature.

Even if you were prepared to enter that long identifier, first you’d have to find it and, currently, it’s not revealed anywhere. You would have to look in places that weren’t intended to be explored.

The solution is to be able to create Template Sensors via the UI. Then it could offer a list of Devices (by name) to associate with the Template Sensor (and, under the hood, save its device_id). Unless that becomes available, I see no practical way of implementing your Feature Request.


Definitely see your points. Another method would be to customize the entity. So it would come in as a “On/Off” sensor or 22/23 sensor, but then being able to select that and change type to “Window/Door” etc. and specify and open closed value. This could be maintained as a custom device template, not in the use config yamls.

Just thinking out of the box.


This kind of dynamic ‘on-the-fly’ re-configuration of an entity is not possible if the entity is defined in YAML. It, as you know, requires restarting Home Assistant.

It may change if Template Sensors are ever allowed to be created and stored via the UI (and stored in the .storage directory). That’s now possible for the so-called “Helpers” (input_text, input_boolean, etc).

I’m searching the exactly same thing.
I have a z-wave device with some entities linked to it.
One of them expose the status of a switch in a numeric form as a sensor (0 when closed, 255 when opened). I can obviously create a binary template and turn it in a door sensor… but I like to see it in the list of entities linked to the device.

Any change in the last year?


Also looking for the same thing. I have a Z-Wave device with an entity that occasionally sends incorrect/erroneous values. I can make a template sensor to filter the outliers, but it would be nice to associate this sensor with the device.

I would love to see this functionality implemented. I have a lot of sensors that require some sort of manipulation (e.g. filtering for temperature, power, humidity), or other manipulation (integration of power to get energy for the energy dashboard).

This means I have all these nice devices with their overview pages, and then a whole bunch of entities which a derived from those devices but not linked to them.

I think it would make a lot of sense if we could link entities to devices.



I need this fonctionality too, for linking template sensors, and helper to existing device.

For example :
I made an automation to shutdown a switch if power is less that a numerical values since a delay.
It would be nice in in device pannel, i see the automation, the power values, and the delay value

+1. I am often needing to clean up values (especially cumulative energy from zwave devices). So a way to associate template sensors and also filter sensors with a device would be extremely useful.

+1, being able to specify device_id in template sensors would be great

1 Like

I believe this may be possible if the derived sensor entity is created using MQTT, but seemingly not when it is a template sensor

I have so many template sensors that simply exist to address dealing with ‘unknown’ values or more often, simply rounding decimals off temperatures to prevent database bloat and IO frequency

Being able to associate them with a device would be great, however for me, the best solution (in most cases) would be to not require so many template sensors, but to define a templated attribute for the underlying source entity that controlled the precision I actually care about having stored in the database as well as how significant the change should be for me to even consider recording it

1 Like

Giving this a bump because it seems HA now has the capability to do this internally, so I feel like it isn’t a stretch to ask for this to be exposed to the user base.

For example, when you create a reimann sum integration sensor via the helper page, it adds an attribute called “source” to the entity which points to an entity_id. The device page for that entity now shows both the original entities, as well as the newly linked reimann sum entity.

It also adds “Reimann Sum Integration” to the devices integrations list.

I was hoping this meant that I could now manually specify a “source” attribute in order to manually link it to the device, in the same way it seems to handle it internally, however, after testing it out, it does not work.

In my case, this would be very useful because I take a lot of time to calibrate all of my temperature entities. I create a template sensor to mimic the original temperature entity, but then it adjusts it using a +/- value. Unfortunately, this occasionally makes using the HA UI a bit annoying because these template sensors don’t have the option to jump to the device page.

1 Like

+1 => Being able to specify device_id in template sensors would be great !

+1. It’s starting to be ALOT of template entities in my config after a couple of years. It would be great to be able to organize them with self-defined devices but also the possibility to link them to existing devices.

Template devices would be nice, to mix and match entities with

1 Like

+1 searched for: “homeassistant template device” - found this threat

1 Like

Why don’t you add the Template-sensor to the Helpers-Page? My utility meter are all added to the respective devices. (I am using HomeAssistant in a docker container. Being able to add template sensors as a ‘helper’ would allow me to get rid of VSCode…)

There’s a Template helper in 2023.9.0 that allows you to create a Template Sensor via the UI.