|
| 1 | +# Matter Simple Window Blinds Example |
| 2 | + |
| 3 | +This is a minimal example demonstrating how to create a Matter-compatible window covering device with lift control only. This example uses a single `onGoToLiftPercentage()` callback to handle all window covering lift changes, making it ideal for simple implementations. |
| 4 | + |
| 5 | +## Supported Targets |
| 6 | + |
| 7 | +| SoC | Wi-Fi | Thread | BLE Commissioning | Status | |
| 8 | +| --- | ---- | ------ | ----------------- | ------ | |
| 9 | +| ESP32 | ✅ | ❌ | ❌ | Fully supported | |
| 10 | +| ESP32-S2 | ✅ | ❌ | ❌ | Fully supported | |
| 11 | +| ESP32-S3 | ✅ | ❌ | ✅ | Fully supported | |
| 12 | +| ESP32-C3 | ✅ | ❌ | ✅ | Fully supported | |
| 13 | +| ESP32-C5 | ✅ | ❌ | ✅ | Fully supported | |
| 14 | +| ESP32-C6 | ✅ | ❌ | ✅ | Fully supported | |
| 15 | +| ESP32-H2 | ❌ | ✅ | ✅ | Supported (Thread only) | |
| 16 | + |
| 17 | +### Note on Commissioning: |
| 18 | + |
| 19 | +- **ESP32 & ESP32-S2** do not support commissioning over Bluetooth LE. For these chips, you must provide Wi-Fi credentials directly in the sketch code so they can connect to your network manually. |
| 20 | +- **ESP32-C6** Although it has Thread support, the ESP32 Arduino Matter Library has been precompiled using Wi-Fi only. In order to configure it for Thread-only operation it is necessary to build the project as an ESP-IDF component and to disable the Matter Wi-Fi station feature. |
| 21 | +- **ESP32-C5** Although it has Thread support, the ESP32 Arduino Matter Library has been precompiled using Wi-Fi only. In order to configure it for Thread-only operation it is necessary to build the project as an ESP-IDF component and to disable the Matter Wi-Fi station feature. |
| 22 | + |
| 23 | +## Features |
| 24 | + |
| 25 | +- Matter protocol implementation for a window covering device |
| 26 | +- **Lift control only** (0-100%) - simplified implementation |
| 27 | +- **Single `onGoToLiftPercentage()` callback** - handles all window covering lift changes when `TargetPositionLiftPercent100ths` changes |
| 28 | +- Matter commissioning via QR code or manual pairing code |
| 29 | +- Integration with Apple HomeKit, Amazon Alexa, and Google Home |
| 30 | + |
| 31 | +## Hardware Requirements |
| 32 | + |
| 33 | +- ESP32 compatible development board (see supported targets table) |
| 34 | +- Window covering motor/actuator (optional for testing - example simulates movement) |
| 35 | + |
| 36 | +## Software Setup |
| 37 | + |
| 38 | +### Prerequisites |
| 39 | + |
| 40 | +1. Install the Arduino IDE (2.0 or newer recommended) |
| 41 | +2. Install ESP32 Arduino Core with Matter support |
| 42 | +3. ESP32 Arduino libraries: |
| 43 | + - `Matter` |
| 44 | + - `Wi-Fi` (only for ESP32 and ESP32-S2) |
| 45 | + |
| 46 | +### Configuration |
| 47 | + |
| 48 | +Before uploading the sketch, configure the following: |
| 49 | + |
| 50 | +1. **Wi-Fi Credentials** (for ESP32 and ESP32-S2 only): |
| 51 | + ```cpp |
| 52 | + const char *ssid = "your-ssid"; |
| 53 | + const char *password = "your-password"; |
| 54 | + ``` |
| 55 | + |
| 56 | +## Expected Output |
| 57 | + |
| 58 | +``` |
| 59 | +======================================== |
| 60 | +Matter Simple Window Blinds Example |
| 61 | +======================================== |
| 62 | +
|
| 63 | +Connecting to your-ssid |
| 64 | +WiFi connected |
| 65 | +IP address: 192.168.1.100 |
| 66 | +Matter started |
| 67 | +
|
| 68 | +======================================== |
| 69 | +Matter Node is not commissioned yet. |
| 70 | +Initiate the device discovery in your Matter environment. |
| 71 | +Commission it to your Matter hub with the manual pairing code or QR code |
| 72 | +Manual pairing code: 34970112332 |
| 73 | +QR code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=MT:Y.K9042C00KA0648G00 |
| 74 | +======================================== |
| 75 | +``` |
| 76 | + |
| 77 | +When a command is received from the Matter controller: |
| 78 | +``` |
| 79 | +Window Covering change request: Lift=50% |
| 80 | +``` |
| 81 | + |
| 82 | +## Usage |
| 83 | + |
| 84 | +1. **Commissioning**: Use the QR code or manual pairing code to commission the device to your Matter hub (Apple Home, Google Home, or Amazon Alexa). |
| 85 | + |
| 86 | +2. **Control**: Once commissioned, you can control the window covering lift percentage (0-100%) from your smart home app. The `onGoToLiftPercentage()` callback will be triggered whenever the target lift percentage changes. |
| 87 | + |
| 88 | +## Code Structure |
| 89 | + |
| 90 | +- **`onBlindLift()`**: Callback function that handles window covering lift changes. This is registered with `WindowBlinds.onGoToLiftPercentage()` and is triggered when `TargetPositionLiftPercent100ths` changes. The callback receives the target lift percentage (0-100%). |
| 91 | +- **`setup()`**: Initializes WiFi (if needed), Window Covering endpoint with `ROLLERSHADE` type, registers the callback, and starts Matter. |
| 92 | +- **`loop()`**: Empty - all control is handled via Matter callbacks. |
| 93 | + |
| 94 | +## Customization |
| 95 | + |
| 96 | +### Adding Motor Control |
| 97 | + |
| 98 | +In the `onBlindLift()` callback, replace the simulation code with actual motor control: |
| 99 | + |
| 100 | +```cpp |
| 101 | +bool onBlindLift(uint8_t liftPercent) { |
| 102 | + Serial.printf("Moving window covering to %d%%\r\n", liftPercent); |
| 103 | + |
| 104 | + // Here you would control your actual motor/actuator |
| 105 | + // For example: |
| 106 | + // - Calculate target position based on liftPercent and installed limits (if configured) |
| 107 | + // - Move motor to target position |
| 108 | + // - When movement is complete, update current position: |
| 109 | + // WindowBlinds.setLiftPercentage(finalLiftPercent); |
| 110 | + // WindowBlinds.setOperationalState(MatterWindowCovering::LIFT, MatterWindowCovering::STALL); |
| 111 | + |
| 112 | + // For this minimal example, we just return true to accept the command |
| 113 | + return true; // Indicate command was accepted |
| 114 | +} |
| 115 | +``` |
| 116 | +
|
| 117 | +## Troubleshooting |
| 118 | +
|
| 119 | +1. **Device not discoverable**: Ensure WiFi is connected (for ESP32/ESP32-S2) or BLE is enabled (for other chips). |
| 120 | +
|
| 121 | +2. **Lift percentage not updating**: Check that `onGoToLiftPercentage()` callback is properly registered and that `setLiftPercentage()` is called when movement is complete to update the `CurrentPosition` attribute. |
| 122 | +
|
| 123 | +3. **Commands not working**: Ensure the callback returns `true` to accept the command. If it returns `false`, the command will be rejected. |
| 124 | +
|
| 125 | +4. **Motor not responding**: Replace the simulation code in `onBlindLift()` with your actual motor control implementation. Remember to update `CurrentPosition` and set `OperationalState` to `STALL` when movement is complete. |
| 126 | +
|
| 127 | +## Notes |
| 128 | +
|
| 129 | +- This example uses `ROLLERSHADE` window covering type (lift only, no tilt). |
| 130 | +- The example accepts commands but doesn't actually move a motor. In a real implementation, you should: |
| 131 | + 1. Move the motor to the target position in the callback |
| 132 | + 2. Update `CurrentPositionLiftPercent100ths` using `setLiftPercentage()` when movement is complete |
| 133 | + 3. Set `OperationalState` to `STALL` using `setOperationalState(MatterWindowCovering::LIFT, MatterWindowCovering::STALL)` to indicate the device has reached the target position |
| 134 | +- **Important**: `onGoToLiftPercentage()` is called when `TargetPositionLiftPercent100ths` changes. This happens when commands are executed or when a Matter controller writes directly to the target position attribute. |
| 135 | +- Commands modify `TargetPosition`, not `CurrentPosition`. The application is responsible for updating `CurrentPosition` when the physical device actually moves. |
| 136 | +
|
0 commit comments