Skip to content

Commit 8319250

Browse files
committed
feat(matter): adds dimmable plugin matter endpoint
1 parent 471dcb0 commit 8319250

File tree

10 files changed

+952
-0
lines changed

10 files changed

+952
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ set(ARDUINO_LIBRARY_Matter_SRCS
198198
libraries/Matter/src/MatterEndpoints/MatterPressureSensor.cpp
199199
libraries/Matter/src/MatterEndpoints/MatterOccupancySensor.cpp
200200
libraries/Matter/src/MatterEndpoints/MatterOnOffPlugin.cpp
201+
libraries/Matter/src/MatterEndpoints/MatterDimmablePlugin.cpp
201202
libraries/Matter/src/MatterEndpoints/MatterThermostat.cpp
202203
libraries/Matter/src/Matter.cpp
203204
libraries/Matter/src/MatterEndPoint.cpp)
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
####################
2+
MatterDimmablePlugin
3+
####################
4+
5+
About
6+
-----
7+
8+
The ``MatterDimmablePlugin`` class provides a dimmable plugin unit endpoint for Matter networks. This endpoint implements the Matter dimmable plugin standard for controlling power outlets, relays, and other dimmable devices with power level control.
9+
10+
**Features:**
11+
* On/off control
12+
* Power level control (0-255)
13+
* State persistence support
14+
* Callback support for state and level changes
15+
* Integration with Apple HomeKit, Amazon Alexa, and Google Home
16+
* Matter standard compliance
17+
18+
**Use Cases:**
19+
* Dimmable smart power outlets
20+
* Variable power control
21+
* Dimmable relay control
22+
* Smart dimmer plugs
23+
* Level-controlled device control
24+
25+
API Reference
26+
-------------
27+
28+
Constructor
29+
***********
30+
31+
MatterDimmablePlugin
32+
^^^^^^^^^^^^^^^^^^^^
33+
34+
Creates a new Matter dimmable plugin endpoint.
35+
36+
.. code-block:: arduino
37+
38+
MatterDimmablePlugin();
39+
40+
Initialization
41+
**************
42+
43+
begin
44+
^^^^^
45+
46+
Initializes the Matter dimmable plugin endpoint with optional initial state and level.
47+
48+
.. code-block:: arduino
49+
50+
bool begin(bool initialState = false, uint8_t level = 64);
51+
52+
* ``initialState`` - Initial on/off state (``true`` = on, ``false`` = off, default: ``false``)
53+
* ``level`` - Initial power level (0-255, default: 64 = 25%)
54+
55+
This function will return ``true`` if successful, ``false`` otherwise.
56+
57+
end
58+
^^^
59+
60+
Stops processing Matter plugin events.
61+
62+
.. code-block:: arduino
63+
64+
void end();
65+
66+
On/Off Control
67+
**************
68+
69+
setOnOff
70+
^^^^^^^^
71+
72+
Sets the on/off state of the plugin.
73+
74+
.. code-block:: arduino
75+
76+
bool setOnOff(bool newState);
77+
78+
* ``newState`` - New state (``true`` = on, ``false`` = off)
79+
80+
This function will return ``true`` if successful, ``false`` otherwise.
81+
82+
getOnOff
83+
^^^^^^^^
84+
85+
Gets the current on/off state of the plugin.
86+
87+
.. code-block:: arduino
88+
89+
bool getOnOff();
90+
91+
This function will return ``true`` if the plugin is on, ``false`` if off.
92+
93+
toggle
94+
^^^^^^
95+
96+
Toggles the on/off state of the plugin.
97+
98+
.. code-block:: arduino
99+
100+
bool toggle();
101+
102+
This function will return ``true`` if successful, ``false`` otherwise.
103+
104+
Level Control
105+
**************
106+
107+
setLevel
108+
^^^^^^^^
109+
110+
Sets the power level of the plugin.
111+
112+
.. code-block:: arduino
113+
114+
bool setLevel(uint8_t newLevel);
115+
116+
* ``newLevel`` - New power level (0-255, where 0 = off, 255 = maximum level)
117+
118+
This function will return ``true`` if successful, ``false`` otherwise.
119+
120+
getLevel
121+
^^^^^^^^
122+
123+
Gets the current power level of the plugin.
124+
125+
.. code-block:: arduino
126+
127+
uint8_t getLevel();
128+
129+
This function will return the power level (0-255).
130+
131+
Constants
132+
*********
133+
134+
MAX_LEVEL
135+
^^^^^^^^^^
136+
137+
Maximum power level value constant.
138+
139+
.. code-block:: arduino
140+
141+
static const uint8_t MAX_LEVEL = 255;
142+
143+
Operators
144+
*********
145+
146+
bool operator
147+
^^^^^^^^^^^^^
148+
149+
Returns the current on/off state of the plugin.
150+
151+
.. code-block:: arduino
152+
153+
operator bool();
154+
155+
Example:
156+
157+
.. code-block:: arduino
158+
159+
if (myPlugin) {
160+
Serial.println("Plugin is on");
161+
}
162+
163+
Assignment operator
164+
^^^^^^^^^^^^^^^^^^^
165+
166+
Turns the plugin on or off.
167+
168+
.. code-block:: arduino
169+
170+
void operator=(bool state);
171+
172+
Example:
173+
174+
.. code-block:: arduino
175+
176+
myPlugin = true; // Turn plugin on
177+
myPlugin = false; // Turn plugin off
178+
179+
Event Handling
180+
**************
181+
182+
onChange
183+
^^^^^^^^
184+
185+
Sets a callback function to be called when any parameter changes.
186+
187+
.. code-block:: arduino
188+
189+
void onChange(EndPointCB onChangeCB);
190+
191+
* ``onChangeCB`` - Function to call when state changes
192+
193+
The callback signature is:
194+
195+
.. code-block:: arduino
196+
197+
bool onChangeCallback(bool newState, uint8_t newLevel);
198+
199+
* ``newState`` - New on/off state (``true`` = on, ``false`` = off)
200+
* ``newLevel`` - New power level (0-255)
201+
202+
onChangeOnOff
203+
^^^^^^^^^^^^^
204+
205+
Sets a callback function to be called when the on/off state changes.
206+
207+
.. code-block:: arduino
208+
209+
void onChangeOnOff(EndPointOnOffCB onChangeCB);
210+
211+
* ``onChangeCB`` - Function to call when on/off state changes
212+
213+
The callback signature is:
214+
215+
.. code-block:: arduino
216+
217+
bool onChangeCallback(bool newState);
218+
219+
* ``newState`` - New on/off state (``true`` = on, ``false`` = off)
220+
221+
onChangeLevel
222+
^^^^^^^^^^^^^
223+
224+
Sets a callback function to be called when the power level changes.
225+
226+
.. code-block:: arduino
227+
228+
void onChangeLevel(EndPointLevelCB onChangeCB);
229+
230+
* ``onChangeCB`` - Function to call when level changes
231+
232+
The callback signature is:
233+
234+
.. code-block:: arduino
235+
236+
bool onChangeCallback(uint8_t newLevel);
237+
238+
* ``newLevel`` - New power level (0-255)
239+
240+
updateAccessory
241+
^^^^^^^^^^^^^^^
242+
243+
Updates the state of the plugin using the current Matter Plugin internal state.
244+
245+
.. code-block:: arduino
246+
247+
void updateAccessory();
248+
249+
This function will call the registered callback with the current state.
250+
251+
Example
252+
-------
253+
254+
Dimmable Plugin
255+
***************
256+
257+
.. literalinclude:: ../../../libraries/Matter/examples/MatterDimmablePlugin/MatterDimmablePlugin.ino
258+
:language: arduino
259+

docs/en/matter/matter.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ The library provides specialized endpoint classes for different device types. Ea
135135
* ``MatterFan``: Fan with speed and mode control
136136
* ``MatterThermostat``: Thermostat with temperature control and setpoints
137137
* ``MatterOnOffPlugin``: On/off plugin unit (power outlet/relay)
138+
* ``MatterDimmablePlugin``: Dimmable plugin unit (power outlet/relay with brightness control)
138139
* ``MatterGenericSwitch``: Generic switch endpoint (smart button)
139140

140141
.. toctree::

0 commit comments

Comments
 (0)