Z-Wave JS Server
repository·master·Indexed 41 days ago
https://github.com/zwave-js/zwave-js-serverA lightweight wrapper that exposes Z-Wave JS driver functionality over a WebSocket API, enabling remote access and integration. It provides a standardized messaging protocol for managing Z-Wave controllers and nodes, including support for firmware updates (OTW), NVM operations, and real-time event listening. Version 3.10.2.
What's inside Z-Wave JS Server
- Z-Wave JS Server is a small server wrapper around Z-Wave JS that allows you to access Z-Wave functionality via a WebSocket interface. It is designed to bridge the Z-Wave JS driver to external clients using a standardized messaging protocol.
Unified Credential Management API
masterExposes the unified credential management API from Z-Wave JS under the
endpoint.access_control.*namespace. This is compatible with schema version 48+.Workflow: Before using credential commands, applications should check if the endpoint supports the unified access control API using
endpoint.access_control.is_supported. The response contains asupported: booleanfield.Supported Commands:
endpoint.access_control.is_supported(Check support)endpoint.access_control.get_user_capabilities_cached/get_credential_capabilities_cached(Get capabilities)endpoint.access_control.get_user/get_user_cached/get_users/get_users_cached(Get users)endpoint.access_control.set_user/delete_user/delete_all_users(Manage users)endpoint.access_control.get_credential/get_credential_cached/get_credentials/get_credentials_cached/get_credentials_by_type/get_credentials_by_type_cached/get_all_credentials/get_all_credentials_cached(Get credentials)endpoint.access_control.assign_credential(Reassign credential)endpoint.access_control.set_credential/delete_credential(Manage credentials)endpoint.access_control.start_credential_learn/cancel_credential_learn(Credential learning)endpoint.access_control.get_admin_code/set_admin_code(Admin code management)
Mutating Command Results: Mutating commands return a
resultfield with specific enum values:set_user,delete_user,delete_all_users$\rightarrow$SetUserResultset_credential,delete_credential$\rightarrow$SetCredentialResultassign_credential$\rightarrow$AssignCredentialResult
Examples:
Set a credential:
{ "messageId": "string", "command": "endpoint.access_control.set_credential", "nodeId": number, "endpoint": number, "userId": number, "credentialType": number, "credentialSlot": number, "data": "string" | { "type": "Buffer", "data": number[] } }Create or modify a user:
{ "messageId": "string", "command": "endpoint.access_control.set_user", "nodeId": number, "endpoint": number, "userId": number, "options": { "active": boolean, "userType": number, "userName": "string", "credentialRule": number, "expiringTimeoutMinutes": number } }How Multicasting works in Z-Wave JS Server
masterMulticasting allows you to send commands to multiple nodes simultaneously. The command prefix determines the scope:
- Broadcast to all nodes: Use the
broadcast_nodeprefix. - Multicast to a subset of nodes: Use the
multicast_groupprefix and provide anodeIDsarray as an input parameter.
For
broadcast_nodecommands, you can include alongRangeboolean flag to target Long Range nodes instead of classic Z-Wave nodes.// Example: Multicasting a set_value command to a group of nodes { "messageId": "string", "command": "multicast_group.set_value", "nodeIDs": [1, 2, 3], "valueId": { "commandClass": "COMMAND_CLASS_SWITCH_BINARY", "endpoint": 0, "property": "switch" }, "value": true }- Broadcast to all nodes: Use the
Handle Z-Wave Specific Errors
masterIf the error code is
zwave_error, the response includes additional context from the Z-Wave JS driver via thezwaveErrorCodeandzwaveErrorMessagekeys.{ "type": "result", "success": false, "messageId": 1, "errorCode": "zwave_error", "zwaveErrorCode": 18, "zwaveErrorMessage": "The message cannot be sent because node 61 is dead" }Listen to forwarded `zwave-js` events
masterThe Z-Wave JS Server forwards all standard
zwave-jsevents to clients that have issued thestart_listeningcommand. These events include updates from thedriver,controller,node, orzniffersources.interface { type: "event"; event: { source: "driver" | "controller" | "node" | "zniffer"; event: string; ... // Additional parameters dependent on the event } }Understand Z-Wave JS Server API Schema versions
masterThe Z-Wave JS Server API evolves through versioned schemas. Each schema version introduces new commands, state properties, or changes to existing data structures. When integrating with the server, you should be aware of the schema version being used to ensure compatibility with the available commands and the shape of the state dumps.
Key types of changes include:
- New Commands: Addition of namespaces like
driver.*,controller.*,node.*, orendpoint.*. - State Changes: New properties added to
NodeState,ControllerState, orEndpointstate dumps. - Event Changes: New controller or node events (e.g.,
statistics updated,interview started). - Breaking Changes: Renaming of properties (e.g.,
versiontoprotocolVersion) or changes in parameter types/return shapes.
Refer to the specific schema version documentation to map your client logic to the server's capabilities.
- New Commands: Addition of namespaces like
How Z-Wave JS Server handles controller command callbacks
masterBecause callbacks cannot be passed over a WebSocket connection, the Z-Wave JS Server automatically converts several controller methods that typically accept callback parameters into an event-driven model. Instead of providing a callback function in the command payload, the server emits specific events to the client to signal progress or required user interaction.
Key conversions include:
- Inclusion/Joining: For
controller.begin_inclusion,controller.replace_failed_node, andcontroller.begin_joining_network, the server handlesuserCallbacks(like S2 security bootstrapping) and emits events such asgrant security classes,validate dsk and enter pin,inclusion aborted,joining network show dsk, orjoining network done. - NVM Operations:
controller.backup_nvm_rawreports progress vianvm backup progressevents.controller.restore_nvmandcontroller.restore_nvm_rawusenvm convert progressandnvm restore progressevents. - Firmware Updates:
controller.firmware_update_otwaccepts a base64 encodedfileand afilename. - NVM Buffers: Commands like
controller.external_nvm_read_bufferreturn NVM data as a base64 encoded string in thebufferfield. For writes, thebufferinput must be a base64 encoded string.
- Inclusion/Joining: For
Understand the Z-Wave JS Server Connection Lifecycle
masterWhen a client connects to the server, the following lifecycle occurs:
- Version Handshake: The server immediately sends a
versionmessage containingdriverVersion,serverVersion,homeId, and schema version ranges (minSchemaVersion,maxSchemaVersion). - Driver Readiness: If the driver is not yet ready, the server closes the connection with error code
1013(Try Again Later). Clients should implement a retry mechanism. - Initialization: The client should send an
initializecommand to specify its supportedschemaVersionand optionaladditionalUserAgentComponents. - Listening: The client sends a
start_listeningcommand to receive the current state and subsequent events.
Data Formats
Version Message (Server -> Client):
{ type: "version", driverVersion: string, serverVersion: string, homeId: number | undefined, minSchemaVersion: number, maxSchemaVersion: number }Initialize Command (Client -> Server):
{ messageId: string, command: "initialize", schemaVersion: number, additionalUserAgentComponents?: Record<string, string> }Start Listening Command (Client -> Server):
{ messageId: string, command: "start_listening" }State Result (Server -> Client):
{ type: "result", messageId: string, // maps to the start_listening command success: true, result: { state: { driver: Partial<DriverState>; controller: Partial<ZWaveController>; nodes: Partial<ZWaveNode>[]; } } }- Version Handshake: The server immediately sends a
Access Controller level commands
masterThe
zwave-js-serversupports all controller methods defined in the official Z-Wave JS documentation.Important Mapping Rule: To use a controller method via the server, you must:
- Prefix the method with
controller. - Convert the method name from camelCase to snake_case.
Example: The Z-Wave JS method
beginInclusionis invoked via the server using the commandcontroller.begin_inclusion.- Prefix the method with
Access Utility and Config Manager commands
masterThe server exposes Z-Wave JS utility and configuration manager methods using a specific naming convention:
- Snake Casing: All commands use
snake_caseinstead of camelCase. - Prefixing: Controller-level commands are prefixed with their category.
Examples:
parseQRCodeStringbecomesutils.parse_qr_code_string.lookupDevicebecomesconfig_manager.lookup_device.
Note: String utilities like
num2hexare available but should be implemented locally rather than over WebSocket for performance.- Snake Casing: All commands use
Manage API Schema Versions
masterZ-Wave JS Server uses an API Schema Versioning system to maintain compatibility between different server and client versions.
When a client connects, the server sends a
versionmessage containingminSchemaVersionandmaxSchemaVersion. The client should then use theset_api_schemacommand to tell the server which schema version it intends to use.Key behaviors:
- Default Behavior: If the client does not send
set_api_schema, the server defaults to the minimum supported schema (currently0). - Multi-client Support: The server can handle multiple clients simultaneously, even if they are using different schema versions.
- Breaking Changes: When breaking changes are introduced to the API, the schema version is bumped. New features will also bump the schema version.
- Out of Range: If a client requests a version outside the server's supported range, the server returns a
schema_incompatibleerror.
// 1. Server sends version info upon connection { "type": "version", "driverVersion": "6.5.0", "serverVersion": "1.0.0", "homeId": 3967882672, "minSchemaVersion": 0, "maxSchemaVersion": 1 } // 2. Client sets the desired schema version { "command": "set_api_schema", "messageId": 1, "schemaVersion": 1 }- Default Behavior: If the client does not send
Start the Z-Wave JS Server
masterTo start the server, you can use the
zwave-serverCLI (ortsx src/bin/server.tsduring development). You must provide a path to a Z-Wave controller device (e.g.,/dev/tty0).Configuration Options
--config <path>: Specify a JSON or JS file following the Z-Wave JS config format. Note:emitValueUpdateAfterSetValuedefaults totrueunless specified otherwise.--port <number>: Set the WebSocket server port (default is3000).--host <address>: Set the interface to attach to (default is0.0.0.0).--mock-driver: Use a fake Z-Wave stick if no USB hardware is available.--disable-dns-sd: Disable DNS-SD (enabled by default).--reconnect: Enable automatic reconnection.
For development purposes, use:
tsx src/bin/server.ts /dev/tty0