This project explores an event-driven approach to route monitoring: use a vehicle event to check relevant routes, then send a concise notification when conditions meet a defined threshold.
Traffic Manager monitors predefined routes with the Google Maps Routes API, sends notifications through Discord and Gotify, and uses MQTT messages from a vehicle ignition system as its trigger.
The system is event-driven. When my vehicle's ignition turns on, a GPS tracker publishes an MQTT message to a local broker. Traffic Manager subscribes to that topic and uses it as the trigger to run a traffic check: no point querying traffic at 2am when you're not driving.
# Simplified MQTT listener
client.subscribe("vehicle/+/ignition")
def on_message(client, userdata, msg):
payload = json.loads(msg.payload)
if payload["state"] == "on":
check_all_routes()
Each route is stored in PostgreSQL with a name, priority level, and a list of waypoints in DMS (Degrees Minutes Seconds) coordinates. When a check is triggered, the system queries the Google Maps Routes API for each route and evaluates the result against a dynamic threshold.
This was the trickiest part. A five-minute delay on a 10-minute commute is a big deal. The same delay on a 90-minute journey is barely worth mentioning. A fixed "alert if delay exceeds X minutes" threshold doesn't hold up across different route lengths.
The solution was to calculate thresholds proportionally based on route distance and typical travel time. The system also analyses individual segments, not just the total journey, so it can distinguish between one bad bottleneck and distributed light congestion.
Routes are flagged as either high priority or normal priority. High-priority routes always generate alerts when conditions are bad. Normal-priority routes only alert if the delay is significant, which prevents notification fatigue for optional commutes.
Alerts go out through two channels simultaneously:
Beyond automated alerts, there's an interactive Discord bot for managing the system without touching the database directly. It uses modals for adding routes, lets you update priority levels, check current traffic on demand, and adjust detection sensitivity, all from a Discord slash command.
The project demonstrates how explicit priorities, event-driven checks, and targeted notifications can make a monitoring workflow more useful than a one-size-fits-all alert.