Automated oil tank level monitoring using UniFi Protect camera and Claude AI vision analysis.
- 📷 Grabs snapshots from UniFi Protect camera
- 🤖 Analyzes oil gauge using Claude AI vision
- 📊 Logs all readings to CSV file
- 📧 Email alerts when oil drops below 25%
- 💾 Saves all snapshots to
images/directory
python3 -m venv .venv
source .venv/bin/activate
pip install anthropic python-dotenv Pillow requestsCreate a .env file with:
# UniFi Protect Configuration
UNIFI_HOST=your-unifi-host
UNIFI_API_KEY=your-api-key
CAMERA_ID=your-camera-id
# Anthropic API
ANTHROPIC_API_KEY=your-anthropic-api-key
# Email/SMTP Configuration (optional - defaults to localhost:25)
SMTP_SERVER=localhost
SMTP_PORT=25- Log into UniFi Protect web interface
- Go to Settings → Integrations
- Create a new API key
- Copy the key to
UNIFI_API_KEYin.env
python3 list_cameras.pyCopy the ID of your oil gauge camera to CAMERA_ID in .env.
- Go to https://console.anthropic.com/settings/keys
- Create a new API key
- Add billing/credits if needed
- Copy to
ANTHROPIC_API_KEYin.env
python3 check_oil_level.pyThis will:
- Grab a snapshot from the camera
- Analyze the gauge with Claude
- Save the image to
images/ - Log the reading to
oil_level_log.csv - Send email alert if oil is below 25%
Add to crontab to check daily at 8 AM:
crontab -eAdd:
0 8 * * * cd /Users/jgoulah/dev/oil-notifier && /Users/jgoulah/dev/oil-notifier/.venv/bin/python3 check_oil_level.py
Edit check_oil_level.py to change the alert threshold (default: 25%):
ALERT_THRESHOLD = 25 # Alert when oil level drops below this percentageEmail alerts are sent to jgoulah@gmail.com by default. To change, edit:
ALERT_EMAIL = "your-email@example.com"check_oil_level.py- Main scriptlist_cameras.py- List available camerasget_camera_snapshot.py- Helper for camera snapshotsoil_level_log.csv- Reading historyimages/- Snapshot storagetest/- Test and diagnostic scripts.env- Configuration (not in git)
The script uses localhost SMTP by default. To use an external SMTP server, add to .env:
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=your-email@gmail.com
SMTP_PASSWORD=your-app-passwordThen update the script to use authentication.
The system is calibrated for readings within ±5-10%. If readings are consistently off:
- Check camera angle hasn't changed
- Review saved images in
images/directory - Adjust crop coordinates if needed (see
test/crop_gauge.py)
- UniFi Protect API: Free
- Anthropic Claude Sonnet: ~$0.01-0.02 per reading
- Daily checks: ~$0.30-0.60/month