Apple Home Key - working GitHub

Has anyone else seen the following repo: https://github.com/kormax/apple-home-key-reader. This would be amazing if it could be ported onto a Pi or even better an ESP32 (possibly underpowered for encryption libraries?).

I’m picturing a reader that would be able to communicate back to HA to run a script on successful “unlock”. In my case, I would print a 3d case and mount outside. Then using only my Apple Watch or iPhone, would be able to run a script to disarm, unlock my garage door, and open the garage door.

Interesting! bdraco has a credit near the bottom of the readme, so it seems like at least some of the core HA devs might already be at least peripherally aware of this effort.

@bdraco made a fork, so they’re definitely aware of the project.

Regarding the RPi support - it works from the get go, there are already a couple of people who have reported successfully running the project on their Raspberry Pis.

1 Like

That is very exciting, I think this has great potential. I hope someone smarter than me is able to “package-ize” this and design a nice 3d-printable case for it

My thought is to use a PoE-powered RPi and place on my external wall near the garage door. Easy snake an Ethernet cable out, and with a weather-proof enclosure it might even get WAAF approval!

1 Like

I’m also very interested in this. It would be awesome to have this integrated in ESPHome, and then link it to a door lock in the HA HomeKit config of the accessory, and then use some sort of linked_homekey_sensor where it could be any sensor entity under the ESPHome device that has the HomeKey capabilities.

That way, the two devices are basically the same from HomeKits perspective, and there would have so be some sort of key sharing or something between HA and the ESPHome device.

Possible useful code for the ESPHome bit: GitHub - rednblkx/HomeKey-ESP32

1 Like

We are getting closer! GitHub - rednblkx/HAP-ESPHome: HomeKit for ESPHome

I have a functioning HomeKey device that syncs the state from my Z-Wave lock. After I paired the device to both HomeKit and HA, I had to go the device config in the ESPHome integration to allow it to control HomeAssistant devices.

Here’s the library: GitHub - rednblkx/HAP-ESPHome: HomeKit for ESPHome

Here’s the setup/wiring instructions: Prerequisites · rednblkx/HomeKey-ESP32 Wiki · GitHub

Here is my device config for a ESPHome based HomeKit HomeKey device:

substitutions:
  name: "Example Door"
  esphome_name: example-door-homekey
  id: example_door_homekey
  ha_entity_id: "example_door_lock"
  setup_code: '111-11-111'
  
esphome:
  name: ${esphome_name}
  friendly_name: "${name} HomeKey"

external_components:
  - source:
      type: git
      url: https://github.com/rednblkx/HAP-ESPHome
      ref: main
    components: [ homekit, homekit_base, pn532, pn532_spi ]

# Enable Home Assistant API
api:

ota:
  - platform: esphome

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

logger:
  # hardware_uart: UART0
  level: DEBUG

# Lock Status
text_sensor:
  - platform: homeassistant
    id: "${id}_state"
    name: "${name} State"
    entity_id: ${ha_entity_id}
    internal: True
    on_value:
      then:
        lambda: |-
          if(x == "locked" && id(${id}).state == esphome::lock::LockState::LOCK_STATE_UNLOCKED) {
            id(${id}).lock();
            ESP_LOGI("HA Text Sensor", "Locking ESP Lock via HA");
          }
          else if(x == "unlocked" && id(${id}).state == esphome::lock::LockState::LOCK_STATE_LOCKED) {
            id(${id}).unlock();
            ESP_LOGI("HA Text Sensor", "Unlocking ESP Lock via HA");
          }

lock:
  - platform: template
    id: ${id}
    name: "${name} HomeKey"
    optimistic: True
    on_lock:
      - homeassistant.service:
          service: lock.lock
          data:
            entity_id: ${ha_entity_id}
      - logger.log: "${name} Locked!"
    on_unlock:
      - homeassistant.service:
          service: lock.unlock
          data:
            entity_id: ${ha_entity_id}
      - logger.log: "${name} Unlocked!"

# HomeKey
spi:
  clk_pin: 18
  miso_pin: 19
  mosi_pin: 23

pn532_spi:
  id: nfc_spi_module
  cs_pin: 5
  update_interval: 100ms

esp32:
  board: esp32dev
  flash_size: 4MB
  framework:
    type: esp-idf
    version: 5.2.1
    platform_version: 6.7.0
    sdkconfig_options:
      CONFIG_COMPILER_OPTIMIZATION_SIZE: y
      CONFIG_LWIP_MAX_SOCKETS: "16"
      CONFIG_LOG_DEFAULT_LEVEL_ERROR: y
      CONFIG_LOG_DEFAULT_LEVEL: "1"
      CONFIG_LOG_MAXIMUM_LEVEL_INFO: y
      CONFIG_LOG_MAXIMUM_LEVEL: "3"
      CONFIG_MBEDTLS_HKDF_C: y

button:
  - platform: homekit_base
    factory_reset:
      name: "Reset HomeKit pairings"

homekit_base:
  setup_code: ${setup_code}

homekit:
  lock:
    - id: ${id}
      nfc_id: nfc_spi_module
      on_hk_success:
        - lock.unlock: ${id}
      on_hk_fail:
        lambda: |-
          ESP_LOGI("GSDGSGS", "IT FAILED :(");
      hk_hw_finish: "SILVER"
2 Likes

Hi,
Thank you for your effort and support so far.
Will try to follow your code this weekend.
Did you add this nfc into esphome under HA?

Thanks Andrew