Take a look at the mqtt discovery docs for an entity type… (switch: https://www.home-assistant.io/integrations/switch.mqtt/#device). When you use HA’s discovery feature, you can send a device payload with each entity’s config as opposed to putting static config in yml. I’m not sure if you can replicate this in yml or not but it may be doable.
The way I think of this is imagine you’re building a physical device that has multiple sensors on it/switches… you’d send a discovery payload for each entity but the “device” block would be consistent for all of them. Discovery blocks device id should be something distinct from every other device, but stable (something like a MAC address, but probably not IP address). This allows HA to retain stable configuration and recognize/associate it with the unique id.
Thank you, all! This makes more sense. When I first read the documentation, I assumed the “device” section was about correlating an entity with an already defined device.
I’d still prefer it if this whole thing was done on the hass side - I don’t want my device to have hass specific details embedded within its public interface.
I am going to dig into what 123 wrote and see if I can come up with something clever (but not too delicate) from that.