Homey Pro - Homey-API HTTPS connection fails

Hey guys,

I tested and created a working integration based on the following code snippet provided by Homey Support:

import { HomeyAPI } from 'homey-api';
const homeyApi = await HomeyAPI.createLocalAPI({
  address: 'http://192.169.1.123', // Replace this with Homey Pro's IP address
  token: 'ba78f646-4a0f-4869-95cd-c7040bc4e63b:21b9f8d2...', // Replace this with your API Key
});

// Get all devices
const devices = await homeyApi.devices.getDevices();
for(const device of Object.values(devices)) {
  console.log(device.name); // Prints the device's name
}

However, when I try to connect over HTTPS the application returns the following error:

FetchError: request to https://<homey-ip>.homey.homeylocal.com:<homey-port>/api/manager/system/ping failed, reason: getaddrinfo EAI_AGAIN <homey-ip>.homey.homeylocal.com

I configured my wifi router as follows:

  1. Gave Homey-Pro a static IP address
  2. Port forward(NAT/PAT): external 5679, internal: 443

NAT/PAT image of my Orange Livebox:

The only change I made to the code snippet shown above is the address:

https://<homey-ip>.homey.homeylocal.com:5679

note: the Homey Support article says to use https://192-168-0-123.homey.homeylocal.com as hostname for HTTPS connections.

Any suggestions are much appreciated!

<homey-ip>.homey.homeylocal.com resolves to a local IP address, so you shouldn’t use the external (port-forwarded) port, just https://<homey-ip>.homey.homeylocal.com (unless you used your external IP address as <homey-ip>, but if you did that you have to make sure that your router supports hairpin NAT).

Also, if you did use your local IP address, you need to disabled DNS rebinding protection in your router, otherwise it will not accept external hostnames that resolve to internal addresses (yes, to make your local Homey connection more secure with HTTPS you need to downgrade the overall security of your network :man_shrugging:t3:)

Thanks very much for your reply @robertklep . I tried the following:

HTTPS fails:

https://<local-ip>.homey.homeylocal.com
https://<local-ip>.homey.homeylocal.com:5679

https://<external-ip>.homey.homeylocal.com
https://<external-ip>.homey.homeylocal.com:5679

Still get the same error message, EAI_AGAIN

HTTP works:

http://<external-ip>:5678

Works fine for me:

const homeyApi = await HomeyAPI.createLocalAPI({
  address: 'https://192-168-23-9.homey.homeylocal.com',
  token: '...'
});

Can you try and resolve one of those IP-addresses from a command line or a utility to see what happens? On macOS/Linux you can do that using host:

$ host 192-168-23-9.homey.homeylocal.com
192-168-23-9.homey.homeylocal.com has address 192.168.23.9

I don’t know about Windows (perhaps use nslookup instead of host?).

1 Like

I get:

yh@sepi:~$ host 192-168-0-90.homey.homeylocal.com
192-168-0-90.homey.homeylocal.com has address 192.168.0.90

Remarkable, I noticed the use of dashes (-) in the IP address when resolving in the terminal using the $ host..., so I tried:

https://<ext-ern-al-ip>.homey.homeylocal.com:<port>

Note: use of dashes in the external ip address

in stead of:

https://<ext.ern.al.ip>.homey.homeylocal.com:<port>

and it works!

Note to myself: Wake up and READ more closely, the Homey Support article uses dashes in https://192-168-0-123.homey.homeylocal.com.

Thanks a bunch for the help @robertklep!

1 Like