xerosanyam/ha-traffic-cam

★ 0Forks 0PythonGitHub ↗Compare

README

Nearest Traffic Camera

2026-07-17

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_path
  • sensor.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_image fires whenever the server returns a photo body (not for an HTTP 304 unchanged response) with camera_id, description, distance_km, camera_changed, image_path, local_url

How it works

Every N seconds (default 10, configurable 5–60):

  1. Read lat/lon from your chosen entity
  2. 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)
  3. 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

Install (HACS)

  1. HACS → three-dot menu → Custom repositories → add this repo URL, type Integration
  2. Install Nearest Traffic Camera, restart Home Assistant
  3. Settings → Devices & Services → Add Integration → Nearest Traffic Camera
  4. Pick your phone's device_tracker entity and an interval

Getting real 10-second updates while driving (Android)

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).

Example: upload every new photo somewhere

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 }}"

Contributors

xerosanyam

Issues