MatterGenericSwitch
About
The MatterGenericSwitch class provides a generic switch endpoint for Matter networks. It implements the Matter Switch cluster as a momentary smart button that reports press gestures to the Matter controller.
Features:
Configurable Switch cluster features (short click, long press, multi-press)
Individual event methods matching the Matter specification
click()convenience helper for simple automationsAutomation trigger support for Apple Home, Amazon Alexa, Google Home, and Home Assistant
Matter standard compliance
Use Cases:
Smart buttons and scene triggers
Remote controls with single, double, or long press
Event generators for smart home automation
Switch Cluster Features
The Matter Switch cluster exposes optional FeatureMap bits. This class provides constants that match the specification:
Constant |
Bit |
Events enabled |
|---|---|---|
|
0x02 |
|
|
0x04 |
|
|
0x08 |
|
|
0x10 |
|
Preset combinations:
FEATURE_SIMPLE(default) —FEATURE_MOMENTARY | FEATURE_RELEASEfor a single short clickFEATURE_ALL— all momentary gesture features above
Dependencies:
FEATURE_LONG_PRESSrequiresFEATURE_RELEASEFEATURE_MULTI_PRESSrequiresFEATURE_RELEASE
API Reference
Constructor
MatterGenericSwitch
Creates a new Matter generic switch endpoint.
MatterGenericSwitch();
Feature Constants
static constexpr uint32_t FEATURE_MOMENTARY;
static constexpr uint32_t FEATURE_RELEASE;
static constexpr uint32_t FEATURE_LONG_PRESS;
static constexpr uint32_t FEATURE_MULTI_PRESS;
static constexpr uint32_t FEATURE_SIMPLE; // short click
static constexpr uint32_t FEATURE_ALL; // all gestures
Initialization
begin
Initializes the Matter generic switch endpoint.
bool begin(uint32_t featureFlags = FEATURE_SIMPLE, uint8_t multiPressMax = 5);
featureFlags — Switch cluster features to enable at endpoint creation. Defaults to
FEATURE_SIMPLE.multiPressMax — Maximum press count for multi-press (2–255). Used only when
FEATURE_MULTI_PRESSis set.
Returns true on success, false otherwise.
Examples:
// Simple short-click button (default)
mySwitch.begin();
// Full gesture support (long press + multi-press up to 5 clicks)
mySwitch.begin(MatterGenericSwitch::FEATURE_ALL, 5);
end
Stops processing Matter switch events.
void end();
hasFeature
Returns true if the given feature bit is enabled.
bool hasFeature(uint32_t feature) const;
Event Generation
Call these from your button driver when the corresponding physical action occurs.
press
Sends InitialPress (button pressed down).
void press();
release
Sends ShortRelease (button released after a short press).
void release();
longPress
Sends LongPress (button held past the long-press threshold).
void longPress();
longRelease
Sends LongRelease (button released after a long press).
void longRelease();
multiPressOngoing
Sends MultiPressOngoing when an additional press starts within the multi-press window.
void multiPressOngoing(uint8_t count);
multiPressComplete
Sends MultiPressComplete when the multi-press window expires after the last release.
void multiPressComplete(uint8_t count);
click
Convenience helper: sends InitialPress followed by ShortRelease when the release feature is enabled.
void click();
Gesture Event Flow
A correct short click sends two events:
InitialPresson button downShortReleaseon button up
Long press adds LongPress while held and LongRelease on release.
Multi-press (double/triple click) follows the ESP-Matter generic switch pattern:
First press down →
InitialPressFirst release →
ShortReleaseSecond press down (within window) →
MultiPressOngoing(count = 2)Second release →
ShortReleaseWindow expires →
MultiPressComplete(total count)