Homekit Integration

Hello,
i´m pretty new to HASS and i´m stugeling with the Homekit integration. So i have some enteties that i want to add in Homkit witht the following config:

homekit:
  - entity_config:
    sensor.ble_temperature_buro:
      linked_battery_sensor: sensor.ble_battery_buro
      low_battery_threshold: 10
    sensor.ble_humidity_buro:
      linked_battery_sensor: sensor.ble_battery_buro
      low_battery_threshold: 10
- name: NM-Homeassistant
  port: 56332
  filter:
    include_entity_globs:
      - sensor.ble_*

with this config i got the following errors:

2020-11-18 11:48:55 ERROR (MainThread) [homeassistant.setup] Error during setup of component homekit
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 213, in _async_setup_component
result = await task
File "/usr/src/homeassistant/homeassistant/components/homekit/__init__.py", line 160, in async_setup
entries_by_name = {entry.data[CONF_NAME]: entry for entry in current_entries}
File "/usr/src/homeassistant/homeassistant/components/homekit/__init__.py", line 160, in <dictcomp>
entries_by_name = {entry.data[CONF_NAME]: entry for entry in current_entries}
KeyError: 'name'

cany anyone help here?

check your yaml file
it entity_config and name have to be on the same level

i made now this config changes:

homekit:
  - entity_config:
      sensor.ble_temperature_buro:
        linked_battery_sensor: sensor.ble_battery_buro
        low_battery_threshold: 10
      sensor.ble_humidity_buro:
        linked_battery_sensor: sensor.ble_battery_buro
        low_battery_threshold: 10
  - name: NM-Homeassistant  
    port: 56332
    filter:
      include_entity_globs:
        - sensor.ble_*

and still have the issue

try this

homekit:
  - name: NM-Homeassistant  
    port: 56332
    entity_config:
      sensor.ble_temperature_buro:
        linked_battery_sensor: sensor.ble_battery_buro
        low_battery_threshold: 10
      sensor.ble_humidity_buro:
        linked_battery_sensor: sensor.ble_battery_buro
        low_battery_threshold: 10
    filter:
      include_entity_globs:
        - sensor.ble_*

try this

still the same error

the strange thing that i also get the error if i just put this in the config file:

homekit:
- name: NM-Homeassistant  
  port: 56332

What happens if you remove the name attribute

try removing the leading - in front of name: and indent it 2 spaces from the homekit: header. I know the docs show it in the example, but my config does not have any hyphens and it works.

here’s part of my config as an example:

homekit:
  auto_start: False
  port: 51827
  name: Home Assistant Bridge
  safe_mode: False
  filter:
    include_domains:
      - alarm_control_panel
      - light
      - lock
      - switch
      - vacuum
    include_entities:
      - camera.security_camera
    exclude_entities:
      - switch.doorbell_switch
  entity_config:
    alarm_control_panel.ha_alarm:
      code: !secret alarm_code
    camera.security_camera:
      video_codec: copy
      stream_source: !secret camera_url

EDIT: I only have 1 homekit bridge, so that’s probably why I don’t have the leading hyphens and it works. If I were to add multiple bridges to my YAML config, then I’d probably need the hyphens.

Should be fixed here https://github.com/home-assistant/core/pull/43364

thank you but can you explain me what i did wrong? I was providing a name in the config or?

i also tried this but without success:

homekit:
  name: abc
  port: 51827

Its a bug. You’ll need to delete the integration in the UI and restart for the error to go away once a name is set.

Hi,
I’m facing the same issue (see https://github.com/home-assistant/core/issues/43296)
I’ve applied the patch on top of release 0.117.6 and got a similar failure a little bit later:

2020-11-19 21:17:35 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 128, in async_init
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 201, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/config/custom_components/homekit/config_flow.py", line 144, in async_step_import
    if not self._async_is_unique_name_port(user_input):
  File "/config/custom_components/homekit/config_flow.py", line 190, in _async_is_unique_name_port
    if entry.data[CONF_NAME] == name or entry.data[CONF_PORT] == port:
KeyError: 'name'

Needed to patch also config_flow.py like this to get a working config:

from .const import (
    BRIDGE_NAME,

...

    @callback
    def _async_is_unique_name_port(self, user_input):
        """Determine is a name or port is already used."""
        name = user_input[CONF_NAME]
        port = user_input[CONF_PORT]
        for entry in self._async_current_entries():
            if entry.data.get(CONF_NAME, BRIDGE_NAME) == name or entry.data[CONF_PORT] == port:
                return False
        return True

After that, impossible to get the Pairing Notification and nothing in the log :frowning:

After i removed the integration i still have the same error

Please upgrade to 0.118.1

Still same issue.
I found a way to recover:
Remove HomeKit from configurations.yaml and from Integrations UI.
In the config folder, edit the .storage/core.config_entries, remove the entry_id related to HomeKit like this one (not the one of Hue):

            {
                "entry_id": "dc5107347ba15e203768d5f3d6fd8cf9",
                "version": 1,
                "domain": "homekit",
                "title": "Ignored",
                "data": {},
                "options": {},
                "system_options": {
                    "disable_new_entities": false
                },
                "source": "ignore",
                "connection_class": "local_push",
                "unique_id": null
            }

Restart HA.
Add an homekit config in configurations.yaml like this one:

homekit:
  filter:
    include_entities:
      - demo.demo

And tadam! No more error and a splendide notification with HomeKit code!

Looks like removing HomeKit from Integration UI let some artifacts in the core.config_entries.

2 Likes

i updated to 0.118.2 with this config:

homekit:
- entity_config:
    sensor.ble_temperature_buro:
      linked_battery_sensor: sensor.ble_battery_buro
      low_battery_threshold: 10
    sensor.ble_humidity_buro:
      linked_battery_sensor: sensor.ble_battery_buro
      low_battery_threshold: 10
- name: NM-Homeassistant  
  port: 56332
  filter:
    include_entity_globs:
      - sensor.ble_*

I don´t get now any error but the Home Kit Bridge didn´t appear in the setup

Just to flag that I get this error in 0.118.3.

Even with just:

homekit:

I end up with the error:

KeyError: 'name'

in the logs.

Tried defining ‘name’ with and without a dash before it - incase name was mandatory and still nothing.

The actual config I am trying to test with, before simplifying further:

homekit:
- name: testha
  filter:
    include_entities: 
      - switch.shed_heating

(Didn’t work)

Also, fails when not using a list ‘-’ , for example:

homekit:
  name: testha
  filter:
    include_entities: 
      - switch.shed_heating

Update;

Followed Manu3b’s advice and deleted the entry from .storage/.core.config_entries then rebooted. Fixed the issue, however its worth mentioning that when I used a list to define the entry (ie where you have more than one HomeKit bridge) it didn’t work.

ie:

homekit:
- name: testha
  filter:

didn’t work - but this did:

homekit:
  name: testha
  filter:

looks like rebooting and clearing out the old config is essential.

Thanks :). Worked perfectly.