docs/en/matter/ep_generic_switch.rst
################### MatterGenericSwitch ###################
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:
click() convenience helper for simple automationsUse Cases:
The Matter Switch cluster exposes optional FeatureMap bits. This class provides constants that match the specification:
+---------------------------+-------+-----------------------------------+
| Constant | Bit | Events enabled |
+===========================+=======+===================================+
| FEATURE_MOMENTARY | 0x02 | InitialPress |
+---------------------------+-------+-----------------------------------+
| FEATURE_RELEASE | 0x04 | ShortRelease |
+---------------------------+-------+-----------------------------------+
| FEATURE_LONG_PRESS | 0x08 | LongPress, LongRelease |
+---------------------------+-------+-----------------------------------+
| FEATURE_MULTI_PRESS | 0x10 | MultiPressOngoing, |
| | | MultiPressComplete |
+---------------------------+-------+-----------------------------------+
Preset combinations:
FEATURE_SIMPLE (default) — FEATURE_MOMENTARY | FEATURE_RELEASE for a single short clickFEATURE_ALL — all momentary gesture features aboveDependencies:
FEATURE_LONG_PRESS requires FEATURE_RELEASEFEATURE_MULTI_PRESS requires FEATURE_RELEASEConstructor
MatterGenericSwitch ^^^^^^^^^^^^^^^^^^^
Creates a new Matter generic switch endpoint.
.. code-block:: arduino
MatterGenericSwitch();
Feature Constants
.. code-block:: arduino
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.
.. code-block:: arduino
bool begin(uint32_t featureFlags = FEATURE_SIMPLE, uint8_t multiPressMax = 5);
FEATURE_SIMPLE.FEATURE_MULTI_PRESS is set.Returns true on success, false otherwise.
Examples:
.. code-block:: arduino
// 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.
.. code-block:: arduino
void end();
hasFeature ^^^^^^^^^^
Returns true if the given feature bit is enabled.
.. code-block:: arduino
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).
.. code-block:: arduino
void press();
release ^^^^^^^
Sends ShortRelease (button released after a short press).
.. code-block:: arduino
void release();
longPress ^^^^^^^^^
Sends LongPress (button held past the long-press threshold).
.. code-block:: arduino
void longPress();
longRelease ^^^^^^^^^^^
Sends LongRelease (button released after a long press).
.. code-block:: arduino
void longRelease();
multiPressOngoing ^^^^^^^^^^^^^^^^^
Sends MultiPressOngoing when an additional press starts within the multi-press window.
.. code-block:: arduino
void multiPressOngoing(uint8_t count);
multiPressComplete ^^^^^^^^^^^^^^^^^^
Sends MultiPressComplete when the multi-press window expires after the last release.
.. code-block:: arduino
void multiPressComplete(uint8_t count);
click ^^^^^
Convenience helper: sends InitialPress followed by ShortRelease when the release feature is enabled.
.. code-block:: arduino
void click();
A correct short click sends two events:
InitialPress on button downShortRelease on button upLong press adds LongPress while held and LongRelease on release.
Multi-press (double/triple click) follows the ESP-Matter generic switch pattern:
InitialPressShortReleaseMultiPressOngoing (count = 2)ShortReleaseMultiPressComplete (total count)Simple Smart Button
Minimal short-click implementation using press() on down and release() on up.
View Matter Smart Button example on GitHub <https://github.com/espressif/arduino-esp32/tree/master/libraries/Matter/examples/MatterSmartButton>_
Enhanced Smart Button
Full gesture support with long press and multi-press.
View Matter Enhanced Smart Button example on GitHub <https://github.com/espressif/arduino-esp32/tree/master/libraries/Matter/examples/MatterEnhancedSmartButton>_