|
| 1 | +--- |
| 2 | +tags: |
| 3 | + - integration |
| 4 | + - manual |
| 5 | + - ai |
| 6 | + - docker |
| 7 | +--- |
| 8 | + |
| 9 | +# Integration: AI Log Reporter |
| 10 | + |
| 11 | +**Type:** Remote Docker Container |
| 12 | +**Host:** `10.0.0.23` |
| 13 | +**Language:** Python 3.11 |
| 14 | + |
| 15 | +## Overview |
| 16 | +The **AI Log Reporter** is an external system designed to offload heavy log analysis from the Home Assistant host. It runs in a Docker container on a separate server, allowing it to process large datasets without impacting HA performance. |
| 17 | + |
| 18 | +## Architecture |
| 19 | + |
| 20 | +The system works via a "Pull & Push" mechanism: |
| 21 | +1. **Trigger:** Home Assistant opens a secure SSH tunnel to the host. |
| 22 | +2. **Execution:** HA executes the python script inside the running container. |
| 23 | +3. **Callback:** The script analyzes the data and pushes the result back to Home Assistant via the API. |
| 24 | + |
| 25 | +```mermaid |
| 26 | +sequenceDiagram |
| 27 | + participant HA as 🏠 Home Assistant |
| 28 | + participant SSH as 🔐 SSH Tunnel |
| 29 | + participant Docker as 🐳 Docker (ai-log-reporter) |
| 30 | + participant API as 📡 HA API |
| 31 | +
|
| 32 | + HA->>SSH: Connect (Identity File) |
| 33 | + SSH->>Docker: exec python /app/reporter.py |
| 34 | + activate Docker |
| 35 | + Docker->>Docker: Analyze Logs & Generate Summary |
| 36 | + Docker->>API: POST /api/events/update_ai_summary |
| 37 | + deactivate Docker |
| 38 | +``` |
| 39 | + |
| 40 | +## Deployment |
| 41 | + |
| 42 | +### Docker Compose |
| 43 | +The system is deployed using a standard `docker-compose.yml` file on the remote host. |
| 44 | + |
| 45 | +```yaml |
| 46 | +version: '3.8' |
| 47 | +services: |
| 48 | + reporter: |
| 49 | + container_name: ai-log-reporter |
| 50 | + image: python:3.11-slim |
| 51 | + restart: unless-stopped |
| 52 | + volumes: |
| 53 | + - ./app:/app |
| 54 | + - ./logs:/logs:ro |
| 55 | + environment: |
| 56 | + - HA_URL=http://10.0.0.5:8123 |
| 57 | + - HA_TOKEN=klsjdflkjsdf... |
| 58 | + command: tail -f /dev/null # Keep alive for exec |
| 59 | +``` |
| 60 | +
|
| 61 | +### The Reporter Script |
| 62 | +The core logic resides in `reporter.py`. It uses the Gemini API to summarize text. |
| 63 | + |
| 64 | +```python |
| 65 | +# /app/reporter.py (Simplified) |
| 66 | +import requests |
| 67 | +import os |
| 68 | +
|
| 69 | +def analyze_logs(): |
| 70 | + # ... logic to read files ... |
| 71 | + summary = "System is stable. No critical errors found." |
| 72 | + |
| 73 | + # Send Event to HA |
| 74 | + url = f"{os.getenv('HA_URL')}/api/events/update_ai_summary" |
| 75 | + headers = {"Authorization": f"Bearer {os.getenv('HA_TOKEN')}"} |
| 76 | + requests.post(url, json={"summary": summary}, headers=headers) |
| 77 | +
|
| 78 | +if __name__ == "__main__": |
| 79 | + analyze_logs() |
| 80 | +``` |
| 81 | + |
| 82 | +## Related Components |
| 83 | +* **[Ai Summary Package](../packages/ai_summary.md)**: The Home Assistant configuration that triggers this integration. |
0 commit comments