Home Assistant custom integration that follows a location entity (your phone
via the Companion App, a Tile tracker — anything with latitude/longitude
attributes), finds the nearest Redmond, WA traffic camera,
and keeps a fresh photo of it.
Input is any device_tracker/person entity. Output is a photo,
exposed three ways so you can wire it to anything with normal HA automations:
camera.nearest_traffic_camera— live image entity (dashboard cards,camera.snapshot, casting)sensor.nearest_camera— camera name; its state changes when you pass a new camera (great automation trigger). Attributes:camera_id,distance_km,image_url,image_pathsensor.distance_to_nearest_camera— km to the current camera- The JPEG is also written to
config/www/traffic_cam/current.jpg, served at/local/traffic_cam/current.jpg - Event
traffic_cam_nearest_new_imagefires whenever the server returns a photo body (not for an HTTP 304 unchanged response) withcamera_id,description,distance_km,camera_changed,image_path,local_url
Every N seconds (default 10, configurable 5–60):
- Read lat/lon from your chosen entity
- Find the nearest camera by great-circle distance (camera list comes from Redmond's public ArcGIS API — both the city layer and the external WSDOT/Bellevue layer — cached and refreshed daily)
- Revalidate that camera's current JPEG with ETag/Last-Modified, reuse cached bytes on HTTP 304, and rewrite the local JPEG only when its bytes change
- HACS → three-dot menu → Custom repositories → add this repo URL, type Integration
- Install Nearest Traffic Camera, restart Home Assistant
- Settings → Devices & Services → Add Integration → Nearest Traffic Camera
- Pick your phone's
device_trackerentity and an interval
The integration polls the entity every 10 s, but the Companion App only reports location every few minutes by default. Turn on high accuracy mode while driving, e.g.:
automation:
- alias: "Traffic cam: high accuracy while driving"
triggers:
- trigger: state
entity_id: sensor.your_phone_detected_activity
to: "in_vehicle"
actions:
- action: notify.mobile_app_your_phone
data:
message: command_high_accuracy_mode
data:
command: turn_on(and a mirror automation with turn_off when activity leaves in_vehicle).
automation:
- alias: "Upload nearest-camera photo"
triggers:
- trigger: event
event_type: traffic_cam_nearest_new_image
actions:
- action: shell_command.upload_photo # or any notify/REST action
data:
path: "{{ trigger.event.data.image_path }}"