grizzly v0.8.4 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 recevied 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 repersents 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

Link to this type

connected() View Source
connected() :: Grizzly.Conn.t() | Grizzly.Controller | Grizzly.Node.t()

A type the repersents things the have/can establish connections to the Z/IP network.

  1. Conn.t - A Connection struct
  2. Grizzly.Controller - The controller process, this is a global, started on application start process
  3. Node.t - This is a Z-Wave Node that has been connected to the network
Link to this type

seq_number() View Source
seq_number() :: 0..255

Link to this section Functions

Link to this function

add_node(opts \\ []) View Source
add_node([Grizzly.Inclusion.opt()]) ::
  :ok | {:error, {:invalid_option, Grizzly.Inclusion.invalid_opts_reason()}}

Put network in inclusion mode

Link to this function

add_node_stop() View Source
add_node_stop() :: :ok

Put network out of inclusion mode

Link to this function

close_connection(conn) View Source
close_connection(Grizzly.Conn.t()) :: :ok

Close a connection

Link to this function

command_class_names(node) View Source
command_class_names(Grizzly.Node.t()) :: [atom()]

Get the command classes supported by a node.

Link to this function

command_class_versions_known?(zw_node) View Source
command_class_versions_known?(Grizzly.Node.t()) :: boolean()

Whether the node's command class versions are known

Whether a node is connected.

Link to this function

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 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.

Link to this function

get_node(node_id) View Source
get_node(Grizzly.Node.node_id()) ::
  {:ok, Grizzly.Node.t()} | {:error, :node_not_found}

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.

Link to this function

get_nodes() View Source
get_nodes() :: {:ok, [Grizzly.Node.t()]} | {:error, :unable_to_get_nodes}

List the nodes on the Z-Wave network

Link to this function

has_command_class?(node, command_class_name) View Source
has_command_class?(Grizzly.Node.t(), atom()) :: boolean()

Whether a node has a given command class

Link to this function

network_busy?() View Source
network_busy?() :: boolean()

Check to see if the network is busy

Link to this function

network_ready?() View Source
network_ready?() :: boolean()

Check to see if the network is ready

Link to this function

remove_node(opts \\ []) View Source
remove_node([Grizzly.Inclusion.opt()]) :: :ok

Put network in exclusion mode

Put network out of exclusion mode

Link to this function

reset_controller() View Source
reset_controller() :: :ok | {:error, :network_busy}

Reset the Z-Wave Module to a clean state

Link to this function

send_command(connected, command_module, command_opts \\ []) View Source
send_command(
  connected() | Grizzly.Node.node_id(),
  command_module :: module(),
  command_opts :: keyword()
) :: :ok | {:ok, any()} | {:error, any()}

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.

Link to this function

start_learn_mode(opts \\ []) View Source
start_learn_mode([Grizzly.Inclusion.opt()]) :: :ok

Put the controller in learn mode for a few seconds

Link to this function

subscribe(topic) View Source
subscribe(Grizzly.Notifications.topic()) :: :ok | {:error, :already_subscribed}

Subscribe to notifications about a topic

See Grizzly.Notifications for more information

Link to this function

update_command_class_versions(zw_node) View Source
update_command_class_versions(Grizzly.Node.t()) :: Grizzly.Node.t()

Update the command class version of a node