Shelly.CloudV2 (Shelly v0.3.0)

Copy Markdown View Source

Shelly Cloud v2 API, authorized by a per-account auth key (Shelly app → Settings → User Settings → Access And Permissions → "Get key" — the key and the server URI are shown together).

Takes a Shelly.Client holding an :auth_key (Shelly app → Settings → User Settings → Access And Permissions → "Get key").

Rate limit: ~1 request/second/account (paced via Shelly.RateGate when running). Status supports up to 10 devices per call.

Note: the v2 API takes the auth key as a query parameter (Shelly's design) — be aware that intermediary proxies may log query strings.

Summary

Functions

Bulk status for up to 10 device ids. Returns {:ok, %{device_id => element}} (lowercase ids); each element has "status", "code" (model), "gen", "online" — parse with Shelly.Status.parse/4

Control a cover: position is "open" | "close" | "stop" | 0..100.

Control a light: opts may include :on, :brightness, :temperature, :toggle_after.

Switch a relay on or off. toggle_after (seconds) asks Shelly's own cloud to revert the command later — a watchdog that survives your app going down.

Functions

get_statuses(conn, device_ids)

@spec get_statuses(Shelly.Client.t(), [String.t()]) ::
  {:ok, %{optional(String.t()) => map()}} | {:error, term()}

Bulk status for up to 10 device ids. Returns {:ok, %{device_id => element}} (lowercase ids); each element has "status", "code" (model), "gen", "online" — parse with Shelly.Status.parse/4:

Shelly.Status.parse(el["status"], channel, el["online"] in [1, true],
  %{model: el["code"], gen: Shelly.Status.gen_to_int(el["gen"])})

set_cover(conn, device_id, channel, position, opts \\ [])

@spec set_cover(
  Shelly.Client.t(),
  String.t(),
  non_neg_integer(),
  String.t() | non_neg_integer(),
  keyword()
) :: :ok | {:error, term()}

Control a cover: position is "open" | "close" | "stop" | 0..100.

set_light(conn, device_id, channel, opts \\ [])

@spec set_light(Shelly.Client.t(), String.t(), non_neg_integer(), keyword()) ::
  :ok | {:error, term()}

Control a light: opts may include :on, :brightness, :temperature, :toggle_after.

set_switch(conn, device_id, channel, on?, opts \\ [])

@spec set_switch(
  Shelly.Client.t(),
  String.t(),
  non_neg_integer(),
  boolean(),
  keyword()
) ::
  :ok | {:error, term()}

Switch a relay on or off. toggle_after (seconds) asks Shelly's own cloud to revert the command later — a watchdog that survives your app going down.