This project is to detect which cars are in my garage as well as if the garbage bins are present. I use a simple object detection model along with an IP Camera in my garage. I publish the state as bianry sensors for use in HomeAssistant. The images used for training are here: https://app.roboflow.com/egge-public/garage/overview
The script uses a rolling average to determine if the object is present or absent, and also skips updating if it detects a person, as they may be obscuring something. I also trained it to recongize my toolbucket. This is a sort of sanity / calibration check. If it finds nothing in the scene, it's likely a system problem, so it shouldn't update the state of the objects.
![image](https://private-user-images.githubusercontent.com/175930/305052802-ee8b9e05-b508-479b-9ac7-670228d3a32f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE1MjgwODIsIm5iZiI6MTcyMTUyNzc4MiwicGF0aCI6Ii8xNzU5MzAvMzA1MDUyODAyLWVlOGI5ZTA1LWI1MDgtNDc5Yi05YWM3LTY3MDIyOGQzYTMyZi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzIxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcyMVQwMjA5NDJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hMDg4N2U0ZTI0NjNiNWVjYWQ5ZWMyOGU2Y2U2MzAyZmQ3ZWRlYTVmY2I2NDE0OTE1MTA1NmY4NzRhOTc1ODMxJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.dJt1n6rFfPdHECP-xF09lf0B_B9K7Rlk6V4dd4Kbkhc)
Linux Install
sudo apt install libsystemd-dev
python3 -m venv .
. bin/activate
pip install -r requirements.txt
Install service
$ cat /etc/systemd/system/garbage_bin_detector.service
[Unit]
Description=Image processor to find the garbage bin
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=egge
WorkingDirectory=/home/egge/garbage_bin/flask
ExecStart=/home/egge/garbage_bin/flask/simple.py
[Install]
WantedBy=multi-user.target
You need to create a config file, example:
[file]
path=/mnt/capture
[camera]
user=admin
password=*****
host=garage-cam.home
[mqtt]
host=mqtt
port=1883
In HomeAssistant I have a dashboard showing my garage (along with a camera view)
Here is one of my automations, which closes my garage door after I leave:
alias: Garage Close Civic departs
description: "Close left garage door after departure "
trigger:
- platform: state
entity_id:
- person.brian
to: not_home
from: home
condition:
- condition: state
entity_id: binary_sensor.honda_civic
state: "off"
- condition: state
entity_id: cover.garage_door_left
state: open
action:
- service: cover.close_cover
target:
entity_id:
- cover.garage_door_left
data: {}
- wait_for_trigger:
- platform: state
entity_id:
- cover.garage_door_left
to: closed
timeout: "60"
- service: notify.mobile_app_brians_iphone_x
data:
message: Garage door left is {{ states('cover.garage_door_left') }}
data:
entity_id: camera.garage_cam
url: /lovelace-mobile/garage/
mode: single
The arriving home automations are a bit more complicated, because I might be driving either car. If both cars are away, I'm driving the Civic. If the Civic is present, I'm driving the CRV.