# Quick Matrix Alerting Setup ## Step 1: Get Matrix Account 1. Go to https://app.element.io or install Element app 2. Create account or login with existing Matrix account ## Step 2: Get Access Token ### Method 1: Element Web (Recommended) 1. Open Element in browser: https://app.element.io 2. Login to your account 3. Click Settings (gear icon) → Help & About → Advanced 4. Copy your "Access Token" (starts with `syt_...` or similar) ### Method 2: Command Line ```bash curl -X POST https://matrix.org/_matrix/client/v3/login \ -H "Content-Type: application/json" \ -d '{ "type": "m.login.password", "user": "your_username", "password": "your_password" }' ``` ## Step 3: Create Alert Room 1. In Element, click "+" to create new room 2. Name: "Water Level Alerts" 3. Set to Private 4. Copy the room ID from room settings (format: `!roomid:matrix.org`) ## Step 4: Configure .env File Add these to your `.env` file: ```bash # Matrix Alerting Configuration MATRIX_HOMESERVER=https://matrix.org MATRIX_ACCESS_TOKEN=syt_your_access_token_here MATRIX_ROOM_ID=!your_room_id:matrix.org # Grafana Integration (optional) GRAFANA_URL=http://localhost:3000 ``` ## Step 5: Test Configuration ```bash # Test Matrix connection uv run python run.py --alert-test # Check system status (shows Matrix config) uv run python run.py --status # Run alert check uv run python run.py --alert-check ``` ## Example Alert Message When thresholds are exceeded, you'll receive messages like: ``` 🌊 **WATER LEVEL ALERT** **Station:** P.1 (สถานีเชียงใหม่) **Alert Type:** Critical Water Level **Severity:** CRITICAL **Current Level:** 6.75m **Threshold:** 6.0m **Difference:** +0.75m **Discharge:** 450.2 cms **Time:** 2025-09-26 14:30:00 📈 View dashboard: http://localhost:3000 ``` ## Cron Job Setup (Optional) Add to crontab for automatic alerting: ```bash # Check water levels every 15 minutes */15 * * * * cd /path/to/monitor && uv run python run.py --alert-check >> alerts.log 2>&1 ``` ## Troubleshooting - **403 Error**: Check Matrix access token is valid - **Room Not Found**: Verify room ID includes `!` prefix and `:homeserver.com` suffix - **No Alerts**: Check database has recent data with `uv run python run.py --status`