Files
unifi-access-dashboard/README.md

115 lines
3.2 KiB
Markdown
Raw Normal View History

2026-03-04 19:53:39 -06:00
# UniFi Access Badge-In Dashboard (V3)
2026-03-04 17:45:28 -06:00
2026-03-04 19:42:38 -06:00
A Dockerised Flask + SQLite web app that receives UniFi Access `access.door.unlock` webhooks,
2026-03-04 19:53:39 -06:00
resolves UUIDs to real user names via the UniFi Access API, and displays a modern dark
attendance dashboard with on-time / late status, first + latest badge times, and a test reset button.
2026-03-04 19:42:38 -06:00
---
2026-03-04 17:45:28 -06:00
## Features
2026-03-04 19:53:39 -06:00
- Receives webhooks from the UniFi Access developer API or legacy Alarm Manager format.
- Resolves UUIDs to real names via the UniFi Access REST API (cached in SQLite, refreshed every 6 hrs).
- **First badge in** column — never overwritten by subsequent badges.
- **Latest badge in** column — shows the most recent entry that day.
- **Sync Users** button — manually refreshes the user name cache.
- **Reset Day** button — confirmation modal deletes all records for the selected date (testing only).
- Green ON TIME / Red LATE status chips based on a configurable cutoff time.
- Fully Dockerised — single container, persistent SQLite volume.
2026-03-04 19:42:38 -06:00
---
## Project layout
2026-03-04 17:45:28 -06:00
2026-03-04 19:42:38 -06:00
```
.
2026-03-04 19:53:39 -06:00
├── app.py
2026-03-04 19:42:38 -06:00
├── requirements.txt
├── Dockerfile
├── docker-compose.yml
2026-03-04 19:53:39 -06:00
├── .env.example
2026-03-04 19:42:38 -06:00
├── .gitignore
└── static/
2026-03-04 19:53:39 -06:00
└── index.html
2026-03-04 19:42:38 -06:00
```
2026-03-04 17:45:28 -06:00
2026-03-04 19:42:38 -06:00
---
2026-03-04 17:45:28 -06:00
2026-03-04 19:53:39 -06:00
## Setup
2026-03-04 17:45:28 -06:00
2026-03-04 19:53:39 -06:00
### 1. Generate a UniFi Access API token
2026-03-04 17:45:28 -06:00
2026-03-04 19:53:39 -06:00
1. Open UniFi OS → UniFi Access → Settings → Integrations / Developer API.
2. Create a new API Key (Bearer Token) and copy it.
2026-03-04 17:45:28 -06:00
2026-03-04 19:53:39 -06:00
### 2. Create your .env file
2026-03-04 17:45:28 -06:00
```bash
2026-03-04 19:42:38 -06:00
cp .env.example .env
2026-03-04 19:53:39 -06:00
# edit .env and fill in UNIFI_HOST and UNIFI_API_TOKEN
2026-03-04 19:42:38 -06:00
```
2026-03-04 19:53:39 -06:00
### 3. Register the webhook with UniFi Access (run once)
2026-03-04 17:45:28 -06:00
```bash
2026-03-04 19:42:38 -06:00
curl -k -X POST "https://192.168.1.1:45/api1/webhooks/endpoints" \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-H "Content-Type: application/json" \
-d '{
"name": "Dashboard Unlock Events",
"endpoint": "http://YOUR_UNRAID_IP:8000/api/unifi-access",
"events": ["access.door.unlock"],
"headers": { "X-Source": "unifi-access" }
}'
2026-03-04 17:45:28 -06:00
```
2026-03-04 19:53:39 -06:00
Verify registration:
2026-03-04 17:45:28 -06:00
2026-03-04 19:42:38 -06:00
```bash
curl -k -X GET "https://192.168.1.1:45/api1/webhooks/endpoints" \
-H "Authorization: Bearer YOUR_TOKEN_HERE"
```
2026-03-04 19:53:39 -06:00
### 4. Deploy on Unraid
2026-03-04 17:45:28 -06:00
```bash
cd /mnt/user/appdata
git clone https://github.com/<your-user>/<your-repo>.git unifi-access-dashboard
cd unifi-access-dashboard
2026-03-04 19:53:39 -06:00
cp .env.example .env && nano .env
2026-03-04 19:42:38 -06:00
docker compose up -d --build
2026-03-04 17:45:28 -06:00
```
2026-03-04 19:53:39 -06:00
Open: `http://<UNRAID-IP>:8000/`
2026-03-04 19:42:38 -06:00
2026-03-04 19:53:39 -06:00
### 5. Updating from GitHub
2026-03-04 17:45:28 -06:00
```bash
2026-03-04 19:53:39 -06:00
cd /mnt/user/appdata/unifi-access-dashboard
git pull
docker compose up -d --build
2026-03-04 17:45:28 -06:00
```
2026-03-04 19:42:38 -06:00
---
2026-03-04 17:45:28 -06:00
2026-03-04 19:53:39 -06:00
## API endpoints
2026-03-04 17:45:28 -06:00
2026-03-04 19:53:39 -06:00
| Method | Path | Description |
|---|---|---|
| POST | `/api/unifi-access` | Receives webhook from UniFi Access |
| GET | `/api/first-badge-status` | Returns first + latest badge per user for a date |
| GET | `/api/sync-users` | Triggers immediate user cache sync |
| DELETE | `/api/reset-day?date=YYYY-MM-DD` | Deletes all records for the given date |
2026-03-04 17:45:28 -06:00
2026-03-04 19:42:38 -06:00
---
## Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
2026-03-04 19:53:39 -06:00
| Names show as `Unknown (UUID…)` | Users not cached yet | Click Sync Users |
| Webhook not arriving | Firewall / port | Ensure port 8000 reachable from controller |
| SSL error on curl | Self-signed cert | Use `-k` flag |
| 404 on `/api1/users` | Firmware path differs | Try `/api/v1/users` |
| Duplicate events | Both Alarm Manager and API webhooks active | Remove one or deduplicate by event ID |