Skip to content

This is a server script for unlocking the auto-lock of an apartment using Switch Bot's Bot.

License

Notifications You must be signed in to change notification settings

nglcobdai/auto-unlock-server

Repository files navigation

auto-unlock-server

This is a script for unlocking the auto-lock of an apartment using Switch Bot's Bot.
It triggers when the room's intercom sounds, performs pass-phrase authentication, and presses the unlock button.
It is intended to be used in combination with Auto Unlock App.

License LICENSE
Environment Ubuntu
Docker Docker Compose
CUDA Python
Technology Poetry FastAPI MongoDB
OpenAI-Whisper SwitchBot API

Requirements

  • Docker and docker-compose are required. The versions are as follows.

    • Docker: v26.0.2
    • Docker Compose: v2.22.0
  • Nvidia Driver is required for CUDA 12.1.

  • Whisper model is used. Please refer to the official github for the device requirements.

Getting Started

1. Clone & Prepare .env

$ git clone -b v1.1.1 https://github.com/nglcobdai/auto-unlock-server.git
$ cd auto-unlock-server

2. Create .env & Set Environment Variables

copy .env.example to .env

$ cp .env.example .env.prod

edit .env.prod

You need to edit the following items

Key Description Reference
SWITCH_BOT_TOKEN Switch Bot Token Switch Bot
SWITCH_BOT_SECRET Switch Bot Secret Switch Bot
UNLOCK_BOT_ID Bot ID for Unlock button Refer to the output of python server/src/switch_bot.py
CALL_BOT_ID Bot ID for Call button Refer to the output of python server/src/switch_bot.py
MONGODB_USER_NAME MongoDB User Name Any value can be set
MONGODB_USER_PWD MongoDB User Password Any value can be set
DATADRIVE Data Drive MongoDB information storage directory
SECRET_PHRASE Secret Phrase Set any password to unlock

3. Docker Build & Run

$ docker-compose -f docker-compose.prod.yml --env-file .env.prod up --build -d

4. Server Start

$ docker exec -it auto-unlock-server-prod-1 uvicorn server.main:server --host 0.0.0.0 --port 8000

5. Access

Open other terminal and move to the project directory.

$ cd auto-unlock-server

Trigger Call Bot

$ curl --noproxy 127.0.0.1 -X POST https://127.0.0.1:8000/v1.1/unlock

Trigger Unlock Bot

$ curl --noproxy 127.0.0.1 -X POST -F "file=@./sample/test.wav" https://127.0.0.1:8000/v1.1/unlock