WTH can't I attach a template sensor to a particular device

I often create derivative template sensors from other sensors created by particular integrations/devices. It would be nice to be able to declare the template to be part of the device, so that it could appear on the device’s page (e.g. under a separate template entities categories).

Or devices could automatically show all the template sensors which depend on the device’s entities.

It actually attaches itself to a device automatically, code reference:

Please note, devices are only a feature that can be used for things managed through the UI; there is no device context or possibility available when creating YAML helpers.

…/Frenck

i can create device referneces in yaml, when i create mqtt entities, why the heck isn’t that possible when creating template entities in yaml?

For template helper entities created through the UI, you can associate them with a device through the template options.
I’ve been migrating some of my template sensors that were defined in YML to be configured through the UI (If they don’t use properties that are only definable through YML…)

Migration is not the problem. Problematic might be a situation if one wants to maintain his/her configuration organized in packages. Having some sensors in packages while others in UI isn’t a really good idea.

I’m not sure you still need a solution (for yaml created templates).
Since I’m on the same board, I was desperately looking for su a way, I found a custom integration that can do that. It’s still not the same as managing entities in yaml. But it’s better than nothing in some cases

It looks it provides lot of options to manipulate devices.
One of them is assigning any entity to a device. I can confirm I was able to assign the Yaml-created energy template sensor to an existing device.

PS. I hope it will not discourage possible developers to add native way to do so.

That looks interesting, but am I blind or is there no documentation whatsoever on how to use it? The only instructions there is only tells you how to install it. I’ve done that but there is no new Device Tools anywhere within HASS as far as I can find…

It’s true. I didn’t find it either.
But the usage is simple. install it, then in Settings/ Devices&Services use add integration button and select Device Tools.
After that, the GUI will guide you

I’m also using this custom_component.

so I can guide you a bit:

If you have a couple of sensors, for example, created via Modbus integration - or templates, you can create a new device.

If you want to modify an existing device, select the device name you want to modify…

Within the device, you can then assign the entities you want to.
Go to “Configure” - and there, you can add all the entities to your “new” or “modified” device, you want…

You could also merge two different devices together with this, if you want to… :slight_smile:

Also device actions reference devices from YAML.

Why this push to force everyone to use the UI for everything? For those of us with a computer science or software engineering background, it’s exhausting creating template entities through the UI, even using blueprints, when copy & paste in a well structured set of YAML files & Jinja2 macros loaded from configuration.yaml is easier to maintain & can be kept under revision control?

It’s legitimately not possible to attach devices via yaml at the moment because template integration doesn’t have a config entry. It’s not on purpose and it’s rather annoying that you’re assuming that it’s done on purpose.

Didn’t mean to ruffle feathers but from @frenck 's post here and discussions of features not available in YAML in other threads, there is a concern from many of us that YAML is becoming a second class citizen. If the UI config supports associating a ‘helper’ entity with a device, why not from YAML? Consider this a feature request if you prefer.

New releases often say ‘now available to set up from the UI’ which usually also means ‘can no longer be set up from YAML’.

I love Home Assistant & the fully appreciate the work done by the core team. I’ve even bought the T-shirt. Keep doing the great things you are but please think about those of us who prefer a text editor when adding or changing things.

It’s not possible because it does not have a config_entry. A config entry is required for devices to work. Integrations that allow devices via YAML have a config entry. MQTT, KNX to name a few. That’s because the user sets up a configuration via the UI which creates the config entry, which allows the yaml configuration to add devices. Config entries are generated from unique information at time of creation. That’s not possible with YAML. So there’s no way around this. The only way template entities can ever get a device_id option is if I’m provided a way to automatically create a config_entry for yaml based template entities.

Yes, integrations that connect to external devices require a UI setup. This is a hard requirement for HA now. Integrations that do not connect to external devices still allow yaml and can keep yaml. There’s an ADR about this.

Well the core team doesn’t manage template entities, I do. A yaml loving volunteer. So it annoys the shit out of me when people bitch like it’s my fault when I can’t implement something because the framework doesn’t exist.

Asking why a feature is not available is not ‘bitching’. Nor is it blaming anyone for anything.

As you are an admin on this site, I assumed you were pretty ‘core’.

As you’re an admin, I might expect a little more civility too, please.

By all means, flag my posts if you don’t like them. I’m a member of this community just like yourself. I’m not going to hide my opinion if you aren’t hiding yours. I’ve put way more time and effort into making template entities better for everyone, so its a bit personal.

Anyways, once blueprints are introduced to the UI (No ETA yet), devices will be attachable that way for both trigger based template entities and state based template entities. Outside that, I have a arch proposal to add a default config entry that’s waiting on approvals. But I’m not holding my breath because it would require work from someone on the frontend and I don’t do frontend work. It would also mean that template entities would have to be reclassified as an integration instead of helpers.

TLDR: Red tape, unlikely anytime soon. However it is a goal to have device_id in yaml.

When someone reviews my work, closed source or FOSS, I don’t accuse them of bad behaviour when they query a limitation or find a flaw nor do I take it as a personal attack. End message.

Thank you.

You aren’t reviewing work, you’re just making random assumptions and spamming the forums in multiple threads. I just happened to chose this thread to respond. Your comments are akin to a random redditor on a video game subreddit making assumptions about the decisions of the direction of the game. Which is 100% off the mark. It’s a technical issue, not a decision issue.

I’m going to cool off for a moment. Ending this discussion.