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.
/.homeycompose/discovery/nanoleaf-aurora.json
1
{
2
"type": "mdns-sd",
3
"mdns-sd": {
4
"name": "nanoleafapi",
5
"protocol": "tcp"
6
},
7
"id": "{{txt.id}}",
8
"conditions": [
9
[
10
{
11
"field": "txt.md",
12
"match": {
13
"type": "string",
14
"value": "NL22"
15
}
16
}
17
]
18
]
19
}
Copied!
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.
/.homeycompose/discovery/denon-heos.json
1
{
2
"type": "ssdp",
3
"ssdp": {
4
"search": "urn:schemas-denon-com:device:ACT-Denon:1"
5
},
6
"id": "{{headers.usn}}",
7
"conditions": [
8
[
9
{
10
"field": "headers.st",
11
"match": {
12
"type": "string",
13
"value": "urn:schemas-denon-com:device:ACT-Denon:1"
14
}
15
}
16
]
17
]
18
}
Copied!

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.
/.homeycompose/discovery/weinzierl.json
1
{
2
"type": "mac",
3
"mac": {
4
"manufacturer": [
5
[ 0, 36, 109 ],
6
[ 0, 36, 110 ]
7
]
8
}
9
}
Copied!
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:
1
"id": "{{txt.id}}"
Copied!
1
"id": "{{headers.uuid}}"
Copied!
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.
1
"conditions": [
2
[
3
{
4
"field": "txt.md",
5
"match": {
6
"type": "string",
7
"value": "NL29"
8
}
9
},
10
// AND:
11
{
12
"field": "txt.version",
13
"match": {
14
"type": "string",
15
"value": "1"
16
}
17
}
18
],
19
// OR:
20
[
21
{
22
"field": "txt.md",
23
"match": {
24
"type": "regex",
25
"value": "NL\\d\\d" // double slashes because of JSON
26
}
27
}
28
]
29
]
Copied!
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:
/.homeycompose/discovery/my_discovery.json
1
{
2
"type": "mdns-sd",
3
"mdns-sd": {
4
"protocol": "tcp",
5
"name": "my_service"
6
}
7
}
Copied!
/drivers/<driver_id>/driver.compose.json
1
"discovery": "my_discovery"
Copied!
In your driver.js, you can call Driver#getDiscoveryStrategy() to get the current strategy.
/drivers/<driver_id>/driver.js
1
const Homey = require('homey');
2
​
3
class Driver extends Homey.Driver {
4
async onPairListDevices() {
5
const discoveryStrategy = this.getDiscoveryStrategy();
6
const discoveryResults = discoveryStrategy.getDiscoveryResults();
7
​
8
const devices = Object.values(discoveryResults).map(discoveryResult => {
9
return {
10
name: discoveryResult.txt.name,
11
data: {
12
id: discoveryResult.id,
13
},
14
};
15
});
16
​
17
return devices;
18
}
19
}
20
​
21
module.exports = Driver;
Copied!
In your device.js, overload the methods starting with onDiscovery.
/drivers/<driver_id>/device.js
1
const Homey = require('homey');
2
​
3
class Device extends Homey.Device {
4
onDiscoveryResult(discoveryResult) {
5
// Return a truthy value here if the discovery result matches your device.
6
return discoveryResult.id === this.getData().id;
7
}
8
​
9
async onDiscoveryAvailable(discoveryResult) {
10
// This method will be executed once when the device has been found (onDiscoveryResult returned true)
11
this.api = new MyDeviceAPI(discoveryResult.address);
12
await this.api.connect(); // When this throws, the device will become unavailable.
13
}
14
​
15
onDiscoveryAddressChanged(discoveryResult) {
16
// Update your connection details here, reconnect when the device is offline
17
}
18
​
19
onDiscoveryLastSeenChanged(discoveryResult) {
20
// When the device is offline, try to reconnect here
21
}
22
}
23
​
24
module.exports = Device;
Copied!

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.
/app.js
1
const Homey = require('homey');
2
​
3
class App extends Homey.App {
4
async onInit() {
5
const discoveryStrategy = this.homey.discovery.getStrategy("my_strategy");
6
​
7
// Use the discovery results that were already found
8
const initialDiscoveryResults = discoveryStrategy.getDiscoveryResults();
9
for (const discoveryResult of Object.values(initialDiscoveryResults)) {
10
this.handleDiscoveryResult(discoveryResult);
11
}
12
​
13
// And listen to new results while the app is running
14
discoveryStrategy.on("result", discoveryResult => {
15
this.handleDiscoveryResult(discoveryResult);
16
});
17
}
18
​
19
handleDiscoveryResult(discoveryResult) {
20
this.log("Got result:", discoveryResult);
21
}
22
}
23
​
24
module.exports = App;
Copied!
Last modified 29d ago