fritz_api v0.1.0 FritzApi View Source

API Client for the Fritz!Box Home Automation HTTP Interface

Link to this section Summary

Types

  • base: The base url of the fritzbox. Defaults to “http://fritz.box”
  • ssl: SSL options supported by the ssl erlang module

Functions

Get essential information of all smart home devices

Get the total energy usage (kWh) of the switch

Get the actuator identification numbers (AIN) of all known switches

Get the name of the actor

Get the current power consumption (Watt) of the switch

Get the current connection state of the actor

Get the current state of the switch

Get the last measured temperature (Celsius) of the actor

Link to this section Types

Link to this type opts() View Source
opts() :: [base: String.t, ssl: list]
  • base: The base url of the fritzbox. Defaults to “http://fritz.box”
  • ssl: SSL options supported by the ssl erlang module

Link to this section Functions

Link to this function get_device_list_infos(sid, opts \\ []) View Source
get_device_list_infos(String.t, opts) ::
  {:error, any} |
  {:ok, FritzApi.DeviceListInfos.t}

Get essential information of all smart home devices.

Example

iex> FritzApi.get_device_list_infos(sid)
{:ok, [%{
  ain: "687690315761",
  fwversion: "03.87",
  id: 21,
  manufacturer: "AVM",
  name: "FRITZ!DECT #1",
  powermeter: %{energy: 0.475, power: 0.0},
  present: true,
  productname: "FRITZ!DECT 200",
  switch: %{
    devicelock: false,
    lock: false,
    mode: "manuell",
    state: false
  },
  temperature: %{
    celsius: 23.5,
    offset: 0.0
  }
}]}
Link to this function get_session_id(username, password, opts \\ []) View Source
get_session_id(String.t, String.t, opts) ::
  {:error, any} |
  {:ok, String.t}

Get a session ID.

A valid session ID is required in order to interact with the FritzBox API.

Each application should only acquire a single session ID since the number of sessions to a FritzBox is limited.

In principle, each session ID has a validity of 60 Minutes whereby the validity period gets extended with every access to the API. However, if any application tries to access the API with an invalid session ID, all other sessions get terminated.

Example

iex> FritzApi.get_session_id("admin", "changeme")
{:ok, "879b972027084f61"}
Link to this function get_switch_energy(sid, ain, opts \\ []) View Source
get_switch_energy(String.t, String.t, opts) ::
  {:error, any} |
  {:ok, float}

Get the total energy usage (kWh) of the switch.

Example

iex> FritzApi.get_switch_energy(sid, "687690315761")
{:ok, 0.475}
Link to this function get_switch_list(sid, opts \\ []) View Source
get_switch_list(String.t, opts) ::
  {:error, any} |
  {:ok, [String.t]}

Get the actuator identification numbers (AIN) of all known switches.

Example

iex> FritzApi.get_switch_list(sid, opts)
{:ok, ["687690315761"]}
Link to this function get_switch_name(sid, ain, opts \\ []) View Source
get_switch_name(String.t, String.t, opts) ::
  {:error, any} |
  {:ok, String.t}

Get the name of the actor.

Example

iex> FritzApi.get_switch_name(sid, "687690315761")
{:ok, "FRITZ!DECT #1"}
Link to this function get_switch_power(sid, ain, opts \\ []) View Source
get_switch_power(String.t, String.t, opts) ::
  {:error, any} |
  {:ok, float}

Get the current power consumption (Watt) of the switch.

Example

iex> FritzApi.get_switch_power(sid, "687690315761")
{:ok, 0.0}
Link to this function get_switch_present(sid, ain, opts \\ []) View Source
get_switch_present(String.t, String.t, opts) ::
  {:error, any} |
  {:ok, :connected} |
  {:ok, :not_connected}

Get the current connection state of the actor.

Example

iex> FritzApi.get_switch_present(sid, "687690315761")
{:ok, :connected}
Link to this function get_switch_state(sid, ain, opts \\ []) View Source
get_switch_state(String.t, String.t, opts) ::
  {:error, any} |
  {:ok, :on} |
  {:ok, :off}

Get the current state of the switch.

Example

iex> FritzApi.get_switch_state(sid, "687690315761")
{:ok, :off}
Link to this function get_temperature(sid, ain, opts \\ []) View Source
get_temperature(String.t, String.t, opts) ::
  {:error, any} |
  {:ok, float}

Get the last measured temperature (Celsius) of the actor.

Example

iex> FritzApi.get_temperature(sid, "687690315761")
{:ok, 23.5}
Link to this function set_switch_off(sid, ain, opts \\ []) View Source
set_switch_off(String.t, String.t, opts) ::
  {:error, any} |
  :ok

Turn off the switch.

Example

iex> FritzApi.set_switch_off(sid, "687690315761")
:ok
Link to this function set_switch_on(sid, ain, opts \\ []) View Source
set_switch_on(String.t, String.t, opts) :: {:error, any} | :ok

Turn on the switch.

Example

iex> FritzApi.set_switch_on(sid, "687690315761")
:ok
Link to this function set_switch_toggle(sid, ain, opts \\ []) View Source
set_switch_toggle(String.t, String.t, opts) ::
  {:error, any} |
  {:ok, :on} |
  {:ok, :off}

Toggle the switch.

Example

iex> FritzApi.set_switch_toggle(sid, "687690315761")
{:ok, :off}