Custom integration with multiple devices

Hi everyone!

I’m creating an integration that polls data from devices.
It should allow for adding multiple devices, where each device has some connection data which should be supplied by the user.

Ideally I would like an Add Device button like the Z-Wave / ZigBee integrations have, but I don’t think this is possible with a custom integration?
As of now I have the possibility to add multiple instances of the integration (which creates multiple config_entries), but this is a rather ugly setup.

What would be the best way to achieve what I want? I’m considering storing data in the config options / options flow if there isn’t a better way to do it, but this seems a bit “hacky” as well.

you’d do this with a config_flow / user_form.

Have a look at the Cast component - it is initially added by zerfoconf but the user can revisit it and add other devices, which is stored in CONF_KNOWN_HOSTS in the config.entry.data

You’d have to distinguish between being added as a new integration or being asked to add a new device.

Thanks for your reply. Due to my integration having automatic discovery of devices etc, I found it more natural to use one config entry per device.
This also made it easier to organize my data, with each entry having one coordinator with one instance of the device data.

The only downside is that HA lists for instance 7 integration instances with 1 device instead of 1 integration instance with 7 devices. But I guess I can live with this.

I am trying to do something very similar for my integration. I want to discover multiple devices but add them all as separate ConfigEntries. But as one step - I can discover them all simultaneously but my integation is currently very hard coded to handle exactly one device per instance. So I’d like to have the config flow create multiple ConfigEntry instances in one go. It seems like this isn’t possible?