Load the library local zb = require('applibs.zigbee')

Library functions zb.step() Waits for a single message sent from/to ZigBee. Returns the received message or nil plus an error message on timeout.

zb.loop(timeout, callback) Reads messages for up to timeout seconds. Optional callback function is executed for each received message.

zb.addcallback(address, callback) Adds a callback function for all messages sent from the given address. address is a device IEEE address (string, 64-bit identifier in a lowercase hexadecimal form). See below for message structure explanation.

zb.cmd(fnname, address, ...) zb.cmdep(fnname, address, endpoint, ...) Sends a single command message to the given address/group. address must be either a device IEEE address (string, 64-bit identifier in a lowercase hexadecimal form) or a group (number, between 1 and 65535).

zb.cmdep allows passing the endpoint number directly. zb.cmd uses the first endpoint that contains the required cluster. Additional arguments can be passed depending on the command.

zb.cmdsync(fnname, address, ...) zb.cmdepsync(fnname, address, endpoint, ...) Similar to zb.cmd and zb.cmdep but waits for a reply. Default timeout is 20 seconds, it can be changed by setting the zb.cmdtimeout variable. Returns the command result or nil plus an error message in case of an error.

Available commands Arguments should be passed to the function in the same order as documented. See examples below.

getcolortemp - retrieve color temperature Returns a table with the following fields:

getlevel - retrieve level Returns a number with the current level from 0 to 254

getonoff - retrieve On/Off status Returns a Boolean with the current On/Off status.

getxy - retrieve color space coordinates Returns a table with the following fields:

identify - start/stop device identification Arguments:

setonoff Arguments:

setlevel - set light level Arguments:

setlevelup - move the light level up at a given rate setleveldown - move the light level down at a given rate Arguments:

setlevelstop - stop the light level change

setcolortemp - set color temperature Arguments:

setrgb - set RGB color value This function calculates the required level and XY coordinates from the given RGB color values. Each color value must be number between 0 and 255. Arguments:

setxy - set color space coordinates Both coordinates must be a number between 0 and 65534. Arguments:

sethuesat - set hue and saturation Both hue and saturation must be a number between 0 and 254. Arguments:

setdoor - lock/unlock a door Arguments:

Example - resident script for monitoring several devices, sleep time set to 0 Devices with addresses 0123456789abcdef and abcdef0123456789 are monitored

Example - sending commands and reading status responses

Message table structure

The following fields are mostly applicable to messages from ZigBee network:

Attribute table example The following attributes are sent from a security device like a door/window sensor. detection field is true when a door/window is opened.

Cluster data example The following data is sent for an On command:

The following data is sent for a Move command with Down direction with a rate of 38 per second: