UnifiApi.Protect.Events (UnifiApi v0.4.0)

Copy Markdown View Source

UniFi Protect API — event log.

Returns motion, ring, smartDetect, and recording events emitted by Protect cameras and other devices. Use this for security automation ("when the front door rings, do X") or for ad-hoc forensics ("what motion was detected last Tuesday around midnight?").

Requires cookie + CSRF authentication. See UnifiApi.Auth.Cookie.

Event fields

  • id, type"motion", "ring", "smartDetectZone", "smartAudioDetect", "recording", "package"
  • start, end — unix milliseconds
  • score — confidence (0..100) for smart detections
  • camera, cameraId — source device
  • smartDetectTypes — list of "person", "vehicle", "animal", "package", "licensePlate" for smart events
  • thumbnail, heatmap — opaque IDs to fetch via thumbnail/3 (binary JPEG)

Summary

Functions

Returns a single event by id.

Lists events.

Returns Protect's system event log (firmware updates, NVR events, device adoption, etc. — distinct from camera events).

Returns the event thumbnail as a JPEG binary.

Functions

get(client, event_id)

@spec get(Req.Request.t(), String.t()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}

Returns a single event by id.

list(client, opts \\ [])

@spec list(
  Req.Request.t(),
  keyword()
) :: {:ok, term()} | {:error, UnifiApi.Error.t()}

Lists events.

Options

  • :start — window start, unix milliseconds.
  • :end — window end, unix milliseconds.
  • :types — filter to specific event types, list of strings.
  • :cameras — filter to specific camera ids, list of strings.
  • :limit — server-side cap.

Examples

# Last hour, motion only
hour_ago = (System.os_time(:millisecond) - 60 * 60 * 1000)

{:ok, events} = UnifiApi.Protect.Events.list(client,
  start: hour_ago, types: ["motion", "smartDetectZone"], limit: 100)

system_logs(client)

@spec system_logs(Req.Request.t()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}

Returns Protect's system event log (firmware updates, NVR events, device adoption, etc. — distinct from camera events).

thumbnail(client, event_id, opts \\ [])

@spec thumbnail(Req.Request.t(), String.t(), keyword()) ::
  {:ok, binary()} | {:error, UnifiApi.Error.t()}

Returns the event thumbnail as a JPEG binary.

Examples

{:ok, jpeg} = UnifiApi.Protect.Events.thumbnail(client, event_id)
File.write!("event.jpg", jpeg)