Solved: How to configure Avahi daemon on Docker host

Hi,

There are many ‘no response’ issues regarding homekit and homeassistant, I do not claim to have read them all but I read as much as I could. I tried most recommendations (such as playing with IGMP settings on my Ubiquiti equipment), and eventually did get it working in the past by following these steps:

  • Install avahi-daemon on the Docker host
  • create a hap.service file on the Docker host with the following contents:
<service-group>
  <name>HA_Bridge</name>
  <service>
    <type>_hap._tcp</type>
    <port>51827</port>
    <txt-record>md=HA_Bridge</txt-record>         <!-- friendly name                 -->

    <!-- the following appear to be mandatory -->
    <txt-record>pv=1.1</txt-record>               <!-- HAP version                   -->
    <txt-record>id=CB:76:18:26:75:A2</txt-record> <!-- MAC (from `.homekit.state`)   -->
    <txt-record>c#=2</txt-record>
    <txt-record>s#=1</txt-record>                 <!-- config version                -->
    <txt-record>ff=0</txt-record>                 <!-- config version                -->
    <txt-record>ci=2</txt-record>
    <txt-record>sf=1</txt-record>
    <txt-record>sh=""</txt-record>
  </service>
</service-group>
  • Start homeassistant with the following configuration snippet:
homekit:
- name: HA_Bridge
  port: 51827
  advertise_ip: 192.168.2.3
  • Wait for the Homekit integration to start,
  • Replace the ‘id’ and the ‘sh’ values in the hap.service file with the values returned by python3 -m netdisco
  • Open Home app on iPhone, and pair the Homebridge gateway
  • If it fails after a while, verify the values again by running python3 -m netdisco and replace them in the hap.service file if necessary

However, since I upgraded to the latest version of home-assistant the command python3 -m netdisco does not work anymore. As an alternative I use the MAC address value shown in .storage/homekit.*.state as the ‘id’ in the hap.service file. This works for pairing, but a while after the homeassistant entities go into ‘no response’. I suspect this is due to the fact that:

  • my iPhone tranfers the connection to a homekit gateway (e.g. homepod)
  • this homekit gateway tries to discover the hap service (I see queries and correct responses in Wireshark)
  • the gateway and homeassistant do not link since their expected values for the hap service do not match (perhaps the ‘sh’ value?).

My ultimate goal is simply to get the homekit integration to work in my environment (see below). I don’t mind executing some manual steps after the initial pairing.

My environment

  • Homeassistant in rootless Docker container running in its own VLAN
  • Homeassistant version core-2021.11.2 with HAP-python version: 4.3.0 (default)
  • Avahi-daemon running on Docker host (Ubuntu)
  • PFSense firewall with Avahi reflection enabled for IPV4 (disabled for IPV6)
  • Ubiquiti APs
  • Two homepods: one original and one mini
  • One Apple TV

Any help is greatly appreciated.

Ok, it’s always when you take the time to ask for help that things start to be clear. I simply have to ensure the Avahi reflector on the Docker host matches exactly what the home-assistant container internally emits.

I used to do check that with python3 -m netdisco but that seems to be deprecated and can be replaced by python3 discover_hap.py where the ‘discover_hap.py’ program looks like the following (copy paste from zeroconf · PyPI):

from zeroconf import ServiceBrowser, Zeroconf

class MyListener:

    def remove_service(self, zeroconf, type, name):
        print("Service %s removed" % (name,))

    def add_service(self, zeroconf, type, name):
        info = zeroconf.get_service_info(type, name)
        print("Service %s added, service info: %s" % (name, info))

zeroconf = Zeroconf()
listener = MyListener()
browser = ServiceBrowser(zeroconf, "_hap._tcp.local.", listener)
try:
    input("Press enter to exit...\n\n")
finally:
    zeroconf.close()

Run the above both on the container and on the host, and modify the hap.service file on the host if necessary to exactly match the container. Then everything works.

Hey @Michel5, it looks like you’ve done a fair bit of discovery on this topic. I’d hope you could shed me a light.

My setup looks very similar to yours but I’ve also got NGINX to reverse proxy HASS to the real network.
I’m trying to figure out why I can’t complete the homekit setup process (once I add the integration, it creates the homekit QR code, I then scan it with the phone/ipad, get the option to “add the bridge to home” (within the homekit app), select to add to my existing home. At this point, it attempts to connect to the bridge, but it fails.

This really looks to me that some traffic is broken when I scan the QR code. That is probably between the homekit bridge (ipad) and HASS, but I don’t know what I’m looking for and I don’t know what too look for. (i.e. what type of traffic flow happens at this point?).

The message I get on the phone isn’t helpful (Accessory Not Found. Make sure your accessory is powered and connected to your router with an Ethernet cable, then try again.")

I’ve been looking for traffic logs between the homekit bridge (ipad) and HASS but nothing being blocked.
let me ask a few questions that might help me to understand this…

I noticed that you specified a mac address on the hap service - from which device/interface is that mac address?

how do I add hap.service to my avahi container?

on your example, the IP address 192.168.2.3… is it HASS IP address to be advertised to the homekit bridge?

if you know it, what sort of network traffic am I looking for at this initial setup?

really appreicate in advance!

1 Like

Hi @zlochevsky ,

Sure, I can try to help.

  • 192.168.2.3 is the IP of the ubuntu host running the Homeassistant Docker container. Are you running Homeassistant as a Docker container, or are you running the Homeassistant operating system?
  • the MAC address changes everytime - I guess it is a fake MAC generated internally. So you have to fetch it from the /config/.homekit.state file or find it using the python command of my previous post.

A couple of things you could do to troubleshoot:

2 Likes