Skip to content

HomeKit Integration with HomeAssisstant not working in Docker (Accessory Not found) #88785

Description

@sambhavbharvesh

The problem

The Issue
I recently setup my smart devices on Home Assistant through Local Tuya and ESPHome. Everything works as expected apart from the HomeKit Integration. When I scan the QR Code in the notification through my Apple Home App, it detects the bridge but after a few minutes says - Unable to add the accessory.

My Environment
I am running HA on a Docker Container on a Windows Based Host.

Information that I could gather

  1. My HA runs on Docker, which has its own bridge (a virtual network, ex: 172.x.x.x), which is totally different from my LAN's IP subnet (192.x.x.x), which could be a reason why my Apple Device is unable to add the bridge.
  2. To resolve this I need an mDns (ex: Avahi) along with a macvlan network.

What I have tried

  1. I tried creating a macvlan network adding the HA Container and an mDNs Reflector.
  2. Used Portainer's cumbersome way of creating a macvlan config network followed by an actual macvlan network using the UI
  3. The mdns-reflector code in docker-compose.yaml
 mdns-reflector:
    image: flungo/avahi
    container_name: mdns-reflector
    restart: unless-stopped
    volumes:
      - "D:\\Docker\\avahi:/etc/avahi/"
    ports:
      - "5353:5353"
  1. Allowing Inbound and Outbound traffic on several ports in Windows Firewall, tried turning it off as well. No help.
  2. Used Windows Subsystem for Linux too. I saw a video stating that is not possible to achieve all functionalities using just a Windows Host.
  3. Turned on Promiscuous mode on my eth0 adapter in WSL on my Windows Host.

Outcomes

  1. I was able to create a macvlan network.
  2. Added the HA Container and mDns reflector to the macvlan network
  3. Both the containers now had an IP Address belonging to my subnet instead of the virtual address they had earlier.
  4. I was able to ping one container from the other, but wasn't able to ping my gateway (physical) from the containers. I always got a Destination Host Unreachable/ Request timed out error message.
  5. I was not able to access HA after adding it to the macvlan network since it no longer ran on localhost. I tried accessing HA's macvlan IP at port 8123 from my Windows Host. But it did not work.
  6. Checked HomeKit logs, there is no error as such

2023-02-25 10:31:18.823 INFO (MainThread) [pyhap.accessory_driver] Starting accessory Test HomeKit on address 192.x.x.x, port 51828.
2023-02-25 10:31:18.823 DEBUG (MainThread) [pyhap.accessory_driver] Starting server.
2023-02-25 10:31:18.837 DEBUG (MainThread) [pyhap.accessory_driver] Get accessories response: (all accessory information here)
2023-02-25 10:31:18.838 DEBUG (MainThread) [pyhap.accessory_driver] Scheduling write of accessory state to disk
2023-02-25 10:31:18.838 DEBUG (MainThread) [pyhap.accessory_driver] Starting mDNS.
2023-02-25 10:31:18.839 DEBUG (MainThread) [pyhap.accessory_driver] Starting accessory Test HomeKit
2023-02-25 10:31:18.839 DEBUG (SyncWorker_1) [pyhap.accessory_driver] Writing of accessory state to disk
2023-02-25 10:31:18.840 DEBUG (MainThread) [pyhap.accessory_driver] AccessoryDriver for Test HomeKit started successfully
2023-02-25 10:31:18.841 DEBUG (SyncWorker_5) [pyhap.accessory_driver] Writing of accessory state to disk
2023-02-25 10:31:18.845 DEBUG (MainThread) [homeassistant.components.homekit.accessories] New_state: (state)
2023-02-25 10:31:18.846 DEBUG (MainThread) [homeassistant.components.homekit.type_switches] automation.ikea_air_purifier_automation_on: Set current state to True

Since the ping command to the gateway didn't work as expected, it means that macvlan wasn't working. I am bummed to not be able to use this integration. Am I missing something or does this integration not work anymore?

What version of Home Assistant Core has the issue?

2023.2.5

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

HomeKit

Link to integration documentation on our website

https://www.home-assistant.io/integrations/homekit

Diagnostics information

{
"home_assistant": {
"installation_type": "Home Assistant Container",
"version": "2023.2.5",
"dev": false,
"hassio": false,
"virtualenv": false,
"python_version": "3.10.7",
"docker": true,
"arch": "x86_64",
"timezone": "Asia/Kolkata",
"os_name": "Linux",
"os_version": "5.10.102.1-microsoft-standard-WSL2",
"run_as_root": true
},
"custom_components": {
"hacs": {
"version": "1.30.1",
"requirements": [
"aiogithubapi>=22.10.1"
]
},
"localtuya": {
"version": "5.0.0",
"requirements": []
}
},
"integration_manifest": {
"domain": "homekit",
"name": "HomeKit",
"documentation": "https://www.home-assistant.io/integrations/homekit",
"requirements": [
"HAP-python==4.6.0",
"fnvhash==0.1.0",
"PyQRCode==1.2.1",
"base36==0.1.1"
],
"dependencies": [
"ffmpeg",
"http",
"network"
],
"after_dependencies": [
"camera",
"zeroconf"
],
"codeowners": [
"@bdraco"
],
"zeroconf": [
"homekit.tcp.local."
],
"config_flow": true,
"iot_class": "local_push",
"loggers": [
"pyhap"
],
"is_built_in": true
},
"data": {
"status": 1,
"config-entry": {
"title": "Test HomeKit:51828",
"version": 1,
"data": {
"port": 51828,
"name": "Test HomeKit",
"advertise_ip": "192.x.x.x" #Windows Host IP
},
"options": {
"filter": {
"include_entity_globs": [],
"include_entities": [],
"exclude_domains": [],
"exclude_entities": [],
"include_domains": [],
"exclude_entity_globs": []
},
"entity_config": {},
"mode": "bridge"
}
},
"iid_storage": {
"1": {
"3E__14
": 2,
"3E__20
": 3,
"3E__21_": 4,
"3E__23_": 5,
"3E__30_": 6,
"3E__52_": 7,
"A2___": 8,
"A2__37_": 9
},
"2768650851": {
"3E__14_": 2,
"3E__20_": 3,
"3E__21_": 4,
"3E__23_": 5,
"3E__30_": 6,
"3E__52_": 7,
"86___": 8,
"86__71_": 9
},
"1665589703": {
"3E__14_": 2,
"3E__20_": 3,
"3E__21_": 4,
"3E__23_": 5,
"3E__30_": 6,
"3E__52_": 7,
"49___": 8,
"49__25_": 9
},
"2860342867": {
"3E__14_": 2,
"3E__20_": 3,
"3E__21_": 4,
"3E__23_": 5,
"3E__30_": 6,
"3E__52_": 7,
"49___": 8,
"49__25_": 9
},
"1827336563": {
"3E__14_": 2,
"3E__20_": 3,
"3E__21_": 4,
"3E__23_": 5,
"3E__30_": 6,
"3E__52_": 7,
"49___": 8,
"49__25_": 9
},
"3934288271": {
"3E__14_": 2,
"3E__20_": 3,
"3E__21_": 4,
"3E__23_": 5,
"3E__30_": 6,
"3E__52_": 7,
"8D___": 8,
"8D__95_": 9,
"8D__C6_": 10
}
},
"bridge": {
"2768650851": {
"aid": 2768650851,
"config": {
"platform": "Person"
},
"category": 10,
"name": "Sambhav Bharvesh",
"entity_id": "person.sambhav_bharvesh",
"entity_state": {
"entity_id": "person.sambhav_bharvesh",
"state": "unknown",
"attributes": {
"editable": true,
"id": "sambhav_bharvesh",
"user_id": "b7c7d265220e42cc9d0616dd1703efc0",
"entity_picture": "/api/image/serve/1beeb4e0330c3c81d53325cb001948bd/512x512",
"friendly_name": "Sambhav Bharvesh"
},
"last_changed": "2023-02-25T10:31:14.158114+00:00",
"last_updated": "2023-02-25T10:31:18.738580+00:00",
"context": {
"id": "01GT4211YJ9EYB9N6RCZGWHQK8",
"parent_id": null,
"user_id": null
}
}
},
"2860342867": {
"aid": 2860342867,
"config": {
"platform": "Automation"
},
"category": 8,
"name": "IKEA Air Purifier Automation - ON",
"entity_id": "automation.ikea_air_purifier_automation_on",
"entity_state": {
"entity_id": "automation.ikea_air_purifier_automation_on",
"state": "on",
"attributes": {
"last_triggered": "2023-02-24T17:08:17.329013+00:00",
"mode": "single",
"current": 0,
"id": "1677225409614",
"friendly_name": "IKEA Air Purifier Automation - ON"
},
"last_changed": "2023-02-25T10:31:17.494185+00:00",
"last_updated": "2023-02-25T10:31:17.494185+00:00",
"context": {
"id": "01GT4210QPYZNTP519SQP87TSH",
"parent_id": null,
"user_id": null
}
}
},
"1827336563": {
"aid": 1827336563,
"config": {
"platform": "Automation"
},
"category": 8,
"name": "IKEA Air Purifier Automation - OFF ",
"entity_id": "automation.ikea_air_purifier_automation_off",
"entity_state": {
"entity_id": "automation.ikea_air_purifier_automation_off",
"state": "on",
"attributes": {
"last_triggered": "2023-02-25T10:31:24.137393+00:00",
"mode": "single",
"current": 0,
"id": "1677225573564",
"friendly_name": "IKEA Air Purifier Automation - OFF "
},
"last_changed": "2023-02-25T10:31:17.494424+00:00",
"last_updated": "2023-02-25T10:31:24.157583+00:00",
"context": {
"id": "01GT421778WVMRG944RTH45HDE",
"parent_id": "01GT421776XSQB3NF3HP9G2622",
"user_id": null
}
}
},
"1665589703": {
"aid": 1665589703,
"config": {
"manufacturer": "Tuya",
"model": "Tuya generic (eb494ebb59f222fd53hj85)",
"sw_version": "3.3",
"platform": "localtuya"
},
"category": 8,
"name": "Wipro 10A Smart Plug",
"entity_id": "switch.wipro_10a_smart_plug",
"entity_state": {
"entity_id": "switch.wipro_10a_smart_plug",
"state": "off",
"attributes": {
"current": false,
"current_consumption": 0.0,
"voltage": 0.0,
"raw_state": false,
"icon": "mdi:toggle-switch",
"friendly_name": "Wipro 10A Smart Plug"
},
"last_changed": "2023-02-25T10:31:24.208390+00:00",
"last_updated": "2023-02-25T10:31:24.208390+00:00",
"context": {
"id": "01GT421778WVMRG944RTH45HDE",
"parent_id": "01GT421776XSQB3NF3HP9G2622",
"user_id": null
}
}
},
"3934288271": {
"aid": 3934288271,
"config": {
"manufacturer": "Espressif",
"model": "d1_mini",
"sw_version": "2023.2.3 (Feb 23 2023, 09:11:46)",
"platform": "esphome"
},
"category": 10,
"name": "Ikea Vindriktning Air Quality Sensor",
"entity_id": "sensor.ikea_vindriktning_air_quality_sensor_ikea_vindriktning_pm25",
"entity_state": {
"entity_id": "sensor.ikea_vindriktning_air_quality_sensor_ikea_vindriktning_pm25",
"state": "43",
"attributes": {
"state_class": "measurement",
"unit_of_measurement": "\u00b5g/m\u00b3",
"device_class": "pm25",
"icon": "mdi:air-filter",
"friendly_name": "Ikea Vindriktning Air Quality Sensor"
},
"last_changed": "2023-02-25T10:34:34.466860+00:00",
"last_updated": "2023-02-25T10:34:34.466860+00:00",
"context": {
"id": "01GT427132HB3EJKS5HXKE1FY5",
"parent_id": null,
"user_id": null
}
}
}
},
"accessories": [
{
"aid": 1,
"services": [
{
"iid": 1,
"type": "3E",
"characteristics": [
{
"iid": 2,
"type": "14",
"perms": [
"pw"
],
"format": "bool"
},
{
"iid": 3,
"type": "20",
"perms": [
"pr"
],
"format": "string",
"value": "Home Assistant"
},
{
"iid": 4,
"type": "21",
"perms": [
"pr"
],
"format": "string",
"value": "Bridge"
},
{
"iid": 5,
"type": "23",
"perms": [
"pr"
],
"format": "string",
"value": "Test HomeKit"
},
{
"iid": 6,
"type": "30",
"perms": [
"pr"
],
"format": "string",
"value": "homekit.bridge"
},
{
"iid": 7,
"type": "52",
"perms": [
"pr"
],
"format": "string",
"value": "2023.2.5"
}
]
},
{
"iid": 8,
"type": "A2",
"characteristics": [
{
"iid": 9,
"type": "37",
"perms": [
"pr",
"ev"
],
"format": "string",
"value": "01.01.00"
}
]
}
]
},
{
"aid": 2768650851,
"services": [
{
"iid": 1,
"type": "3E",
"characteristics": [
{
"iid": 2,
"type": "14",
"perms": [
"pw"
],
"format": "bool"
},
{
"iid": 3,
"type": "20",
"perms": [
"pr"
],
"format": "string",
"value": "Person"
},
{
"iid": 4,
"type": "21",
"perms": [
"pr"
],
"format": "string",
"value": "Person"
},
{
"iid": 5,
"type": "23",
"perms": [
"pr"
],
"format": "string",
"value": "Sambhav Bharvesh"
},
{
"iid": 6,
"type": "30",
"perms": [
"pr"
],
"format": "string",
"value": "person.sambhav_bharvesh"
},
{
"iid": 7,
"type": "52",
"perms": [
"pr"
],
"format": "string",
"value": "2023.2.5"
}
]
},
{
"iid": 8,
"type": "86",
"characteristics": [
{
"iid": 9,
"type": "71",
"perms": [
"pr",
"ev"
],
"format": "uint8",
"valid-values": [
0,
1
],
"value": 0
}
]
}
]
},
{
"aid": 2860342867,
"services": [
{
"iid": 1,
"type": "3E",
"characteristics": [
{
"iid": 2,
"type": "14",
"perms": [
"pw"
],
"format": "bool"
},
{
"iid": 3,
"type": "20",
"perms": [
"pr"
],
"format": "string",
"value": "Automation"
},
{
"iid": 4,
"type": "21",
"perms": [
"pr"
],
"format": "string",
"value": "Automation"
},
{
"iid": 5,
"type": "23",
"perms": [
"pr"
],
"format": "string",
"value": "IKEA Air Purifier Automation - ON"
},
{
"iid": 6,
"type": "30",
"perms": [
"pr"
],
"format": "string",
"value": "automation.ikea_air_purifier_automation_on"
},
{
"iid": 7,
"type": "52",
"perms": [
"pr"
],
"format": "string",
"value": "2023.2.5"
}
]
},
{
"iid": 8,
"type": "49",
"characteristics": [
{
"iid": 9,
"type": "25",
"perms": [
"pr",
"pw",
"ev"
],
"format": "bool",
"value": true
}
]
}
]
},
{
"aid": 1827336563,
"services": [
{
"iid": 1,
"type": "3E",
"characteristics": [
{
"iid": 2,
"type": "14",
"perms": [
"pw"
],
"format": "bool"
},
{
"iid": 3,
"type": "20",
"perms": [
"pr"
],
"format": "string",
"value": "Automation"
},
{
"iid": 4,
"type": "21",
"perms": [
"pr"
],
"format": "string",
"value": "Automation"
},
{
"iid": 5,
"type": "23",
"perms": [
"pr"
],
"format": "string",
"value": "IKEA Air Purifier Automation - OFF "
},
{
"iid": 6,
"type": "30",
"perms": [
"pr"
],
"format": "string",
"value": "automation.ikea_air_purifier_automation_off"
},
{
"iid": 7,
"type": "52",
"perms": [
"pr"
],
"format": "string",
"value": "2023.2.5"
}
]
},
{
"iid": 8,
"type": "49",
"characteristics": [
{
"iid": 9,
"type": "25",
"perms": [
"pr",
"pw",
"ev"
],
"format": "bool",
"value": true
}
]
}
]
},
{
"aid": 1665589703,
"services": [
{
"iid": 1,
"type": "3E",
"characteristics": [
{
"iid": 2,
"type": "14",
"perms": [
"pw"
],
"format": "bool"
},
{
"iid": 3,
"type": "20",
"perms": [
"pr"
],
"format": "string",
"value": "Tuya"
},
{
"iid": 4,
"type": "21",
"perms": [
"pr"
],
"format": "string",
"value": "Tuya generic (eb494ebb59f222fd53hj85)"
},
{
"iid": 5,
"type": "23",
"perms": [
"pr"
],
"format": "string",
"value": "Wipro 10A Smart Plug"
},
{
"iid": 6,
"type": "30",
"perms": [
"pr"
],
"format": "string",
"value": "switch.wipro_10a_smart_plug"
},
{
"iid": 7,
"type": "52",
"perms": [
"pr"
],
"format": "string",
"value": "3.3"
}
]
},
{
"iid": 8,
"type": "49",
"characteristics": [
{
"iid": 9,
"type": "25",
"perms": [
"pr",
"pw",
"ev"
],
"format": "bool",
"value": false
}
]
}
]
},
{
"aid": 3934288271,
"services": [
{
"iid": 1,
"type": "3E",
"characteristics": [
{
"iid": 2,
"type": "14",
"perms": [
"pw"
],
"format": "bool"
},
{
"iid": 3,
"type": "20",
"perms": [
"pr"
],
"format": "string",
"value": "Espressif"
},
{
"iid": 4,
"type": "21",
"perms": [
"pr"
],
"format": "string",
"value": "d1_mini"
},
{
"iid": 5,
"type": "23",
"perms": [
"pr"
],
"format": "string",
"value": "Ikea Vindriktning Air Quality Sensor"
},
{
"iid": 6,
"type": "30",
"perms": [
"pr"
],
"format": "string",
"value": "sensor.ikea_vindriktning_air_quality_sensor_ikea_vindriktning_pm"
},
{
"iid": 7,
"type": "52",
"perms": [
"pr"
],
"format": "string",
"value": "2023.2.3"
}
]
},
{
"iid": 8,
"type": "8D",
"characteristics": [
{
"iid": 9,
"type": "95",
"perms": [
"pr",
"ev"
],
"format": "uint8",
"valid-values": [
0,
1,
2,
3,
4,
5
],
"value": 3
},
{
"iid": 10,
"type": "C6",
"perms": [
"pr",
"ev"
],
"format": "float",
"minStep": 1,
"maxValue": 1000,
"minValue": 0,
"value": 43
}
]
}
]
}
],
"client_properties": {},
"config_version": 13,
"pairing_id": "B6:16:26:FA:57:27"
}
}

Example YAML snippet

version: '3'
services:
  mdns-reflector:
    image: flungo/avahi
    container_name: mdns-reflector
    restart: unless-stopped
    volumes:
      - "D:\\Docker\\avahi:/etc/avahi/"
    ports:
      - "5353:5353"
      #- "5353:5353/tcp"

  homeassistant:
    container_name: homeassistant
    image: "homeassistant/home-assistant:stable"
    volumes:
      - "D:\\Docker\\homeassistant:/config"
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    #network_mode: host
    privileged: true
    ports:
      - "8123:8123"

  #VSCode
  vscode:
    container_name: vscode
    image: codercom/code-server
    volumes:
      # Set <project dir> to the directory you want to open in VS Code.
      - "D:\\Docker\\:/config"
      # <vs code config> should point to a local dir where vs code stores its data.
      - "D:\\Docker\\:/home/coder/.local/share/code-server"
    ports:
      - "8443:8080"
    command: code-server --auth none --disable-telemetry /config
    restart: unless-stopped
  
  #Mosquitto
  mosquitto:
    container_name: mqtt
    image: eclipse-mosquitto
    ports:
      - "1883:1883"
      # This port is for Webhooks
      - "9001:9001"
    volumes:
      - "D:\\Docker\\mosquitto:/config:/mosquitto/config"
      - "D:\\Docker\\mosquitto\\data:/mosquitto/data"
      - "D:\\Docker\\mosquitto\\logs:/mosquitto/log"
      
  #ESPHome 
  esphome:
    container_name: esphome
    image: esphome/esphome
    ports:
      - "6052:6052"
    volumes:
      # Update PATH_TO_YOUR_CONFIG, the :rw gives the container Read/Write access
      - "D:\\Docker\\esphome:/config:rw"
      # Use local time for logging timestamps
      - /etc/localtime:/etc/localtime:ro
    # You do have to map a serial port here. Determine your port and uncomment.
    #devices:
    #  - /dev/ttyAMC0:/dev/ttyAMC0
    restart: always
    environment:
      - ESPHOME_DASHBOARD_USE_PING=true

Anything in the logs that might be useful for us?

No response

Additional information

No response

Metadata

Metadata

Assignees

Type

No type

Fields

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions