Just finished building a system that announces when Amazon, UPS, or FedEx enters my driveway! I am not a programmer, so I must admit I was pretty happy with myself getting this working. It leverages an RTSP camera feed and custom yolov8 model and MQTT to send to OpenHAB, which uses Alexa to announce the carrier entering.
The images for the model:
https://drive.google.com/file/d/1UwB89XpKy_sEIj_V9jTaCbs_B3RPsrwl/view?usp=sharing
To train the model:
yolo task=detect model=train model=yolov8x.pt imgsz=640 data=data.yaml epochs=128 batch=32 name=Delivery
Model Inference yolo.py:
import paho.mqtt.client as mqttClient
import time
from ultralytics import YOLO
# Load a pretrained YOLOv8n model
model = YOLO('yolov8x.pt')
# Define path to video file
source = 'rtsp://10.88.64.102:7447/iTRNax6vQJlyyBFN'
# Broker callback
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to broker")
global Connected
Connected = True
else:
print("Connection failed")
Connected = False
# Broker info
broker_address= "10.88.64.4"
port = 1883
client = mqttClient.Client("Marge")
client.on_connect=on_connect
# Connect to OpenHab MQTT
client.connect(broker_address, port=port)
client.loop_start()
time.sleep(1)
# Run inference on the source
results = model.predict(source, stream=True, imgsz=1280, verbose=False, conf=0.75) # generator of Results objects
for result in results:
boxes = result.boxes.cpu().numpy()
for box in boxes:
conf = box.conf[0]
cls = box.cls[0]
if cls==0.0:
carrier = "Amazon"
elif cls==1.0:
carrier = "UPS"
elif cls==2.0:
carrier = "Fedex"
print(carrier, conf)
client.publish("/driveway/delivery",carrier)
My things:
Thing mqtt:topic:delivery "Delivery Vehicles" (mqtt:broker:mosquitto) {
Channels:
Type string : carrier "Delivery Vehicles" [ stateTopic="/driveway/delivery" ]
}
My items:
String Carrier "Delivery Carrier" {channel="mqtt:topic:delivery:carrier"}
Switch Carrier_Entering {expire="30s"}
My rules:
rule "Carrier Entering"
when
Item Carrier received update
then
sendCommand(Carrier_Entering, ON)
end
rule "Announce Carrier"
when
Item Carrier_Entering changed from UNDEF to ON
then
logInfo("Driveway", Carrier.state.toString)
Alexa_TTS.sendCommand(Carrier.state.toString)
end
Well that’s about it, I am sure there are lots of ways to clean this up, but it works for me.