Skip to content

kevinschweikert/homex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Homex

This library aims to bring Elixir (and especially Nerves) closer to Home Assistant. This is a work in progress based on the initial idea.

Example

There is a Livebook example example.livemd to get you started!

Installation

If available in Hex, the package can be installed by adding homex to your list of dependencies in mix.exs:

def deps do
  [
    {:homex, "~> 0.1.0"}
  ]
end

Usage

Define a module for the type of entity you want to use

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

  def handle_on(entity) do
    IO.puts("Switch turned on")
    entity
  end

  def handle_off(entity) do
    IO.puts("Switch turned off")
    entity
  end
end

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

import Config

config :homex,
  broker: [host: "localhost", port: 1883],
  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

Contribution

PRs and Feedback are very welcome!

Acknowledgements and Inspiration

About

A bridge between Elixir and Homeassistant

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages