Emit a switch action for a GenericSwitch accessory.
High-level helper for stateless switches and remotes (e.g. Pico remotes, scene controllers).
Sets the Switch cluster's currentPosition attribute, which causes the Matter.js SwitchServer
to automatically fire the appropriate cluster events:
| Action | When to use | Events fired by Matter.js |
|---|---|---|
press |
Physical button pressed / contact closed | initialPress |
release |
Physical button released / contact opened | shortRelease or longRelease* |
shortRelease vs longRelease is determined automatically by the SwitchServer based on
how long the button was held (configurable via longPressDelay, default 2 s).
Multi-press sequences (multiPressComplete) are generated automatically when press/release
cycles occur within the multiPressDelay window (default 300 ms).
UUID of the GenericSwitch accessory
'press' to press the button, 'release' to release it
Optionaloptions: { partId?: string; position?: number }Optional configuration
OptionalpartId?: stringPart ID for composed devices with GenericSwitch parts.
Optionalposition?: numberButton position index (1-based). Defaults to 1. Use when the
GenericSwitch has multiple positions (e.g. a multi-button remote).
// Simple single-button press and release
await api.matter?.switch.emit(uuid, 'press')
await api.matter?.switch.emit(uuid, 'release')
// Multi-button remote: button 2 press and release
await api.matter?.switch.emit(uuid, 'press', { position: 2 })
await api.matter?.switch.emit(uuid, 'release', { position: 2 })
// GenericSwitch as a part in a composed device
await api.matter?.switch.emit(uuid, 'press', { partId: 'button-top' })
await api.matter?.switch.emit(uuid, 'release', { partId: 'button-top' })
Emit a high-level gesture for a GenericSwitch accessory.
Convenience helper for integrations that already classify gestures (e.g. remotes that
report only single, double, or hold). Translates each gesture into the canonical
press / release sequence that Matter.js SwitchServer expects, so the server still
determines the correct Switch cluster events (shortRelease, longRelease,
multiPressComplete) based on timing.
| Gesture | Translated sequence |
|---|---|
singlePress |
press → release |
doublePress |
press → release → (multiPressDelayMs) → press → release |
longPress |
press → (longPressDelayMs) → release |
Default delays:
longPressDelayMs – 2500 ms (just above the Matter.js longPressDelay default of 2000 ms)multiPressDelayMs – 100 ms (well within the Matter.js multiPressDelay window of 300 ms)UUID of the GenericSwitch accessory
The gesture to emit: 'singlePress', 'doublePress', or 'longPress'
Optionaloptions: {Optional configuration
OptionallongPressDelayMs?: numberHow long (ms) to hold the button for a long press.
Defaults to 2500. Only relevant for 'longPress'.
OptionalmultiPressDelayMs?: numberDelay (ms) between the two press cycles of a double press.
Defaults to 100. Only relevant for 'doublePress'.
OptionalpartId?: stringPart ID for composed devices with GenericSwitch parts.
Optionalposition?: numberButton position index (1-based). Defaults to 1.
// Single press on a simple remote
await api.matter?.switch.emitGesture(uuid, 'singlePress')
// Double press on button 2 of a multi-button remote
await api.matter?.switch.emitGesture(uuid, 'doublePress', { position: 2 })
// Long press on a composed device part
await api.matter?.switch.emitGesture(uuid, 'longPress', { partId: 'button-top' })
Switch helper API for
GenericSwitchaccessories (stateless remotes and buttons).Grouped under
api.matter?.switchso device-type-specific helpers don't crowd the top-levelMatterAPIsurface. Built on top ofupdateAccessoryStatefor the Switch cluster.