Config Subentries #1070
-
ContextThere are integrations that have authentication stored in a config entry. Some of these integrations really are building blocks that have to be built on top of:
MQTT and KNX have in common that we use the config entry to store the authentication, and the entities are created on top of it. They have to be configured in YAML. For OpenAI and Google AI we decided to limit the user configuration to a single thing, and merge that into the config entry (in this case the prompt). It has the annoying side effect that a user has to re-enter API key for each OpenAI prompt it wants to use. There are also notifications that are in dire need of a solution. If you add an SMS gateway, how would you define targets? Right now you need to keep your targets in your scripts. Wouldn’t it be great if you could pre-create targets and those are represented as entities ? The scrape integration actually "solved" this and allows defining the sensors based on the scrape information via a very elaborate options flow. SolutionWe create a new data type called “config subentry”. It is owned by a config entry. It is set up as part of async_setup_entry. Config subentries are created by config subentry flows and updated by config subentry options flows. This works similarly to how we create/edit config flows. Config subentries will have a type such that we can decide what config subentry flows to show where in the UI. For example, config subentries of type Example use casesCreate MQTT entities from UINew flow with live preview with what the messages from MQTT will result in. Create conversation entitiesAdd config subentry flows to Google and OpenAI to allow creating customized conversation entities. This will users to create different entities with different prompts, instead of having both OpenAI API key and prompt in 1 config entry. Notification targetsCreate targets for notification integrations, like an SMS gateway or Telegram. Weather: add different locationsAdd different weather stations to a single API key. AI AgentsExample of how different AI providing integrations and their config subentries can provide different prompts and capabilities And a UI to manage all config subentries across different integrations could look like this: LifecyclePre-config subentries, the data hierarchy is like this (source): With subentries, we are introducing a new optional block between "Config Entry" and "Device Registry Entry". A device can either be linked directly to a config entry or a config subentry, not both. Deleting, disabling or re-enabling a config subentry will follow the existing logic:
AlternativesAn alternative is to get all integrations to put all config subentries inside their config entry. The downside of this is that it will not be possible to group config subentries from different integrations together on a single page, like showing a page with all AI agents, weather stations or notification targets. Having the config subentries as a new concept will also allow us to offer edit buttons for entities if we know the relationship between config subentry and entity is 1:1. NoteIt is not the goal to put automations and scripts into config subentries. Those are inside YAML as per our ADRs and will be kept there. |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 17 replies
-
If I read this some more examples come to mind, can you validate that these are a logical next step?
|
Beta Was this translation helpful? Give feedback.
-
If this also allow discovery, rfxtrx could use this and get rid of its annoying/complex config flow. |
Beta Was this translation helpful? Give feedback.
-
This is a very nice idea, and actually very much like what I have been "toying" with for modbus, at least if I understand it correctly. Thinking in terms of modbus, there would be a subentry for each transport type, with the specific transport parameters. So in the config entry the user select transport type, and can then set the parameters in the subentry. The idea that the subentry have a type, is important, because it helps have different subentries. |
Beta Was this translation helpful? Give feedback.
-
I think we also need to think about a way to define the flow for the integration. For example, MQTT would maybe be sufficient to only have set up the main config entry, and quit the flow, while another integration might want to register an x amount of flows directly at creation which the user should finish before it can load (To take MyUplink for example, they have devices that can expose up to 600 entities which are not all relevant (but they can't create a generic way to differentiate on that). So in that case it would be nice that the user first has to finish the device flow before the device is added (so the user had to select their relevant data points before adding the device). Maybe some sort of way to allow the integration or the config flow to "discover" new subentries the user has to configure, that'd be great |
Beta Was this translation helpful? Give feedback.
-
Could matter use this? Right now, the integration has a config entry for the connection to the matter addon. With this each pairing would be a sub-config-entry. Pairings could then be deleted by the normal config entry delete hook. This could potentially unlock using normal HA discovery flow for adding new matter devices too? AIUI For devices already visible by zeroconf we wouldn't need the app involvement, but previously that didn't really work because the discovery flows end in the creation of config entries. |
Beta Was this translation helpful? Give feedback.
-
Thinking about sub entries... sub entries from another domain could make sense. Say modbus main domain, some heat pump needing to piggy back on the modbus bus config. |
Beta Was this translation helpful? Give feedback.
-
It's not clear to me why a device can only be linked to either a config entry or a sub entry. Today it's up to integrations to decide how to link entities to devices/services. Eg one config entry can have single device/service with multiple entities or multiple devices/services with one or many entities. From an integration perspective, adding configuration via config subentries doesn't mean that an integration has a specific relationship between devices/services and its entities. It means that the integration needs to be able to add entities with their own configuration. I think we should be very careful before we start deciding the relationship between devices/services and entities on behalf of integrations if that's not really needed. |
Beta Was this translation helpful? Give feedback.
-
This proposal has been approved by the core meeting. |
Beta Was this translation helpful? Give feedback.
This proposal has been approved by the core meeting.