Production-ready door access control system where guests WhatsApp your agent to open doors. Perfect for hotels, apartments, coworking spaces, or any building requiring secure access control.What it does:
Guests WhatsApp to unlock doors
Verify guest access permissions
Time-window access control
Audit logging of all unlocks
Staff tools for guest registration
Hardware: Raspberry Pi 4/5, relay module, 12V electric strike or maglockAPIs used: Lua WhatsApp channel + Edge API (Flask) + Lua Data API (guest management)
# Install dependencies (Raspberry Pi OS Bookworm)sudo apt updatesudo apt install -y python3-pip python3-venv python3-libgpiod# Add user to gpio group (allows GPIO without sudo)sudo adduser $USER gpio# Log out and back in for this to take effect# Create projectmkdir -p ~/door-edge && cd ~/door-edgepython3 -m venv .venvsource .venv/bin/activatepip install flask gpiozero
import { LuaAgent, LuaSkill, PreProcessor } from 'lua-cli';import CheckAccessTool from './tools/CheckAccessTool';import UnlockDoorTool from './tools/UnlockDoorTool';import RegisterGuestTool from './tools/RegisterGuestTool';// Door control skillconst doorSkill = new LuaSkill({ name: "door-control", description: "Secure door access control via Raspberry Pi", context: ` This skill controls building door access with strict security. Access Control Flow: 1. check_access: ALWAYS check first - verify phone has valid access 2. unlock_door: Only if check_access returns allowed=true 3. register_guest: Staff only - add or extend guest access Security Rules: - NEVER unlock without verifying access first - Check time windows (startAt/endAt) - Rate-limit repeated unlock attempts - Log all unlock events - Confirm which door before unlocking User Experience: - Ask which door if unclear ("front" or "garage") - Report unlock duration in response - Provide helpful error messages for denied access - Suggest contacting staff if no valid booking `, tools: [ new CheckAccessTool(), new UnlockDoorTool(), new RegisterGuestTool() ]});// Security preprocessor: Rate limitingconst rateLimitPreProcessor = new PreProcessor({ name: 'unlock-rate-limit', description: 'Prevent rapid repeated unlock attempts', priority: 1, execute: async (message, user) => { const text = message.content.toLowerCase(); // Check if message is about unlocking if (text.includes('unlock') || text.includes('open door')) { // Check recent unlock requests const recentUnlocks = await Data.search('door_logs', user.id, 10); const lastMinute = recentUnlocks.data.filter(log => { const logTime = new Date(log.data.timestamp).getTime(); return Date.now() - logTime < 60000; // Last minute }); if (lastMinute.length >= 3) { return { block: true, response: "You've made multiple unlock requests recently. Please wait a moment before trying again." }; } } return { block: false }; }});// Configure agent (v3.0.0)export const agent = new LuaAgent({ name: "door-assistant", persona: `You are a concise, security-focused door access assistant.Your role:- Verify guest access permissions before unlocking- Control door locks securely and safely- Maintain audit logs of all access- Provide clear feedback on access statusSecurity Protocol:1. Identify user by WhatsApp phone number2. If user asks to unlock/open door, ask which door if unclear3. ALWAYS call check_access first to verify permissions4. If allowed: call unlock_door and confirm success5. If denied: politely explain and suggest contacting staff6. Log every unlock attemptCommunication style:- Concise and professional- Security-conscious- Clear about access status- Helpful with denied requestsSafety rules:- NEVER unlock without valid access check- NEVER reveal GPIO pin numbers or internal config- Rate-limit rapid repeated requests- Confirm door name before unlocking- Report unlock duration in confirmationTypical responses:- Allowed: "✅ Front door unlocked. It will re-lock in 3 seconds."- Denied: "I don't have an active booking for your number. Please contact the front desk or provide your booking details."- Unclear: "Which door would you like to open? Front or garage?"When to escalate:- Guest has no valid booking- Access outside time window- Technical errors with lock- Multiple failed attempts`, skills: [doorSkill], preProcessors: [rateLimitPreProcessor]});
v3.0.0 Features: Uses LuaAgent with preprocessors for rate limiting and security validation.
Guest via WhatsApp: "Open door"Agent: I don't have an active booking for your number. Please contact the front desk with your booking confirmation, or provide your booking name and dates.
[Unit]Description=Door Control Edge APIAfter=network-online.targetWants=network-online.target[Service]User=piWorkingDirectory=/home/pi/door-edgeEnvironment=EDGE_API_KEY=supersecretEnvironment=DOOR_PIN=17Environment=ACTIVE_LOW=trueEnvironment=UNLOCK_MS=3000ExecStart=/home/pi/door-edge/.venv/bin/python edge_api.pyRestart=alwaysRestartSec=10[Install]WantedBy=multi-user.target