Dynamically Creating Entities

Hi all,

I’m currently creating an integration to merge into Home Assistant core. This integration connects to a server and can report the number of transcode processes that this server is doing. I would like to represent each transcode process as a Sensor entity in Home Assistant. The problem is, the number of these processes could theoretically be anywhere from 0 to infinity, given the computing resources of the transcode server. This number can also change at any time given the number of tasks, the number may scale up or down. I’m having trouble with how I would represent transcode processes that no longer exist. For example, there is workers numbered 1 through 8 where there are 8 transcoding processes happening at the same time and one minute later, there only be 4 transcoding processes. These 4 transcoding processes could turn back on given the correct circumstances, but they could also never turn on to a number that high again. For the 4 processes that no longer exist, would it be best to represent these as disabled entities, or outright remove them? I’m leaning towards outright removing them, because there is no guarantee that those processes could ever spin up again, leaving un-used disabled entities in a user’s Home Assistant instance, but I’m really not sure how that would affect things like user automations.

Also, I’m able to add entities statically in my integrations files, but I’m unsure how to dynamically add more as more transcoding processes are discovered.

Right now, I’m currently listing all of these processes in the attributes of a “Number of Processes” sensor entity as Process1_DataPoint1, Process2_DataPoint2, but I find it a bit messy in the attributes as really each process should have its own attributes and not multiple attributes to signify each data point.

I’m just looking for some advice and best practices in what to do in this situation. I tried looking through some other existing integrations in the core, but I’m unsure of any that add and remove entities dynamically depending on an external variable like this integration is planning to do.

Thank you in advance to anyone willing to lend a hand, I really appreciate it!