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:
def deps do
[
{:zwave, git: "https://github.com/laibulle/ex-zwave.git"}
]
end🏁 Basic usage
Listener
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{:ok, pid} = ZWave.DemoListener.start_link([])
ZWave.EventBus.register(pid)Start a network
ZWave.start("/dev/tty.usbmodem142401", "stick1") Send a command to a node
ZWave.send_command("stick1", "node_3", {:basic_set, 1}) Get node informations
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
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\")"