# Door Bot This repository helps you setup a Delta Chat bot to open your doors via chat. The bot will be running on a Raspberry Pi. To open your downstairs door, it needs to be connected to your doorbuzzer. To open your upstairs door, it needs to talk via bluetooth to an Eqiva mechanical lock. ## Material - Raspberry Pi Zero W (e.g. ) - Eqiva Mechanical Lock: - A 5V relais module (e.g. ) ## Mounting the Eqiva Mechanical Lock to the upstairs door Following the instructions, mount the mechanical lock to your door. **Warning:** From the inside, it needs a key to be permanently in the lock, so make sure you have a lock which can still be opened from the outside if there is already a key on the inside, or you can only enter your door through the mechanical lock. Otherwise you need to buy a lock. Feel free to test the unlocker with the official app; with the bot you will not need it anymore, though. ## Flash the Raspberry Pi ``` sudo apt install rpi-imager rpi-imager ``` Select your Device, OS, and Storage. In my case: - Device: Raspberry Pi Zero - Operating System: Raspberry Pi OS (32-bit) - Storage: /dev/mm.... (whatever the raspi's SD card is called on your system) Then click "Next", and "Edit Settings": - Set Wifi SSID + Password to your local WIFI network - Enable Key-based SSH authentication to "user" with an ed25519 key - Hostname: r8.local Add to your /home/user/.ssh/config: ``` Host r8 Hostname 192.168.0.12 # adjust the local IP User user IdentityFile /home/user/.ssh/id_ed25519 ``` ## Store the keyblepy secrets in pass In order to enter pairing mode, press and hold the "Unlock" button on the Eqiva until the yellow light flashes. Then register the user: ``` cd keyble ./keyble.py --register --qrdata --user-name doorbot --user-key --verbose ``` This is how you get the variables (you should store them in [pass](https://www.passwordstore.org/)): - `pass edit r8/keyblepy/qr_data`: scan the QR code on the key card with Delta Chat, use the text - `pass edit r8/keyblepy/user_key`: generate a 32-character hexadecimal string - `pass edit r8/keyblepy/user_id`: 0 if the raspi is your only device, 1 if you have an additional app configured. - `pass edit r8/keyblepy/device_address`: the Eqiva's Bluetooth MAC address, best you scan for it with the laptop. The device is called `KEY-BLE`. ## Setup pyinfra and deploy the bot on the Raspberry Pi ``` python3 -m venv venv . venv/bin/activate pip install pyinfra pyinfra r8 deploy.py ``` ## Get the invite link of the bot ``` ssh r8 sudo systemctl stop doorbot . .local/lib/eqiva.venv/bin/activate python3 bot.py admin sudo systemctl start doorbot ``` The `python3 bot.py admin` command prints the invite link; join the group with your Delta profile. Write `/open2` to the chat, to test whether the upstairs door unlocks. ## Connect door buzzer of downstairs door - Connect some 5V DC power, e.g. from a USB charger, to the DC+ and DC- ports - From your Raspberry Pi's GPIO 26 pin (see pin layout here: https://www.etechnophiles.com/raspberry-pi-zero-gpio-pinout-specifications-programming-language/) connect a cable to the relais module's IN port - Open up the casing of your door buzzer - Solder the relais module's COM, NC, and NO ports to the door buzzer, in a way that makes the downstairs door open on high current Now write `/open` to the chat to test whether the downstairs door unlocks.