grizzly v0.8.5 Grizzly View Source
Grizzly functions for controlling Z-Wave devices and the Z-Wave network.
Sending commands to Z-Wave
The most fundamental function in Grizzly
is Grizzly.send_command/3
.
There are two ways of using this function.
First, by passing in a node id for a node on the network:
Grizzly.send_command(10, Grizzly.CommandClass.SwitchBinary.Get)
{:ok, :on}
Grizzly.send_command(10, Grizzly.CommandClass.SwitchBinary.Set, value: :off)
This is useful for short lived deterministic communication like iex
and scripts. This is because there is the overhead of connecting and
disconnecting to the node for each call.
For long lived applications that have non-deterministic sending of
messages (some type of automated commands) and user expectations on
device action we recommend using this function by passing in a
Grizzly.Node
, Grizzly.Conn
, or Grizzly.Controller
.
{:ok, zw_node} = Grizzly.get_node(10)
{:ok, zw_node} = Grizzly.Node.connect(zw_node)
{:ok, :on} = Grizzly.send_command(zw_node, Grizzly.CommandClass.SwitchBinary.Get)
:ok = Grizzly.send_command(zw_node, Grizzly.CommandClass.SwitchBinary.Set, value: :on)
This is useful because we maintain a heart beat with the node and overhead
of establishing the connection is removed from send_command
.
In order for the consumer of Grizzly to use this in a long running application they will need to hold on to a reference to the connected Z-Wave Node.
To know more commands and their arguments see the modules under the
Grizzly.CommandClass
name space.
Subscribing to Z-Wave messages
Grizzly
has a pubsub module (Grizzly.Notifications
) which is used for
sending or receiving notifications to and from Grizzly
.
You can subscribe to notifications using:
Grizzly.subscribe(topic)
This will subscribe the calling process to the supplied topic. So, if you
are using iex
you can see received messages with flush
, although it would
be most useful from a GenServer
where you can use handle_info
to handle
the notifications.
The available topics are:
:controller_connected,
:connection_established,
:unsolicited_message,
:node_added,
:node_removed,
:node_updated
You can also Grizzly.Notifications
directly, where there are additional and
more useful functions available.
Link to this section Summary
Types
A type the represents things the have/can establish connections to the Z/IP network.
Functions
Put network in inclusion mode
Put network out of inclusion mode
Close a connection
Get the command classes supported by a node.
Whether the node's command class versions are known
Whether a node is connected.
Get the version of a node's command class, if the node does not have a version for this command class this function will try to get it from the Z-Wave network.
Get a node from the network
List the nodes on the Z-Wave network
Whether a node has a given command class
Check to see if the network is busy
Check to see if the network is ready
Put network in exclusion mode
Put network out of exclusion mode
Reset the Z-Wave Module to a clean state
Send a command to the Z-Wave device, first checking if in inclusion/exclusion state.
Put the controller in learn mode for a few seconds
Subscribe to notifications about a topic
Update the command class version of a node
Link to this section Types
connected()
View Source
connected() :: Grizzly.Conn.t() | Grizzly.Controller | Grizzly.Node.t()
connected() :: Grizzly.Conn.t() | Grizzly.Controller | Grizzly.Node.t()
A type the represents things the have/can establish connections to the Z/IP network.
Conn.t
- A Connection structGrizzly.Controller
- The controller process, this is a global, started on application start processNode.t
- This is a Z-Wave Node that has been connected to the network
seq_number()
View Source
seq_number() :: 0..255
seq_number() :: 0..255
Link to this section Functions
add_node(opts \\ [])
View Source
add_node([Grizzly.Inclusion.opt()]) ::
:ok | {:error, {:invalid_option, Grizzly.Inclusion.invalid_opts_reason()}}
add_node([Grizzly.Inclusion.opt()]) :: :ok | {:error, {:invalid_option, Grizzly.Inclusion.invalid_opts_reason()}}
Put network in inclusion mode
add_node_stop()
View Source
add_node_stop() :: :ok
add_node_stop() :: :ok
Put network out of inclusion mode
close_connection(conn)
View Source
close_connection(Grizzly.Conn.t()) :: :ok
close_connection(Grizzly.Conn.t()) :: :ok
Close a connection
command_class_names(node)
View Source
command_class_names(Grizzly.Node.t()) :: [atom()]
command_class_names(Grizzly.Node.t()) :: [atom()]
Get the command classes supported by a node.
command_class_versions_known?(zw_node)
View Source
command_class_versions_known?(Grizzly.Node.t()) :: boolean()
command_class_versions_known?(Grizzly.Node.t()) :: boolean()
Whether the node's command class versions are known
config()
View Source
config() :: Grizzly.Conn.Config.t()
config() :: Grizzly.Conn.Config.t()
connected?(node)
View Source
connected?(Grizzly.Node.t()) :: boolean()
connected?(Grizzly.Node.t()) :: boolean()
Whether a node is connected.
get_command_class_version(node, command_class_name)
View Source
get_command_class_version(Grizzly.Node.t(), atom()) ::
{:ok, non_neg_integer()} | {:error, atom()}
get_command_class_version(Grizzly.Node.t(), atom()) :: {:ok, non_neg_integer()} | {:error, atom()}
Get the version of a node's command class, if the node does not have a version for this command class this function will try to get it from the Z-Wave network.
get_node(node_id)
View Source
get_node(Grizzly.Node.node_id()) :: {:ok, Grizzly.Node.t()} | {:error, any()}
get_node(Grizzly.Node.node_id()) :: {:ok, Grizzly.Node.t()} | {:error, any()}
Get a node from the network
This does not make a DTLS connection to the Node.t()
and if you want to connect to the node use Grizzly.Node.connect/1
.
get_nodes()
View Source
get_nodes() :: {:ok, [Grizzly.Node.t()]} | {:error, :unable_to_get_node_list}
get_nodes() :: {:ok, [Grizzly.Node.t()]} | {:error, :unable_to_get_node_list}
List the nodes on the Z-Wave network
has_command_class?(node, command_class_name)
View Source
has_command_class?(Grizzly.Node.t(), atom()) :: boolean()
has_command_class?(Grizzly.Node.t(), atom()) :: boolean()
Whether a node has a given command class
network_busy?()
View Source
network_busy?() :: boolean()
network_busy?() :: boolean()
Check to see if the network is busy
network_ready?()
View Source
network_ready?() :: boolean()
network_ready?() :: boolean()
Check to see if the network is ready
remove_node(opts \\ [])
View Source
remove_node([Grizzly.Inclusion.opt()]) :: :ok
remove_node([Grizzly.Inclusion.opt()]) :: :ok
Put network in exclusion mode
remove_node_stop() View Source
Put network out of exclusion mode
reset_controller()
View Source
reset_controller() :: {:ok, atom()} | {:error, :network_busy}
reset_controller() :: {:ok, atom()} | {:error, :network_busy}
Reset the Z-Wave Module to a clean state
send_command(connected, command_module, command_opts \\ []) View Source
Send a command to the Z-Wave device, first checking if in inclusion/exclusion state.
See individual command modules for information about what options it takes.
start_learn_mode(opts \\ [])
View Source
start_learn_mode([Grizzly.Inclusion.opt()]) :: :ok
start_learn_mode([Grizzly.Inclusion.opt()]) :: :ok
Put the controller in learn mode for a few seconds
subscribe(topic)
View Source
subscribe(Grizzly.Notifications.topic()) :: :ok | {:error, :already_subscribed}
subscribe(Grizzly.Notifications.topic()) :: :ok | {:error, :already_subscribed}
Subscribe to notifications about a topic
See Grizzly.Notifications
for more information
update_command_class_versions(zw_node)
View Source
update_command_class_versions(Grizzly.Node.t()) :: Grizzly.Node.t()
update_command_class_versions(Grizzly.Node.t()) :: Grizzly.Node.t()
Update the command class version of a node