This project aims to convert a YKK AP electric lock with app control capabilities into a smart lock that can be controlled via iPhone's Home app, integrating it with Home Assistant and MQTT.
- Project Overview
- System Architecture
- Prerequisites
- Installation and Configuration
- Usage
- File Structure
- License
This project integrates a YKK AP electric lock with Home Assistant using an Android phone as a bridge. It allows for remote control and status monitoring of the door lock through MQTT and HomeKit.
graph TD
U((User)) -->|Operate| A[iPhone#40;HomeKit#41;]
A -->|Instruct| C{Home Assistant}
C -->|Configure| D[MQTT Lock Definition]
C <-->|Data Exchange| E{MQTT Server}
F[Docker Container] <-->|Subscribe/Publish| E
F -->|ADB Commands| G[Android Smartphone]
G -->|Bluetooth Control| H((YKK AP Electric Lock))
I[Door/Window Sensor] -.->|Optional| C
I -.->|State Detection| H
- Home Assistant server with HomeKit integration
- MQTT server (Broker address: mqtt://192.168.11.5:21883)
- Android phone with YKK AP's "スマートコントロールキー" app installed and paired with the door lock
- Docker environment for running the control script
- Clone this repository to your local machine.
- Set up the Android phone near the door lock and ensure it's always powered on.
- Configure the Docker environment:
- Update the
docker-compose.ymlfile with your specific settings:environment: - TZ=Asia/Tokyo - MQTT_BROKER=192.168.11.5 - MQTT_PORT=21883 - ADB_DEVICE=192.168.11.135:5555 - LOGGING_LEVEL=INFO
- Update the
- Install the necessary Python dependencies as specified in the Docker configuration.
- Update the
configuration.yamlfile in your Home Assistant setup:input_boolean: fake_door_lock_status: name: "Virtual Door Lock Status" icon: mdi:lock lock: - platform: template name: "Home Door Lock" value_template: "{{ is_state('input_boolean.fake_door_lock_status', 'on') }}" lock: service: script.lock_door unlock: service: script.unlock_door
- Update the
automations.yamlfile in your Home Assistant setup:- id: update-door-lock-status alias: Update Door Lock Status trigger: - platform: mqtt topic: home/doorlock/state action: - choose: - conditions: - condition: template value_template: "{{ trigger.payload == 'LOCKED' }}" sequence: - service: input_boolean.turn_on target: entity_id: input_boolean.fake_door_lock_status - conditions: - condition: template value_template: "{{ trigger.payload == 'UNLOCKED' }}" sequence: - service: input_boolean.turn_off target: entity_id: input_boolean.fake_door_lock_status
- Modify the
app_control.pyscript if needed to adjust settings like MQTT topics or check intervals.
- Start the Docker container using the provided
docker-compose.ymlfile. - The Python script (
app_control.py) will run automatically, handling communication between MQTT and the door lock. - Use your iPhone's Home app to control the door lock.
app_control.py: Main Python script for controlling the door lockdocker-compose.yml: Docker configuration filedoor-lock-state-flow.mermaid: Mermaid diagram of the control logicsystem_overview_diagram.mermaid: System architecture diagramconfiguration.yaml: Home Assistant configurationautomations.yaml: Home Assistant automationsscreenshot_*.png: Screenshots of the Android app in different states
This project is licensed under the MIT License - see the LICENSE.md file for details.