zigbee

package
v1.0.0-beta.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: GPL-3.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package zigbee speaks Zigbee2MQTT's MQTT API: its topics, device names, availability, bridge messages and the device list with each device's features ("exposes"). The Zigbee nodes and the discovery service build on it (docs/design/zigbee.md).

Index

Constants

View Source
const (
	AccessPublished = 1
	AccessSet       = 2
	AccessGet       = 4
)

Access bits of a feature.

View Source
const MaxDeviceNameLength = 256

MaxDeviceNameLength bounds a device's friendly name.

View Source
const (

	// MaxPermitJoinSeconds is Zigbee2MQTT's longest permit-join window.
	MaxPermitJoinSeconds = 254
)

Bounds of what a watcher keeps.

Variables

This section is empty.

Functions

func AvailabilityTopic

func AvailabilityTopic(base, device string) string

AvailabilityTopic is where Zigbee2MQTT publishes whether a device is online.

func BridgeTopic

func BridgeTopic(base, sub string) string

BridgeTopic is a topic under the bridge (state, info, devices, request/…).

func DeviceTopic

func DeviceTopic(base, device string) string

DeviceTopic is where Zigbee2MQTT publishes a device's state.

func GetTopic

func GetTopic(base, device string) string

GetTopic is where a device is asked for a fresh reading.

func ParseAvailability

func ParseAvailability(payload []byte) (online, ok bool)

ParseAvailability reads an availability payload: {"state":"online"} or, in Zigbee2MQTT's legacy format, the plain word.

func SetTopic

func SetTopic(base, device string) string

SetTopic is where a device takes commands.

func ValidDeviceName

func ValidDeviceName(name string) error

ValidDeviceName checks a device (or group) friendly name as a topic part: not empty, no wildcards, no empty level, not the bridge and not ending in a command suffix (set, get, availability).

Types

type BridgeInfo

type BridgeInfo struct {
	Version    string `json:"version"`
	PermitJoin bool   `json:"permitJoin"`
	// PermitJoinEnd is when joining closes, in Unix milliseconds
	// (Zigbee2MQTT 2.x), if it says.
	PermitJoinEnd *int64 `json:"permitJoinEnd,omitempty"`
	Coordinator   string `json:"coordinator,omitempty"`
}

BridgeInfo is what bridge/info says that the editor shows.

func ParseBridgeInfo

func ParseBridgeInfo(payload []byte) (BridgeInfo, error)

ParseBridgeInfo reads bridge/info.

type BridgeStatus

type BridgeStatus struct {
	Online bool       `json:"online"`
	Info   BridgeInfo `json:"info"`
}

BridgeStatus is the bridge as the editor shows it.

type Device

type Device struct {
	FriendlyName string    `json:"friendlyName"`
	IEEE         string    `json:"ieee"`
	Type         string    `json:"type"` // Router or EndDevice
	PowerSource  string    `json:"powerSource,omitempty"`
	Model        string    `json:"model,omitempty"`
	Vendor       string    `json:"vendor,omitempty"`
	Description  string    `json:"description,omitempty"`
	Supported    bool      `json:"supported"`
	Disabled     bool      `json:"disabled,omitempty"`
	Features     []Feature `json:"features"`
}

Device is a device of the network (the coordinator left out).

func ParseDevices

func ParseDevices(payload []byte) ([]Device, error)

ParseDevices reads bridge/devices: every device but the coordinator, its features flattened (a light's or switch's features are listed as its own; composite features keep their property, without sub-features).

func (Device) Feature

func (d Device) Feature(property string) *Feature

Feature returns the device's feature with that property, or nil.

func (Device) Properties

func (d Device) Properties() []string

Properties are the properties the device publishes, in its order.

func (Device) SettableProperties

func (d Device) SettableProperties() []string

SettableProperties are the properties the device can be set, in its order.

type DeviceStatus

type DeviceStatus struct {
	Device
	State    map[string]any `json:"state,omitempty"`
	Online   *bool          `json:"online,omitempty"`
	LastSeen *time.Time     `json:"lastSeen,omitempty"`
}

DeviceStatus is a device with what it last reported.

type Feature

type Feature struct {
	Property    string   `json:"property"`
	Name        string   `json:"name"`
	Type        string   `json:"type"` // binary, numeric, enum, text, …
	Access      int      `json:"access"`
	Unit        string   `json:"unit,omitempty"`
	Min         *float64 `json:"min,omitempty"`
	Max         *float64 `json:"max,omitempty"`
	Values      []string `json:"values,omitempty"`
	ValueOn     any      `json:"valueOn,omitempty"`
	ValueOff    any      `json:"valueOff,omitempty"`
	ValueToggle any      `json:"valueToggle,omitempty"`
	Description string   `json:"description,omitempty"`
}

Feature is one property of a device: what it publishes and, per its access bits, whether it can be set or read on request.

func (Feature) Gettable

func (f Feature) Gettable() bool

Gettable reports whether the feature can be read on request.

func (Feature) Published

func (f Feature) Published() bool

Published reports whether the feature appears in the device's state.

func (Feature) Settable

func (f Feature) Settable() bool

Settable reports whether the feature can be set.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager watches each broker connection's Zigbee2MQTT network (<base>/#, on its own pooled connection, ADR-0025): the bridge's state and info, the device list, and each device's last state and availability. It serves device discovery in the editor and the state the expressions read.

var Default *Manager

Default is the process-wide manager (main starts it); expressions read device states from it. Nil when not started.

func NewManager

func NewManager(store *brokers.Store) *Manager

NewManager creates a manager for the connections of store.

func (*Manager) Connections

func (m *Manager) Connections() []string

Connections returns the names of the watched connections.

func (*Manager) DeviceState

func (m *Manager) DeviceState(name, device string) (map[string]any, bool)

DeviceState returns the last state device reported on the connection name (a copy).

func (*Manager) Network

func (m *Manager) Network(name string) (Network, bool)

Network returns the network of the connection name.

func (*Manager) PermitJoin

func (m *Manager) PermitJoin(name string, seconds int) error

PermitJoin opens (seconds > 0) or closes (0) the network to new devices for up to MaxPermitJoinSeconds. It is the administrator's: no node or agent tool calls it.

func (*Manager) Start

func (m *Manager) Start()

Start watches every connection and follows the store's changes.

func (*Manager) Stop

func (m *Manager) Stop()

Stop ends every watcher.

type Network

type Network struct {
	Connection string         `json:"connection"`
	BaseTopic  string         `json:"baseTopic"`
	Connected  bool           `json:"connected"` // to the broker
	Bridge     BridgeStatus   `json:"bridge"`
	Devices    []DeviceStatus `json:"devices"`
}

Network is a connection's Zigbee network.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL