Unable to add a Homekit Accessory using HA with Docker

Using the Home app on my iPhone, it hangs whilst trying to add Home Assistant as an Accessory. I open the Home app and select Plus icon top-right -> Add Accessory -> Don’t Have a Code or Can’t Scan -> Enter Code -> Type in code given to me by HASS. The app then waits indefinitely with a spinning circle top-right, and doesn’t display any discovered accessories.

I have just moved my HA config from a Raspberry Pi running Hassbian (where Homekit has been working fine - need to move to a faster server) to Docker, where everything works except Homekit. It’s essential I get this working as I was using it for presence detection.

Given what I have already tried below, would someone be able to suggest any further troubleshooting steps I could try please?

  • Docker on Ubuntu 18.04
  • iOS12
  • HA 0.81.5
  • Docker Compose file:
  homeassistant:
    container_name: homeassistant
    hostname: hass
    restart: always
    image: homeassistant/amd64-homeassistant
    volumes:
      - ${USERDIR}/docker/homeassistant:/config
      - /etc/localtime:/etc/localtime:ro
      - ${USERDIR}/docker/shared:/shared
      - ${USERDIR}/docker/sshkeys:/root/.ssh
    privileged: true
    network_mode: host
  • HA yaml settings:
homekit:
  filter:
    include_entities:
      - demo.demo

logs:
  pyhap: debug
  homeassistant.components.homekit: debug
  • deleted .homekit.state
  • Checked port 51827 is listening on the host:
$ netstat -plunt
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 192.168.1.10:51827   0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:8123            0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -
tcp6       0      0 :::8384                 :::*                    LISTEN      -
tcp6       0      0 :::22000                :::*                    LISTEN      -
udp    23040      0 0.0.0.0:10000           0.0.0.0:*                           -
udp    28416      0 127.0.0.53:53           0.0.0.0:*                           -
udp        0      0 192.168.1.10:68      0.0.0.0:*                           -
udp    48896      0 0.0.0.0:21027           0.0.0.0:*                           -
udp        0      0 0.0.0.0:47667           0.0.0.0:*                           -
udp   213056      0 0.0.0.0:5353            0.0.0.0:*                           -
udp   213056      0 0.0.0.0:5353            0.0.0.0:*                           -
udp   213056      0 0.0.0.0:5353            0.0.0.0:*                           -
udp    30592      0 0.0.0.0:5353            0.0.0.0:*                           -
udp    11648      0 224.0.0.50:9898         0.0.0.0:*                           -
udp6       0      0 :::40896                :::*                                -
udp6   33280      0 :::21027                :::*                                -
  • The HA logs only show the following, with nothing happening when trying to add an accessory:
2018-11-05 21:18:44 INFO (SyncWorker_2) [pyhap.accessory_driver] Storing Accessory state in `/config/.homekit.state`
2018-11-05 21:18:44 INFO (SyncWorker_2) [homeassistant.components.homekit.util] Pincode: 123-45-678
2018-11-05 21:18:44 DEBUG (SyncWorker_2) [homeassistant.components.homekit] Driver start
2018-11-05 21:18:44 INFO (SyncWorker_9) [pyhap.accessory_driver] Starting the event loop
2018-11-05 21:18:44 INFO (SyncWorker_0) [pyhap.accessory_driver] Starting accessory Home Assistant Bridge on address 192.168.1.10, port 51827.
2018-11-05 21:18:44 DEBUG (SyncWorker_0) [pyhap.accessory_driver] AccessoryDriver started successfully
  • I’ve rebooted my iPhone and ensured it’s on the same network.
  • I can ping my iPhone IP from the host and from within the HASS container

I’m stuck with what to try next - please help!

@cdce8p - I saw you had some great suggestions in one of the GitHub issues - would you mind having a look at this too please?

Thanks in advance.

Since it worked fine for the Hassbian install, I would rule out general network issues. That leaves your system / install as a point of failure. Personally I don’t use Docker, so don’t have any experience with it, but I see that network_mode: host should be required to make it work. Since you already did that and it still doesn’t work, I don’t really know how to help you.

What I can say is that replacing the accessory_driver file like I suggested for others doesn’t solve your issue. You can try reading through the troubleshooting section again, but I guess that wouldn’t help either.

One last thing I noticed: You’re running Docker on Ubuntu 18.04. Have you tried installing Home Assistant without Docker? You should be able to follow this guide for Rasperry Pi pretty closely.

Is Ubuntu running in a virtual machine? If so, I’m using VirtualBox and had to adjust the network settings to networkbridge (or something similar) to make it work.

I’d love to get to the bottom of this. Are you aware of any tests I can do from another computer to my Docker machine? Is there a command I can use to probe port 51827? I’ll do some digging and googling as well.

wow, the first thing I tried worked!! I changed the default port to 51828 and home assistant was detected after I entered the pin. :slight_smile:

homekit:
  port: 51828
  filter:
    include_entities:
      - demo.demo

Not sure why that made a difference because looking at netstat there’s nothing else listening to 51827 now that I’ve changed to 51828…

Hmm, I wonder - my old HA Pi is still up and running but with HA stopped. I reckon that might have been clashing with 51827 even though HA is no longer active. :slight_smile:
EDIT - nah can’t be that as my old Pi isn’t listening on 51827. Ah well, at least it’s working now!

Great to hear that it’s working :slight_smile:
Regarding the port, normally I would say that should only be an issue if something else on the same machine uses the same port (say another HA instance), but if it does the trick, better to not ask :wink: