IAction est un service web qui analyse des images/flux vidéo avec l’IA et publie des capteurs dans Home Assistant via MQTT.
Principales capacités:
- Détection IA sur images en continu (RTSP) ou images fournies par Home Assistant (HA Polling)
- Détections personnalisées (prompt) avec webhook optionnel par détection
- MQTT Auto-Discovery (capteurs de performance, binaire « capture en cours », capteurs par détection)
- Interface web pour démarrer/arrêter, gérer les détections et afficher le flux live
- Page d’administration pour configurer le
.env(IA, MQTT, RTSP/HA)
- UI:
templates/index.html+static/app.js - Admin:
templates/admin.html+static/admin.js - Backend Flask:
app.py - Services:
services/(caméra RTSP, HA Polling, IA, MQTT, détections)
- Python 3.10+
- Home Assistant (facultatif mais recommandé, pour MQTT/HA Polling)
- Broker MQTT accessible (ex: Mosquitto)
- OpenCV, Flask, Paho MQTT, Requests, OpenAI SDK (via
requirements.txt)
Installation des dépendances:
python -m venv .venv
. .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txtCopiez .env.example vers .env puis renseignez selon votre usage.
- IA générale
AI_API_MODE=openai|lmstudio|ollamaAI_TIMEOUT(s)- OpenAI:
OPENAI_API_KEY,OPENAI_MODEL(ex: gpt-4o) - LM Studio:
LMSTUDIO_URL,LMSTUDIO_MODEL - Ollama:
OLLAMA_URL,OLLAMA_MODEL
- MQTT / Home Assistant
MQTT_BROKER,MQTT_PORT,MQTT_USERNAME,MQTT_PASSWORDHA_DEVICE_NAME,HA_DEVICE_ID
- Mode de capture
CAPTURE_MODE=rtsp|ha_polling- RTSP:
DEFAULT_RTSP_URL,RTSP_USERNAME,RTSP_PASSWORD - HA Polling:
HA_BASE_URL,HA_TOKEN,HA_ENTITY_ID,HA_IMAGE_ATTR,HA_POLL_INTERVAL
- Analyse
MIN_ANALYSIS_INTERVAL(s)
Vous pouvez configurer ces paramètres depuis l’interface /admin (écrit le fichier .env).
python app.py --debug # ou simplement: python app.pyPar défaut: http://localhost:5002
- Configurez votre IA + MQTT + mode de capture dans
/admin. - Sur la page d’accueil, démarrez la capture.
- Ajoutez des détections (nom + phrase) et, si besoin, un webhook.
- Affichez/masquez le flux live sans interrompre la capture.
-
RTSP (recommandé)
- Implémentation:
services/camera_service.py - Flux MJPEG en direct via
/video_feed - Reconnexion auto, latence réduite (BUFFERSIZE=1, MJPEG)
- Implémentation:
-
HA Polling (images via API Home Assistant)
- Implémentation:
services/ha_service.py - Récupère l’URL d’image de l’entité (ex:
camera.xxx), anti-cache, déduplication
- Implémentation:
Créés par services/mqtt_service.py:
- Metrics exposées via
/api/metrics:last_analysis_time(timestamp)analysis_duration(s)analysis_total_interval(s)analysis_total_fps(FPS)
- Binary sensors:
capture_active(ON/OFF)- Un binary sensor par détection personnalisée
- Config & statut
GET /api/configGET /api/status(global),GET /api/metrics(léger)GET /api/capture_status
- Caméras & capture
GET /api/cameras,POST /api/cameras/refresh,GET /api/cameras/<id>POST /api/start_capture(type:rtspouha_polling)POST /api/stop_captureGET /video_feed
- Détections
GET /api/detections,POST /api/detectionsPUT|PATCH /api/detections/<id>,DELETE /api/detections/<id>
- Administration
GET /api/admin/config,POST /api/admin/configGET /api/admin/ai_test,GET /api/admin/mqtt_test,POST /api/admin/rtsp_testPOST /api/admin/restart
- Vérifiez la connexion MQTT (badge dans
/adminou logs CLI). Variables:MQTT_BROKER,MQTT_PORT. - Si l’IA timeoute, augmentez
AI_TIMEOUT. Testez depuis/admin→ « Tester IA ». - RTSP: vérifiez l’URL, les identifiants et que la caméra est joignable. Test rapide via
/admin→ « Tester RTSP ». - Logs CLI configurables via
LOG_LEVEL(DEBUG/INFO/WARNING/ERROR).
- Dépendances: voir
requirements.txt - Code principal:
app.pyetservices/ - UI:
templates/etstatic/
Contributions bienvenues via issues/PR.