This project is an AI-powered solution for monitoring and managing the state of a garage door using image classification, MQTT, and integration with Home Assistant.
-
Image Classification:
- Uses TensorFlow/Keras to classify whether the garage door is
open
orclosed
based on uploaded images.
- Uses TensorFlow/Keras to classify whether the garage door is
-
Home Assistant Integration:
- Publishes the door state via MQTT with auto-discovery for seamless integration into Home Assistant.
-
Web Interface:
- User-friendly interface to upload images for prediction.
- Live retraining logs displayed during model retraining.
-
Model Retraining:
- Ability to retrain the model directly from the web interface with dataset updates.
- Dataset management for categorized (
open
/closed
) images.
-
Automated Cleanup:
- Removes old images from the dataset and upload directories to optimize disk space.
- Installation
- Environment Variables
- Usage
- Home Assistant Setup
- Retraining the Model
- MQTT Topics
- Contributing
- License
-
Clone the repository:
git clone https://github.com/GerryCrooked/garage-door-state.git cd garage-door-state
-
Build and start the Docker container:
docker-compose up -d
-
Access the web interface at:
http://<your-server-ip>:5000
Create a .env
file in the root directory and define the following variables:
# MQTT Configuration
MQTT_HOST=<your-mqtt-broker-ip>
MQTT_PORT=1883
MQTT_USER=<your-mqtt-username>
MQTT_PASSWORD=<your-mqtt-password>
# Device Configuration
TOPIC=homeassistant/binary_sensor/garage_door_status
CONFIG_TOPIC=homeassistant/binary_sensor/garage_door_status/config
STATE_TOPIC=homeassistant/binary_sensor/garage_door_status/state
SENSOR_NAME=Garage Gate Open/Close Sensor
DEVICE_ID=garage_gate_status_sensor
DEVICE_NAME=Garage Gate
DEVICE_MODEL=ARES1500
DEVICE_MANUFACTURER=BFT
# Timezone
TZ=Europe/Berlin
# Web Server Port
PORT=5000
- Use the web interface to upload images for prediction.
- The system will classify the image as
open
orclosed
and publish the result to the MQTT broker.
- Visit the
/last_prediction
page to view the most recent prediction and the associated image.
- Move images to
open
orclosed
categories via the/action/<action>/<filename>
endpoint. - Download or clear the dataset as needed via the web interface.
This project supports MQTT auto-discovery, so minimal setup is required in Home Assistant. Ensure MQTT is configured correctly in Home Assistant.
The device and binary sensor will automatically appear with the following properties:
- Device Name:
Garage Gate
- Entity:
binary_sensor.garage_gate_status
- State:
open
orclosed
If auto-discovery fails, add the following to your configuration.yaml
:
binary_sensor:
- platform: mqtt
name: "Garage Gate Status"
state_topic: "homeassistant/binary_sensor/garage_door_status/state"
payload_on: "open"
payload_off: "closed"
device_class: "door"
Use the following automation to take a snapshot of a camera and upload it to the server:
automation:
- alias: Upload Garage Camera Snapshot
description: Takes a screenshot of the garage camera and uploads it to the server
trigger:
- platform: time_pattern
minutes: "/1" # Run every minute
action:
- service: camera.snapshot
target:
entity_id: camera.garage_camera # Replace with your camera entity
data:
filename: /config/www/garage_snapshot.jpg
- service: shell_command.upload_garage_snapshot
Add this to your configuration.yaml
under the shell_command
section:
shell_command:
upload_garage_snapshot: >
if [ -f /config/www/garage_snapshot.jpg ]; then
rm /config/www/garage_snapshot.jpg;
fi && curl -X POST -F "file=@/config/www/garage_snapshot.jpg" http://<your-server-ip>:5000
- Use the
/retrain
endpoint to start retraining the model. - Logs are displayed live on the
/last_prediction
page.
- Add new images to the
dataset/open
anddataset/closed
directories. - Run the retraining script:
python retrain.py /app/model/garage_door_model.keras
Topic | Description |
---|---|
homeassistant/binary_sensor/garage_door_status/config |
Auto-discovery configuration |
homeassistant/binary_sensor/garage_door_status/state |
Current state of the door |
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or fix.
- Submit a pull request.
This project is licensed under the MIT License. See the LICENSE
file for details.