Homex (homex v0.1.0)

View Source

Configuration

You can configure Homex through a normal config entry like

import Config

config :homex,
  broker: [host: "localhost", port: 1883],
  entities: [MyEntity]

The available options are documented in Homex.Config.

Usage

Define a module for the type of entity you want to use. The available types are:

defmodule MySwitch do
  use Homex.Entity.Switch, name: "my-switch"

  def handle_on(state) do
    IO.puts("Switch turned on")
    {:noreply, state}
  end

  def handle_off(state) do
    IO.puts("Switch turned off")
    {:noreply, state}
  end
end

Configure broker and entities. Entities can also be added/removed at runtime with Homex.add_entity/1 or Homex.remove_entity/1.

import Config

config :homex,
  entities: [MySwitch]

Add homex to you supervision tree

defmodule MyApp.Application do
  def start(_type, _args) do
    children =
      [
        ...,
        Homex,
        ...
      ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

Summary

Functions

add_entities(modules)

See Homex.Manager.add_entities/1.

add_entity(module)

See Homex.Manager.add_entity/1.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

connected?()

See Homex.Manager.connected?/0.

publish(topic, payload, opts)

See Homex.Manager.publish/3.

remove_entity(module)

See Homex.Manager.remove_entity/1.

start_link(init_arg \\ [])