MatterEndPoint
About
The MatterEndPoint class is the base class for all Matter endpoints. It provides common functionality for all endpoint types.
Endpoint Management: Each endpoint has a unique endpoint ID for identification within the Matter network.
Attribute Access: Methods to get and set attribute values from Matter clusters.
Identify Cluster: Support for device identification (visual feedback like LED blinking).
Semantic Tags: Descriptor cluster
TagListsupport viasetTagList(), so controllers can tell sibling endpoints of the same device type apart.Attribute Change Callbacks: Base framework for handling attribute changes from Matter controllers.
All Matter endpoint classes inherit from MatterEndPoint, providing a consistent interface and common functionality across all device types.
MatterEndPoint APIs
Endpoint Management
getEndPointId
Gets the current Matter Accessory endpoint ID.
uint16_t getEndPointId();
This function will return the endpoint number (typically 1-254).
setEndPointId
Sets the current Matter Accessory endpoint ID.
void setEndPointId(uint16_t ep);
ep- Endpoint number to set.
Custom endpoints
For esp-matter device types that are not wrapped by a stock Matter* class, subclass MatterEndPoint, implement attributeChangeCB, and in your subclass begin():
Call
ensureMatterNode()(protected onMatterEndPoint; not callable from the sketch) orMatter.initNode()if you are not using aMatterEndPointsubclass.Create the endpoint with
esp_matter::endpoint::*::create(node::get(), …, ENDPOINT_FLAG_NONE, (void *)this).Call
setEndPointId(endpoint::get_id(ep)), orregisterCreatedEndpoint(ep)aftercreate()with(void *)this.
Override onStackStarted() when you need to push cached attribute values after Matter.begin() (for example code-driven clusters). See the MatterCustomEndpoint example.
registerCreatedEndpoint
Registers an endpoint created with esp_matter::endpoint::*::create(..., (void *)this). Call before Matter.begin().
bool registerCreatedEndpoint(endpoint_t *ep);
onStackStarted
Override this hook in a MatterEndPoint subclass to push cached attribute values after Matter.begin(), when code-driven clusters or the live attribute store are available. The library calls it once per endpoint (via an internal notifyStackStarted()) immediately after esp_matter::start() succeeds.
Do not call notifyStackStarted() from application code.
void onStackStarted() override;
Typical uses: sync a value held in C++ members into clusters that were not writable before the stack started, or re-apply a measurement after Matter.begin() (see the MatterCustomEndpoint example). For Boolean State sensors, prefer the endpoint setters (setContact(), etc.); they cache via setBooleanStateValue() when the cluster is not registered yet.
Secondary Network Interface (deprecated)
Arduino Matter exposes one Network Commissioning cluster on endpoint 0: Wi-Fi or Thread, not both. On ESP32-C6 and ESP32-S31 call Matter.selectNetwork(MATTER_NETWORK_WIFI) or Matter.selectNetwork(MATTER_NETWORK_THREAD) before any accessory begin(). Matter.selectNetwork(MATTER_NETWORK_THREAD) replaces the root Wi-Fi driver so hubs that only talk to endpoint 0 see Thread.
createSecondaryNetworkInterface() is deprecated. It does not create an endpoint and always returns false. getSecondaryNetworkEndPointId() always returns 0.
bool createSecondaryNetworkInterface();
uint16_t getSecondaryNetworkEndPointId();
Attribute Management
getAttribute
Gets a pointer to an attribute from its cluster ID and attribute ID.
esp_matter::attribute_t *getAttribute(uint32_t cluster_id, uint32_t attribute_id);
cluster_id- Cluster ID (e.g.,OnOff::Id).attribute_id- Attribute ID (e.g.,OnOff::Attributes::OnOff::Id).
This function will return a pointer to the attribute, or NULL if not found.
getAttributeVal
Gets the value of an attribute from its cluster ID and attribute ID.
bool getAttributeVal(uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *attrVal);
cluster_id- Cluster ID.attribute_id- Attribute ID.attrVal- Pointer to store the attribute value.
This function will return true if successful, false otherwise.
setAttributeVal
Sets the value of an attribute from its cluster ID and attribute ID.
bool setAttributeVal(uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *attrVal);
cluster_id- Cluster ID.attribute_id- Attribute ID.attrVal- Pointer to the attribute value to set.
This function will return true if successful, false otherwise.
updateAttributeVal
Updates the value of an attribute from its cluster ID. This is typically used for read-only attributes that are updated by the device itself (e.g., sensor readings).
bool updateAttributeVal(uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *attrVal);
cluster_id- Cluster ID.attribute_id- Attribute ID.attrVal- Pointer to the attribute value to update.
This function will return true if successful, false otherwise.
Boolean State StateValue (contact, leak, freeze, rain) lives on the code-driven cluster and cannot be written with updateAttributeVal() (that only updates the shadow table). Those endpoints use a cluster setter. Call setContact() / setLeak() / setFreeze() / setRain() after the endpoint begin(); a value set before Matter.begin() is cached and applied when the cluster is created.
Identify Cluster
onIdentify
Sets a callback function for the Identify cluster. This callback is invoked when clients interact with the Identify Cluster of a specific endpoint.
void onIdentify(EndPointIdentifyCB onEndPointIdentifyCB);
onEndPointIdentifyCB- Function pointer to the callback function. The callback receives a boolean parameter indicating if identify is enabled.
The callback signature is:
bool identifyCallback(bool identifyIsEnabled);
When identifyIsEnabled is true, the device should provide visual feedback (e.g., blink an LED). When false, the device should stop the identification feedback.
Both the Identify command (IdentifyTime → START/STOP) and TriggerEffect invoke this callback. TriggerEffect Blink/Breathe/Okay/ChannelChange report true. StopEffect and FinishEffect report false. A one-shot TriggerEffect does not send a later STOP; if the sketch latches a flag, time the animation out.
getIdentifyRequest
Returns the last Identify event for this endpoint. The library fills it immediately before onIdentify() runs. Use it inside that callback (or later) to distinguish IdentifyTime from TriggerEffect and to read the effect id.
MatterIdentifyRequest getIdentifyRequest();
MatterIdentifyRequest fields:
valid-falseuntil this endpoint has received an Identify event. Do not treat a defaulteffectIdof 0 as Blink.active- same boolean passed toonIdentify().fromTriggerEffect-trueforTriggerEffect;falsefor Identify /IdentifyTime.effectId-MatterIdentifyRequest::BLINK(0x00),BREATHE(0x01),OKAY(0x02),CHANNEL_CHANGE(0x0B),FINISH(0xFE),STOP(0xFF). Meaningful whenfromTriggerEffectistrue. On IdentifyTime START/STOP CHIP still passes a leftover/default id (often Blink); ignore it.effectVariant- usually Default (0).
Example usage:
myEndpoint.onIdentify([](bool identifyIsEnabled) {
MatterIdentifyRequest req = myEndpoint.getIdentifyRequest();
if (identifyIsEnabled && req.fromTriggerEffect && req.effectId == MatterIdentifyRequest::OKAY) {
// Short confirmation flash; time it out in loop()
} else if (identifyIsEnabled) {
// Start blinking LED
digitalWrite(LED_PIN, HIGH);
} else {
// Stop blinking LED
digitalWrite(LED_PIN, LOW);
}
return true;
});
Attribute Change Callback
attributeChangeCB
This function is called by the Matter internal event processor when an attribute changes. It can be overridden by the application if necessary.
virtual bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
endpoint_id- Endpoint ID where the attribute changed.cluster_id- Cluster ID of the changed attribute.attribute_id- Attribute ID that changed.val- Pointer to the new attribute value.
This function should return true if the change was handled successfully, false otherwise.
All endpoint classes implement this function to handle attribute changes specific to their device type. You typically don’t need to override this unless you need custom behavior.
Supported Endpoints
The Matter library provides specialized endpoint classes that inherit from MatterEndPoint. Each endpoint type includes specific clusters and functionality relevant to that device category.
- MatterColorLight
- MatterColorTemperatureLight
- MatterContactSensor
- MatterDimmableLight
- MatterDimmablePlugin
- MatterEnhancedColorLight
- MatterFan
- MatterGenericSwitch
- MatterHumiditySensor
- MatterLightSensor
- MatterOccupancySensor
- MatterOnOffLight
- MatterOnOffPlugin
- MatterPressureSensor
- MatterRainSensor
- MatterSoilSensor
- MatterTemperatureControlledCabinet
- MatterTemperatureSensor
- MatterThermostat
- MatterWaterFreezeDetector
- MatterWaterHeater
- MatterWaterLeakDetector
- MatterWaterValve
- MatterWindowCovering