-
Notifications
You must be signed in to change notification settings - Fork 7.8k
feat(matter): adds dimmable plugin matter endpoint #12105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,259 @@ | ||
| #################### | ||
| MatterDimmablePlugin | ||
| #################### | ||
|
|
||
| About | ||
| ----- | ||
|
|
||
| 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. | ||
|
|
||
| **Features:** | ||
| * On/off control | ||
| * Power level control (0-255) | ||
| * State persistence support | ||
| * Callback support for state and level changes | ||
| * Integration with Apple HomeKit, Amazon Alexa, and Google Home | ||
| * Matter standard compliance | ||
|
|
||
| **Use Cases:** | ||
| * Dimmable smart power outlets | ||
| * Variable power control | ||
| * Dimmable relay control | ||
SuGlider marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * Smart dimmer plugs | ||
| * Level-controlled device control | ||
|
|
||
| API Reference | ||
| ------------- | ||
|
|
||
| Constructor | ||
| *********** | ||
|
|
||
| MatterDimmablePlugin | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| Creates a new Matter dimmable plugin endpoint. | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| MatterDimmablePlugin(); | ||
|
|
||
| Initialization | ||
| ************** | ||
|
|
||
| begin | ||
| ^^^^^ | ||
|
|
||
| Initializes the Matter dimmable plugin endpoint with optional initial state and level. | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| bool begin(bool initialState = false, uint8_t level = 64); | ||
|
|
||
| * ``initialState`` - Initial on/off state (``true`` = on, ``false`` = off, default: ``false``) | ||
| * ``level`` - Initial power level (0-255, default: 64 = 25%) | ||
|
|
||
| This function will return ``true`` if successful, ``false`` otherwise. | ||
|
|
||
| end | ||
| ^^^ | ||
|
|
||
| Stops processing Matter plugin events. | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| void end(); | ||
|
|
||
| On/Off Control | ||
| ************** | ||
|
|
||
| setOnOff | ||
| ^^^^^^^^ | ||
|
|
||
| Sets the on/off state of the plugin. | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| bool setOnOff(bool newState); | ||
|
|
||
| * ``newState`` - New state (``true`` = on, ``false`` = off) | ||
|
|
||
| This function will return ``true`` if successful, ``false`` otherwise. | ||
|
|
||
| getOnOff | ||
| ^^^^^^^^ | ||
|
|
||
| Gets the current on/off state of the plugin. | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| bool getOnOff(); | ||
|
|
||
| This function will return ``true`` if the plugin is on, ``false`` if off. | ||
|
|
||
| toggle | ||
| ^^^^^^ | ||
|
|
||
| Toggles the on/off state of the plugin. | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| bool toggle(); | ||
|
|
||
| This function will return ``true`` if successful, ``false`` otherwise. | ||
|
|
||
| Level Control | ||
| ************** | ||
|
|
||
| setLevel | ||
| ^^^^^^^^ | ||
|
|
||
| Sets the power level of the plugin. | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| bool setLevel(uint8_t newLevel); | ||
|
|
||
| * ``newLevel`` - New power level (0-255, where 0 = off, 255 = maximum level) | ||
|
|
||
| This function will return ``true`` if successful, ``false`` otherwise. | ||
|
|
||
| getLevel | ||
| ^^^^^^^^ | ||
|
|
||
| Gets the current power level of the plugin. | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| uint8_t getLevel(); | ||
|
|
||
| This function will return the power level (0-255). | ||
|
|
||
| Constants | ||
| ********* | ||
|
|
||
| MAX_LEVEL | ||
| ^^^^^^^^^^ | ||
|
|
||
| Maximum power level value constant. | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| static const uint8_t MAX_LEVEL = 255; | ||
|
|
||
| Operators | ||
| ********* | ||
|
|
||
| bool operator | ||
| ^^^^^^^^^^^^^ | ||
|
|
||
| Returns the current on/off state of the plugin. | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| operator bool(); | ||
|
|
||
| Example: | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| if (myPlugin) { | ||
| Serial.println("Plugin is on"); | ||
| } | ||
|
|
||
| Assignment operator | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| Turns the plugin on or off. | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| void operator=(bool state); | ||
|
|
||
| Example: | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| myPlugin = true; // Turn plugin on | ||
| myPlugin = false; // Turn plugin off | ||
|
|
||
| Event Handling | ||
| ************** | ||
|
|
||
| onChange | ||
| ^^^^^^^^ | ||
|
|
||
| Sets a callback function to be called when any parameter changes. | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| void onChange(EndPointCB onChangeCB); | ||
|
|
||
| * ``onChangeCB`` - Function to call when state changes | ||
|
|
||
| The callback signature is: | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| bool onChangeCallback(bool newState, uint8_t newLevel); | ||
|
|
||
| * ``newState`` - New on/off state (``true`` = on, ``false`` = off) | ||
| * ``newLevel`` - New power level (0-255) | ||
|
|
||
| onChangeOnOff | ||
| ^^^^^^^^^^^^^ | ||
|
|
||
| Sets a callback function to be called when the on/off state changes. | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| void onChangeOnOff(EndPointOnOffCB onChangeCB); | ||
|
|
||
| * ``onChangeCB`` - Function to call when on/off state changes | ||
|
|
||
| The callback signature is: | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| bool onChangeCallback(bool newState); | ||
|
|
||
| * ``newState`` - New on/off state (``true`` = on, ``false`` = off) | ||
|
|
||
| onChangeLevel | ||
| ^^^^^^^^^^^^^ | ||
|
|
||
| Sets a callback function to be called when the power level changes. | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| void onChangeLevel(EndPointLevelCB onChangeCB); | ||
|
|
||
| * ``onChangeCB`` - Function to call when level changes | ||
|
|
||
| The callback signature is: | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| bool onChangeCallback(uint8_t newLevel); | ||
|
|
||
| * ``newLevel`` - New power level (0-255) | ||
|
|
||
| updateAccessory | ||
| ^^^^^^^^^^^^^^^ | ||
|
|
||
| Updates the state of the plugin using the current Matter Plugin internal state. | ||
|
|
||
| .. code-block:: arduino | ||
|
|
||
| void updateAccessory(); | ||
|
|
||
| This function will call the registered callback with the current state. | ||
|
|
||
| Example | ||
| ------- | ||
|
|
||
| Dimmable Plugin | ||
| *************** | ||
|
|
||
| .. literalinclude:: ../../../libraries/Matter/examples/MatterDimmablePlugin/MatterDimmablePlugin.ino | ||
| :language: arduino | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supported? Maybe you are referring to SSR (Solid State Relay)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is about the use cases, not the specific components. Yes, it is about SSR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it's better to mention SSR. Dimmable lights with a relay (coil relays) are not possible, only with an SSR, like a TRIAC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove it. It may be better.