UnifiApi.Protect.Cameras (UnifiApi v0.4.0)

Copy Markdown View Source

UniFi Protect API — camera management.

List, view, update cameras, capture snapshots, and control PTZ.

Camera fields

  • id, modelKey, name, mac
  • state"CONNECTED", "CONNECTING", or "DISCONNECTED"
  • isMicEnabled, micVolume
  • osdSettings, ledSettings, lcdMessage
  • activePatrolSlot, videoMode, hdrType
  • featureFlags, smartDetectSettings

Updatable fields

  • name, osdSettings, ledSettings, lcdMessage
  • micVolume, videoMode, hdrType, smartDetectSettings

Summary

Functions

Gets a specific camera by ID.

Lists all cameras.

Moves the camera to a PTZ preset slot.

Starts a PTZ patrol on the given slot.

Stops the current PTZ patrol.

Takes a camera snapshot. Returns JPEG binary data.

Updates camera settings.

Functions

get(client, id)

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

Gets a specific camera by ID.

Examples

{:ok, camera} = UnifiApi.Protect.Cameras.get(client, camera_id)
camera["name"]  # => "Front Door"
camera["state"] # => "CONNECTED"

list(client, opts \\ [])

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

Lists all cameras.

Options

  • :raw — when true, return the raw response body binary (skips JSON decoding). Useful when streaming large camera lists or feeding the body to a custom decoder.

Examples

{:ok, cameras} = UnifiApi.Protect.Cameras.list(client)

{:ok, raw_binary} = UnifiApi.Protect.Cameras.list(client, raw: true)

ptz_goto(client, id, slot)

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

Moves the camera to a PTZ preset slot.

Examples

{:ok, _} = UnifiApi.Protect.Cameras.ptz_goto(client, camera_id, 1)

ptz_patrol_start(client, id, slot)

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

Starts a PTZ patrol on the given slot.

Examples

{:ok, _} = UnifiApi.Protect.Cameras.ptz_patrol_start(client, camera_id, 0)

ptz_patrol_stop(client, id)

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

Stops the current PTZ patrol.

Examples

{:ok, _} = UnifiApi.Protect.Cameras.ptz_patrol_stop(client, camera_id)

snapshot(client, id, opts \\ [])

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

Takes a camera snapshot. Returns JPEG binary data.

Options

  • :high_quality — request a high-quality snapshot (boolean)

Examples

# Standard quality
{:ok, jpeg} = UnifiApi.Protect.Cameras.snapshot(client, camera_id)
File.write!("snapshot.jpg", jpeg)

# High quality
{:ok, jpeg} = UnifiApi.Protect.Cameras.snapshot(client, camera_id, high_quality: true)

update(client, id, body)

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

Updates camera settings.

Examples

{:ok, _} = UnifiApi.Protect.Cameras.update(client, camera_id, %{
  name: "Front Door",
  micVolume: 80,
  videoMode: "highFps",
  ledSettings: %{isEnabled: false}
})