Component Discovery

This option is only available for built-in components.

Home Assistant has a discovery service running in the background to discover new devices. Whenever a new device is discovered, a SERVICE_DISCOVERED event will be fired with the found service and the information. The discovery component has some knowledge about which components handle which type of services and will ensure those are loaded and listening before firing the SERVICE_DISCOVERED event.

Add discovery instructions

Device discovery for Home Assistant has been extracted into an external library called NetDisco. This library is integrated using the discovery component and scans the network in intervals for uPnP and zeroconf/mDNS services.

Listening to SERVICE_DISCOVERED events

From your component, you will have to set up the listening for specific services. Given below is an example how one would listen for a discovered AwesomeDevice:

fromhomeassistant.components.discoveryimportSERVICE_AWESOMEDEVICEfromhomeassistant.helpersimportdiscoveryDOMAIN='awesomedevice'DEPENDENCIES=['http']defsetup(hass,config):cfg=config.get(DOMAIN)defdevice_discovered(service,info):""" Called when a Awesome device has been discovered. """print("Discovered a new Awesome device: {}".format(info))discovery.listen(hass,SERVICE_AWESOMEDEVICE,device_discovered)returnTrue

Auto-loading your component upon discovery

The discovery component is capable of setting up your components before firing the EVENT_PLATFORM_DISCOVERED event. To do this you will have to update the SERVICE_HANDLERS constant in the discovery component: