Overview
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
Architecture
Hardware Setup
Components
Raspberry Pi 4/5
Main controller running Edge API
Relay Module
3.3V-compatible, optocoupled (active-low)
Electric Strike
12V fail-secure strike or maglock
Power Supply
Separate 12V PSU for the lock
Wiring
Complete Implementation
1. Raspberry Pi Edge API
Setup
Edge API Code
Createedge_api.py:
Run Edge API
Test Edge API
2. Lua Agent Implementation
Environment Variables
src/tools/CheckAccessTool.ts
src/tools/UnlockDoorTool.ts
src/tools/RegisterGuestTool.ts
src/index.ts
Uses LuaAgent with preprocessors for rate limiting and security validation.
2. WhatsApp Channel Setup
1
Deploy Your Agent
2
Connect WhatsApp
- Phone Number ID (from Meta Business Suite)
- WhatsApp Business Account ID
- Access Token
3
Configure Webhook
Copy the webhook URL provided by Lua CLIIn Meta Business Suite → WhatsApp → Configuration:
- Add webhook URL
- Subscribe to
messagesevents - Verify webhook
4
Test
Send a WhatsApp message to your business number:
- “Open front door”
WhatsApp Setup Guide
Complete WhatsApp channel setup instructions
Guest Management
Register a Guest (Staff Operation)
Uselua test to register guests:
- Phone: +14155551234
- Name: John Doe
- Building ID: hotel-abc
- Doors: [“front”, “garage”]
- Start: 1735660800000 (epoch ms for check-in)
- End: 1735833600000 (epoch ms for check-out)
- Status: ACTIVE
Security Best Practices
✅ Always Verify Access
✅ Always Verify Access
Never unlock without checking permissions
✅ Time Window Validation
✅ Time Window Validation
Check current time is within access windowGuests table includes
startAt and endAt epoch timestamps.
Query ensures current time is within window.✅ Rate Limiting
✅ Rate Limiting
Prevent abuse with rate limits
- Server-side: 2-second minimum between unlocks
- PreProcessor: Max 3 unlock requests per minute
- Audit log: Track all attempts
✅ Audit Logging
✅ Audit Logging
Log every unlock attempt
✅ Hardware Safety
✅ Hardware Safety
Electrical safety is critical
- Use separate 12V PSU for lock (never from Pi)
- Optocoupled relay for isolation
- Flyback diode across lock coil
- Keep unlock pulses short (2-5s)
- Fail-secure locks (locked when unpowered)
Alternative: Twilio WhatsApp Webhook
If using Twilio instead of Meta’s WhatsApp Business API:src/webhooks/twilio-whatsapp.ts
Conversation Flows
Guest with Valid Access
Guest without Access
Staff Registering Guest
Production Deployment
Run Edge API on Boot
Create/etc/systemd/system/door-edge.service:
Set Static IP for Pi
PI_BASE_URL to use the static IP.
Monitoring & Audit
View Unlock Logs
View Active Guests
Key Features
WhatsApp Control
Guests unlock doors via WhatsApp messages
Time-Window Access
Check-in/check-out time validation
Multi-Door Support
Control multiple doors with different pins
Audit Trail
Complete logs of all unlock attempts
Rate Limiting
Prevent abuse with preprocessor filtering
Staff Tools
Register and manage guest access
WhatsApp Best Practices
See complete WhatsApp guidelines: WhatsApp Channel GuideUse Cases
- Hotels
- Apartments
- Coworking
- Vacation Rentals
Guest Room Access
- Check-in: Register guest with room access
- Guest WhatsApps: “Open room 305”
- Check-out: Access automatically expires
buildingId per locationTroubleshooting
Door doesn't unlock
Door doesn't unlock
Check:
- Edge API is running:
curl http://raspberrypi.local:5001/health - GPIO permissions: User in gpio group, logged back in
- Relay wiring: Correct pins, proper power supply
- Active-low setting: Try toggling
ACTIVE_LOW
Access denied for valid guest
Access denied for valid guest
Check:
- Guest is in database:
Data.get('guests') - Time window is current: startAt < now < endAt
- Status is ACTIVE
- Building ID matches
- Phone number format matches (E.164)
WhatsApp not responding
WhatsApp not responding
Check:
- Agent deployed:
lua deploy - WhatsApp channel connected:
lua channels - Webhook verified in Meta Business Suite
- Check logs:
lua logs
Rate limiting too aggressive
Rate limiting too aggressive
Adjust:
- Increase time window in PreProcessor (60000ms → 120000ms)
- Increase max attempts (3 → 5)
- Adjust server-side throttle in edge_api.py (2s → 5s)
Next Steps
View All IoT Demos
See all Raspberry Pi examples
WhatsApp Setup
Complete WhatsApp channel guide
Data API
Learn about guest data management
PreProcessor API
Learn about rate limiting and filtering

