Discovery
Discover LAN devices using mDNS-SD, SSDP or Manufacturer's MAC address (ARP).
Homey can automatically find devices on the user's Wi-Fi network using mDNS-SD, SSDP and MAC. This provides the best experience for a user, because entering an IP address —which can even change over time— is not a great experience.
Homey Bridge does not support local Wi-Fi connections, and therefore mDNS, SSDP and MAC discovery are not supported on Homey Cloud.
As a bonus, when using Discovery in conjunction with a Driver, Homey manages the Device's availability state automatically.
You can view a working example of a Homey App that uses Discovery at: https://github.com/athombv/com.plugwise.adam-example
Choosing a discovery strategy
Devices can be discovered using different strategies but most devices use mDNS-SD. To list mDNS-SD devices in your network you can use Discovery on MacOS or Bonjour browser on Windows. If a device is not discoverable with mDNS-SD please refer to your device's documentation to learn what strategy you can use for discovery.
mDNS-SD
Multicast-DNS Service Discovery is a widely used protocol to find devices on a network. It is also known as Avahi or Bonjour. A device broadcasts its presence under a name
(as specified by the manufacturer) and a protocol
(tcp
or udp
). For example, Homey broadcasts its presence with the name homey
using the tcp
protocol.
A DiscoveryResultMDNSSD
has a txt
property that contains the (lowercased) TXT values of the broadcast.
The discovery conditions
are optional but highly recommended, you can use these to pre-filter the discovery results. This way your app only receives the discovery results of devices that can actually be paired using your app.
SSDP
Devices using the Simple Service Discovery Protocol can be found by specifying a search
property.
A DiscoveryResultSSDP
has a headers
property that contains the (lowercased) headers of the response.
MAC
MAC Address discovery works by specifying the first 3 bytes of a network device's MAC address. These first three bytes are reserved for the manufacturer and can thus be used to find a device on the network using Address Resolution Protocol (ARP).
A DiscoveryResultMAC
only has an address
property, which contains the IP address of the device.
For example, to find a device with a MAC address that starts with 00:24:6d
or 00:24:6e
, convert them from hexadecimal to decimal.
The MAC address must be specified in decimal numbers, because JSON does not support hexadecimal-notation.
Defining your discovery strategy
The Discovery Result
Depending on your discovery type, some properties are available to match on. For example, an mDNS-SD discovery type has a txt
object and the SSDP discovery type has an headers
object. The discovery result provides the address that you can use to connect to the device.
Discovery Result ID
For the mdns-sd
and ssdp
discovery types, the app must define how a discovery result can be identified when it has been found multiple times, regardless if the IP address has changed.
For the mac
discovery type, the mac address is used as the ID.
Find a unique and consistent property in the discovery result and define it as id
in the App Manifest. Homey will then be able to match the result to previous results, and notify your app the device has been found again, instead of seeing the device as a new discovery result.
Examples:
All properties available in the DiscoveryResult are available between double curly braces ({{
and }}
).
Discovery Result Conditions
A discovery strategy can have a set of conditions that must be true before the result is sent to the app.
The conditions
property is an Array
with one or more Arrays
in it. This array contains Objects
rules. When all rules within an array are true, the result is considered a match. Using multiple arrays behaves as rulesArray1 OR rulesArray2 OR ...
.
There are two match types available: string
and regex
.
Conditions are matched case-insensitive.
Using discovery with a Driver
The recommended way to use Homey's built-in discovery is to link a discovery strategy to a Driver. If you use a discovery strategy with a Driver Homey will automatically manage the availability of your Devices. You can then use the onDiscovery*
methods in your Device class to get updated whenever the status of the device changes.
To start using discovery with a driver, add the discovery
property to your driver's entry in the App Manifest.
For example:
In your driver.js
, you can call Driver#getDiscoveryStrategy()
to get the current strategy.
In your device.js
, overload the methods starting with onDiscovery
.
Using discovery standalone
Simply call ManagerDiscovery#getStrategy()
with the discovery strategy ID as defined in your App Manifest. You can then call DiscoveryStrategy#getDiscoveryResults()
to get the devices that already have been discovered and listen to the result
event on the DiscoveryStrategy
to react to newly discovered devices while the app is running.
Last updated