I’ve been leaving my keys in the outside lock by mistake. It’s terrifying to wake up and realize anyone could have just walked right in while I was asleep. 😱
So, I decided to create this service to monitor the interior lock for the presence of my keys and send me notifications otherwise if I'm not connected to the WIFI!
This works because when I'm home, I always leave the keys on the door lock, so if they are not there, must mean I'm not home or that I actually left them outside!
- A security camera that supports
RTSP(I use a TPlink/TAPO security camera) - A device that can serve as a server
- FFmpeg installed
I have my security camera looking to the door:
From the keys area, I defined an area where the keys should be visible, and for color comparaison, there is a control point to compare the colors with the keys area.
I get all pixels in that area and calculate the average color, ignoring those too close to the control point.
for y := startY; y >= endY; y-- {
for x := startX; x <= endX; x++ {
// Get the color of the pixel at the current position
pixelColor := img.At(x, y)
// Extract the RGB components
r, g, b, _ := pixelColor.RGBA()
if distance(r,g,b, controlPoint) < 10 {
// Ignore colors too close to the control point
// so later the comparator will be more precise.
continue;
}
}
}Since the keys are darker than the door, the difference between the control point should be noticeable.
// Calculate the difference between the avg and the control point colors
difference := distance(
avgR, avgB, avgG,
controlPoint
)
// if the color from the control point differs more than 5 points,
// then the keys are there.
keysThere := difference > 5
return keysThere, nilFor now, I just established a simple http server that prints a json with it 🤣
GET http://localhost:8090/status{
"keysInDoor": true
}
