Skip to content

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.

License

Notifications You must be signed in to change notification settings

Da4ndo/OpenGate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸšͺ OpenGate Detection - Home Assistant Integration

hacs GitHub Release GitHub Activity License

Project Maintenance

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.


✨ Key Features

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

πŸ“¦ Installation

πŸŽͺ HACS (Recommended)

Quick Setup Steps:

  1. 🏠 Open HACS β†’ Integrations
  2. βš™οΈ Three dots β†’ Custom repositories
  3. βž• Add: https://github.com/Da4ndo/OpenGate
  4. πŸ“‚ Category: Integration
  5. πŸ” Search & Install "OpenGate Detection"
  6. πŸ”„ Restart Home Assistant

πŸ“ Manual Installation

# Copy integration files
cp -r custom_components/opengate_detection /config/custom_components/
# Restart Home Assistant

βš™οΈ Configuration

πŸš€ Initial Setup

Path: Settings β†’ Devices & Services β†’ Add Integration β†’ OpenGate Detection

Required Configuration:

  • πŸ“Ή Camera URL: rtsp://user:pass@192.168.1.100:554/stream1
  • ⏱️ Detection Interval: 1.0 seconds
  • 🎯 Confidence Threshold: 0.8 (0.0-1.0)
  • πŸ“Š Pattern Similarity: 0.85 (0.0-1.0)

πŸ“Ή Camera URL Configuration

The camera URL is the most critical configuration parameter. Here's how to configure it correctly:

🌐 RTSP Cameras (Most Common)

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

πŸ“‘ HTTP/MJPEG Streams

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

πŸ”Œ Local USB Cameras

For locally connected USB cameras, use the device index:

  • Primary USB Camera: 0
  • Secondary USB Camera: 1
  • Third USB Camera: 2

πŸ” Finding Your Camera URL

  1. Check Camera Manual/Web Interface:

    • Login to camera's web interface
    • Look for "RTSP" or "Streaming" settings
    • Note the stream path and port
  2. Common RTSP Ports:

    • 554 (standard RTSP port)
    • 8554 (alternative RTSP port)
  3. 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

⚠️ Common Issues & Solutions

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

🎯 Calibration ⚠️ REQUIRED

⚠️ 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

πŸŽ›οΈ Entities Created

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 level
  • similarity_score - Pattern matching score
  • edge_density_ratio - Edge analysis result
  • texture_variance_ratio - Texture analysis result
  • last_detection - Timestamp of last detection

πŸ“Ή Camera Compatibility

🌐 RTSP Cameras (Recommended)

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

πŸ“‘ Alternative Sources

  • HTTP/MJPEG: http://192.168.1.100:8080/stream
  • USB Cameras: 0, 1, 2, etc.

πŸ”¬ How It Works

Texture Analysis Engine

graph LR
    A[Camera Feed] --> B[ROI Extraction]
    B --> C[Texture Analysis]
    C --> D[Pattern Matching]
    D --> E[Temporal Smoothing]
    E --> F[Gate State]
Loading

Analysis Features:

  1. πŸ” Local Binary Patterns (LBP) - Texture pattern capture
  2. ⚑ Edge Density Analysis - Edge detection metrics
  3. πŸ“Š Texture Variance - Homogeneity analysis
  4. πŸ“ˆ Shannon Entropy - Information content measurement
  5. πŸ“ Gradient Analysis - Directional texture features

Detection Logic

βœ… High Similarity β†’ Gate CLOSED
❌ Low Similarity β†’ Gate OPEN
πŸ“Š History Analysis β†’ Noise reduction


πŸ† Advantages

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

πŸ”§ Troubleshooting

⚠️ 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

πŸ‘¨β€πŸ’» Development Info

Built with Home Assistant Best Practices:

  • πŸŽ›οΈ Config Flow - UI-based setup
  • πŸ“Š DataUpdateCoordinator - Efficient data fetching
  • 🏷️ Device Registry - Proper entity management
  • πŸ” Error Handling - Comprehensive logging

🀝 Support & Contributing

Resource Link
πŸ› Bug Reports GitHub Issues
πŸ’¬ Discussions GitHub Discussions
πŸ“– Contributing Contributing Guidelines
πŸ“„ License BSD 3-Clause License

Made with ❀️ by @Da4ndo

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages