A robust Home Assistant integration for gate detection using advanced texture pattern analysis.
Lighting-independent detection that adapts to different environmental conditions by analyzing texture patterns within the gate area.
| Feature | Description |
|---|---|
| π Lighting Independent | Uses texture patterns instead of color values |
| π§ Perspective Correction | Automatic 4-point ROI perspective correction |
| π― Adaptive Calibration | Learns closed gate patterns from multiple samples |
| β‘ Real-time Detection | Fast texture analysis for live video streams |
| π§ Pattern Matching | LBP, edge analysis, and statistical features |
| π Temporal Smoothing | Reduces false positives through history analysis |
| π HA Integration | Native binary sensor and diagnostic entities |
| πΉ RTSP Support | Optimized for IP cameras with low latency |
Quick Setup Steps:
- π Open HACS β Integrations
- βοΈ Three dots β Custom repositories
- β Add:
https://github.com/Da4ndo/OpenGate - π Category: Integration
- π Search & Install "OpenGate Detection"
- π Restart Home Assistant
# Copy integration files
cp -r custom_components/opengate_detection /config/custom_components/
# Restart Home AssistantPath: Settings β Devices & Services β Add Integration β OpenGate Detection
Required Configuration:
- πΉ Camera URL:
rtsp://user:pass@192.168.1.100:554/stream1 - β±οΈ Detection Interval:
1.0seconds - π― Confidence Threshold:
0.8(0.0-1.0) - π Pattern Similarity:
0.85(0.0-1.0)
The camera URL is the most critical configuration parameter. Here's how to configure it correctly:
Format: rtsp://[username]:[password]@[ip_address]:[port]/[stream_path]
| Camera Brand | URL Format Example |
|---|---|
| Hikvision | rtsp://admin:password123@192.168.1.100:554/Streaming/Channels/101 |
| Dahua | rtsp://admin:password123@192.168.1.100:554/cam/realmonitor?channel=1&subtype=0 |
| Reolink | rtsp://admin:password123@192.168.1.100:554/h264Preview_01_main |
| Tapo/TP-Link | rtsp://admin:password123@192.168.1.100:554/stream1 |
| Generic IP Camera | rtsp://user:pass@192.168.1.100:554/stream1 |
Format: http://[ip_address]:[port]/[stream_path]
- MJPEG Stream:
http://192.168.1.100:8080/video.mjpg - HTTP Stream:
http://admin:password@192.168.1.100/cgi-bin/mjpg/video.cgi
For locally connected USB cameras, use the device index:
- Primary USB Camera:
0 - Secondary USB Camera:
1 - Third USB Camera:
2
-
Check Camera Manual/Web Interface:
- Login to camera's web interface
- Look for "RTSP" or "Streaming" settings
- Note the stream path and port
-
Common RTSP Ports:
- 554 (standard RTSP port)
- 8554 (alternative RTSP port)
-
Test Your URL:
# Test with VLC or ffplay vlc rtsp://user:pass@192.168.1.100:554/stream1 # or ffplay rtsp://user:pass@192.168.1.100:554/stream1
| Issue | Solution |
|---|---|
| Authentication Failed | Double-check username/password in camera settings |
| Connection Timeout | Verify IP address and port are correct |
| Stream Not Found | Check stream path in camera documentation |
| Firewall Blocking | Ensure RTSP port (554) is open |
β οΈ Critical: System requires calibration before accurate detection
# Step 1: Set ROI (Region of Interest)
service: opengate_detection.set_roi
target:
entity_id: binary_sensor.gate_state
data:
points: "[[100,100], [300,100], [300,250], [100,250]]"
# Step 2: Calibrate (with gate CLOSED)
service: opengate_detection.recalibrate
target:
entity_id: binary_sensor.gate_state
data:
samples: 10| Entity | Type | Description |
|---|---|---|
binary_sensor.gate_state |
Binary Sensor | π’ ON = Open / π΄ OFF = Closed |
sensor.gate_detection_confidence |
Sensor | Detection confidence (0-100%) |
sensor.gate_pattern_similarity |
Sensor | Pattern similarity score (0-100%) |
Available Attributes:
confidence- Detection confidence levelsimilarity_score- Pattern matching scoreedge_density_ratio- Edge analysis resulttexture_variance_ratio- Texture analysis resultlast_detection- Timestamp of last detection
| Brand | URL Format |
|---|---|
| Hikvision | rtsp://user:pass@ip:554/Streaming/Channels/101 |
| Dahua | rtsp://user:pass@ip:554/cam/realmonitor?channel=1&subtype=0 |
| Generic | rtsp://user:pass@ip:554/stream1 |
- HTTP/MJPEG:
http://192.168.1.100:8080/stream - USB Cameras:
0,1,2, etc.
graph LR
A[Camera Feed] --> B[ROI Extraction]
B --> C[Texture Analysis]
C --> D[Pattern Matching]
D --> E[Temporal Smoothing]
E --> F[Gate State]
Analysis Features:
- π Local Binary Patterns (LBP) - Texture pattern capture
- β‘ Edge Density Analysis - Edge detection metrics
- π Texture Variance - Homogeneity analysis
- π Shannon Entropy - Information content measurement
- π Gradient Analysis - Directional texture features
β High Similarity β Gate CLOSED
β Low Similarity β Gate OPEN
π History Analysis β Noise reduction
| vs Color Detection | OpenGate Advantage |
|---|---|
| π Lighting Changes | β Lighting Independent |
| π Shadow Problems | β Shadow Tolerant |
| π¨ Material Dependent | β Material Agnostic |
| π Angle Sensitive | β Perspective Robust |
| π¦οΈ Weather Issues | β Weather Resistant |
β οΈ Calibration Issues
- β Gate Position: Ensure gate is fully closed during calibration
- π ROI Points: Verify points accurately cover the gate area
- π‘ Lighting: Provide stable lighting during calibration
- π Multiple Samples: Use 10+ samples for better accuracy
π¨ Detection Problems
- π‘ Connectivity: Check camera stream quality and connection
- βοΈ Thresholds: Adjust similarity/confidence if too sensitive
- π ROI Validation: Verify ROI points match current camera view
- π Recalibration: Re-run calibration if environment changed
β‘ Performance Issues
- π Detection Interval: Increase interval (reduce frequency)
- π» Resources: Ensure adequate CPU/memory for image processing
- πΉ Stream Quality: Lower resolution if processing is slow
- π― ROI Size: Smaller ROI = faster processing
Built with Home Assistant Best Practices:
- ποΈ Config Flow - UI-based setup
- π DataUpdateCoordinator - Efficient data fetching
- π·οΈ Device Registry - Proper entity management
- π Error Handling - Comprehensive logging
| Resource | Link |
|---|---|
| π Bug Reports | GitHub Issues |
| π¬ Discussions | GitHub Discussions |
| π Contributing | Contributing Guidelines |
| π License | BSD 3-Clause License |
Made with β€οΈ by @Da4ndo