README.md

# Ex-ZWave

__Credits__: Most of the code comes from https://github.com/derekkraan/domolixir, 🙏 thanks to him.

__⚡DISCLAIMER__: This is driver is experimental. Do not use it in production or your house will burn like hell! 

## ⚙️ Installation

The package can be installed
by adding `zwave` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:zwave, git: "https://github.com/laibulle/ex-zwave.git"}
  ]
end
```

## 🏁 Basic usage

__Listener__

```elixir
defmodule MyListener do
  @moduledoc """
  DemoListener module.
  """
  require Logger

  use GenServer

  def start_link(_) do
    GenServer.start_link(__MODULE__, [])
  end

  @impl true
  def init([]) do
    {:ok, %{listeners: []}}
  end

  @impl true
  def handle_cast({:event, event}, state) do
    Logger.info("#{event.node_identifier}: #{event.event_type}")

    {:noreply, state}
  end
end
```

```elixir
{:ok, pid} = ZWave.DemoListener.start_link([])
ZWave.EventBus.register(pid)
```


__Start a network__

```elixir
ZWave.start("/dev/tty.usbmodem142401", "stick1") 
```

__Send a command to a node__

```elixir
ZWave.send_command("stick1", "node_3", {:basic_set, 1}) 
```

__Get node informations__

```elixir
ZWave.get_node_info("stick1", "node_3") 

%{
  __struct__: ZWave.Node,
  alive: true,
  basic_class: 4,
  capabilities: 211,
  command_class_modules: [ZWave.Association, ZWave.Basic, ZWave.Unsupported, ZWave.SwitchAll],
  command_classes: [133, 32, 37, 39, 39, 37, 32],
  frequent_listening: 0,
  generic_class: 16,
  generic_key: "0x10",
  generic_label: "Binary Switch",
  initialized: true,
  label: "Binary Power Switch",
  listening: 128,
  name: :stick1,
  node_id: 3,
  number_association_groups: nil,
  specific_class: 1,
  specific_key: "0x01",
  specific_label: nil,
  total_errors: 0
}
```

__Get node values__

```elixir
ZWave.send_command("stick1", "node_2", {:basic_get}) 


%{
  __struct__: ZWave.Node,
  alive: true,
  basic_class: 4,
  capabilities: 211,
  command_class_modules: [ZWave.Association, ZWave.Basic, ZWave.Unsupported, ZWave.SwitchAll],
  command_classes: [133, 32, 37, 39, 39, 37, 32],
  frequent_listening: 0,
  generic_class: 16,
  generic_key: "0x10",
  generic_label: "Binary Switch",
  initialized: true,
  label: "Binary Power Switch",
  listening: 128,
  name: :stick1,
  node_id: 3,
  number_association_groups: nil,
  specific_class: 1,
  specific_key: "0x01",
  specific_label: nil,
  total_errors: 0
}
```

__Run demo__

```
iex -S mix run -e "Demo.run(\"/dev/tty.usbmodem142401\")"
```

## Resources

  * https://clemovernet.wordpress.com/2015/07/27/z-wave-presentation-du-protocole-domotique/