This is a dated topic, but I looked around and didnt find a clear solution. After a bit of digging it looks like the solution here is two fold:
-
Open (publish) port 51827 in HA container (or, as it turns out, any port as its configurable on either side)
-
Publish (advertise) HA’s HAP (“Homekit Accessory Protocol”) service (port 51827) to mDNS
The latter can be accomplished in a couple of different ways depending on the host system. In my case its a Synology NAS which doesnt come with avahi-pubilsh
installed.
One (somewhat hacky in this scenario) way to announce a service to mDNS is to configure it in /etc/avahi/services
.
I named mine as homeassistant.service
and populated as follows:
root@nas:~# cat /etc/avahi/services/homeassistant.service
<service-group>
<name>Home Assistant 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.0</txt-record> <!-- HAP version -->
<txt-record>id=00:11:22:33:44:55</txt-record> <!-- MAC (from `.homekit.state`) -->
<txt-record>c#=2</txt-record> <!-- config version -->
<!-- the following appear to be optional -->
<txt-record>s#=1</txt-record> <!-- accessory state -->
<txt-record>ff=0</txt-record> <!-- unimportant -->
<txt-record>ci=2</txt-record> <!-- accessory category (2=bridge) -->
<txt-record>sf=1</txt-record> <!-- 0=not paired, 1=paired -->
<txt-record>sh=UaTxqQ==</txt-record> <!-- setup hash (used for pairing) -->
</service>
</service-group>
MAC address should be the same that was provided to HomeKit at pairing. It is stored in .homekit.state
located in HA configuration folder. At least in my version of Home Assistant. I believe older versions keep it elsewhere, should be easy to find.
Config version (c#
) is an integer, also stored in .homekit.state
however the value in the service descriptor for c#
doesnt appear to have to match whatever is in .homekit.state
.
Setup hash (sh
) is used for pairing with new accessories. I omitted it, as well as the rest of optional TXT records.
For completeness here’s my rather unremarkable docker-compose.yaml
:
version: '3.2'
networks:
homeassistant:
external: true
services:
homeassistant:
container_name: home-assistant
image: homeassistant/home-assistant
restart: always
volumes:
- ./config:/config
- /etc/localtime:/etc/localtime:ro
devices:
- /dev/ttyACM0:/dev/ttyACM0
ports:
- 51827:51827
networks:
- homeassistant
Hope this helps.