Matter: Thermostat
This thermostat sample demonstrates the usage of the Matter application layer to build a thermostat device for monitoring temperature values and controlling the temperature. This device works as a Matter accessory device, meaning it can be paired and controlled remotely over a Matter network built on top of a low-power, 802.15.4 Thread network or on top of a Wi-Fi network. In case of Thread, this device works as a Thread Minimal End Device. Support for both Thread and Wi-Fi is mutually exclusive and depends on the hardware platform, so only one protocol can be supported for a specific Matter device.
Additionally, this example allows you to connect to a temperature sensor device that can also be used for temperature measurement.
Requirements
The sample supports the following development kits:
Hardware platforms |
PCA |
Board name |
Board target |
---|---|---|---|
PCA10143 |
|
||
PCA10156 |
|
||
PCA10095 |
|
||
PCA10056 |
|
If you want to commission the device and control it remotely in a Thread network, you also need a Matter controller device configured on PC or smartphone. This requires additional hardware depending on the setup you choose.
Similarly, if you want to test the sample with External sensor integration, you need additional hardware that incorporates a temperature sensor. For example, Nordic Thingy:53, used for the Matter weather station application.
Note
Matter requires the GN tool. If you are updating from the nRF Connect SDK version earlier than v1.5.0, see the GN installation instructions.
IPv6 network support
The development kits for this sample offer the following IPv6 network support for Matter:
Matter over Thread is supported for
nrf52840dk/nrf52840
,nrf5340dk/nrf5340/cpuapp
, andnrf54l15dk/nrf54l15/cpuapp
.Matter over Wi-Fi is supported for
nrf5340dk/nrf5340/cpuapp
with thenrf7002_ek
shield attached or fornrf7002dk/nrf5340/cpuapp
.
Overview
When programmed, the sample starts the Bluetooth® LE advertising automatically and prepares the Matter device for commissioning into a Matter-enabled Thread network. The sample uses an LED to show the state of the connection.
The sample can operate in one of the following modes:
Simulated temperature sensor mode - In this mode, the thermostat sample generates simulated temperature measurements and prints it to the terminal. This is the default mode, in which the sample provides simulated temperature values.
Real temperature sensor mode - In this mode, the thermostat sample is bound to a remote Matter temperature sensor, which provides real temperature measurements. This mode requires External sensor integration.
The sample automatically logs the temperature measurements with a defined interval and it uses buttons for printing the measurement results to the terminal.
You can test the sample in the following ways:
Standalone, using a single DK that runs the thermostat application.
Remotely over the Thread or the Wi-Fi protocol, which in either case requires more devices, including a Matter controller that you can configure either on a PC or a mobile device.
You can enable both methods after building and running the sample.
Configuration
See Configuring and building for information about how to permanently or temporarily change the configuration.
Access Control List
The Access Control List (ACL) is a list related to the Access Control cluster. The list contains rules for managing and enforcing access control for a node’s endpoints and their associated cluster instances. In this sample’s case, this allows the temperature measurement devices to receive messages from the thermostat and provide the temperature data to the thermostat.
You can read more about ACLs on the Access Control Guide in the Matter documentation.
External sensor integration
The thermostat sample lets you connect to an external temperature sensor, for example Matter weather station application on Nordic Thingy:53. This establishes the Binding to Matter’s temperature measurement cluster.
By default, the thermostat sample generates simulated temperature measurements that simulate local temperature changes. Additionally, you can enable periodic outdoor temperature measurements by binding the thermostat with an external temperature sensor device. To test this feature, follow the steps listed in the Testing with external sensor section.
Binding
Binding refers to establishing a relationship between endpoints on the local and remote nodes. With binding, local endpoints are pointed and bound to the corresponding remote endpoints. Both must belong to the same cluster type. Binding lets the local endpoint know which endpoints are going to be the target for the client-generated actions on one or more remote nodes.
In this sample, the thermostat device prints simulated temperature data by default and it does not know the remote endpoints of the temperature sensors (on remote nodes). Using binding, the thermostat device updates its Binding cluster with all relevant information about the temperature sensor devices, such as their IPv6 address, node ID, and the IDs of the remote endpoints that contain the temperature measurement cluster.
Matter thermostat custom configurations
The sample uses a prj.conf
configuration file located in the sample root directory for the default configuration.
It also provides additional files for different custom configurations.
When you build the sample, you can select one of these configurations using the FILE_SUFFIX variable.
See Custom configurations and Providing CMake options for more information.
The sample supports the following configurations:
Configuration |
File name |
FILE_SUFFIX |
Supported board |
Description |
---|---|---|---|---|
Debug (default) |
|
No suffix |
All from Requirements |
Debug version of the application. Enables additional features for verifying the application behavior, such as logs. |
Release |
|
|
All from Requirements |
Release version of the application. Enables only the necessary application functionalities to optimize its performance. |
Matter thermostat with Trusted Firmware-M
The sample supports using Trusted Firmware-M on the nRF54L15 DK. The memory map of the sample has been aligned to meet the TF-M partition alignment requirements.
You can build the sample with Trusted Firmware-M support by adding the ns
suffix to the nrf54l15dk/nrf54l15/cpuapp
board target.
For example:
west build -p -b nrf54l15dk/nrf54l15/cpuapp/ns
Note
The firmware built for nrf54l15dk/nrf54l15/cpuapp/ns
will not work on the nRF54L15 PDK.
Device Firmware Upgrade support
Note
You can enable over-the-air Device Firmware Upgrade only on hardware platforms that have external flash memory. Currently only nRF52840 DK, nRF5340 DK, nRF7002 DK and nRF54L15 DK support Device Firmware Upgrade feature.
The sample supports over-the-air (OTA) device firmware upgrade (DFU) using one of the two following protocols:
Matter OTA update protocol that uses the Matter operational network for querying and downloading a new firmware image.
Simple Management Protocol (SMP) over Bluetooth® LE. In this case, the DFU can be done either using a smartphone application or a PC command line tool. Note that this protocol is not part of the Matter specification.
In both cases, MCUboot secure bootloader is used to apply the new firmware image.
The DFU over Matter is enabled by default. The following configuration arguments are available during the build process for configuring DFU:
To configure the sample to support the DFU over Matter and SMP, use the
-DCONFIG_CHIP_DFU_OVER_BT_SMP=y
build flag.
See Providing CMake options for instructions on how to add these options to your build.
When building on the command line, run the following command with board_target replaced with the board target name of the hardware platform you are using (see Requirements), and dfu_build_flag replaced with the desired DFU build flag:
west build -b board_target -- dfu_build_flag
For example:
west build -b nrf52840dk/nrf52840 -- -DCONFIG_CHIP_DFU_OVER_BT_SMP=y
Remote testing in a network
By default, the Matter accessory device has no IPv6 network configured. You must pair it with the Matter controller over Bluetooth® LE to get the configuration from the controller to use the device within a Thread or Wi-Fi network. The controller must get the Onboarding information from the Matter accessory device and provision the device into the network. For details, see the Commissioning the device section.
Factory data support
In this sample, the factory data support is enabled by default for all configurations except for the target board nRF21540 DK. This means that a new factory data set will be automatically generated when building for the target board.
To disable factory data support, set the following Kconfig options to n
:
SB_CONFIG_MATTER_FACTORY_DATA_GENERATE
To learn more about factory data, read the Configuring factory data for the nRF Connect examples page in the Matter documentation.
User interface
- LED 1:
Shows the overall state of the device and its connectivity. The following states are possible:
Short Flash On (50 ms on/950 ms off) - The device is in the unprovisioned (unpaired) state and is waiting for a commissioning application to connect.
Rapid Even Flashing (100 ms on/100 ms off) - The device is in the unprovisioned state and a commissioning application is connected over Bluetooth LE.
Solid On - The device is fully provisioned.
- Button 1:
Depending on how long you press the button:
If pressed for less than three seconds:
If the device is not provisioned to the Matter network, it initiates the SMP server (Simple Management Protocol) and Bluetooth LE advertising for Matter commissioning. After that, the Device Firmware Update (DFU) over Bluetooth Low Energy can be started. (See Upgrading the device firmware.) Bluetooth LE advertising makes the device discoverable over Bluetooth LE for the predefined period of time (1 hour by default).
If the device is already provisioned to the Matter network, it re-enables the SMP server. After that, the DFU over Bluetooth Low Energy can be started. (See Upgrading the device firmware.)
If pressed for more than three seconds, it initiates the factory reset of the device. Releasing the button within a 3-second window of the initiation cancels the factory reset procedure.
- Button 2:
Prints the most recent thermostat data to terminal.
- SEGGER J-Link USB Port:
Used for getting logs from the device or for communicating with it through the command-line interface.
- NFC port with antenna attached:
Optionally used for obtaining the Onboarding information from the Matter accessory device to start the commissioning procedure.
- LED 0:
Shows the overall state of the device and its connectivity. The following states are possible:
Short Flash On (50 ms on/950 ms off) - The device is in the unprovisioned (unpaired) state and is waiting for a commissioning application to connect.
Rapid Even Flashing (100 ms on/100 ms off) - The device is in the unprovisioned state and a commissioning application is connected over Bluetooth LE.
Solid On - The device is fully provisioned.
- Button 0:
Depending on how long you press the button:
If pressed for less than three seconds:
If the device is not provisioned to the Matter network, it initiates the SMP server (Simple Management Protocol) and Bluetooth LE advertising for Matter commissioning. After that, the Device Firmware Update (DFU) over Bluetooth Low Energy can be started. (See Upgrading the device firmware.) Bluetooth LE advertising makes the device discoverable over Bluetooth LE for the predefined period of time (1 hour by default).
If the device is already provisioned to the Matter network, it re-enables the SMP server. After that, the DFU over Bluetooth Low Energy can be started. (See Upgrading the device firmware.)
If pressed for more than three seconds, it initiates the factory reset of the device. Releasing the button within a 3-second window of the initiation cancels the factory reset procedure.
- Button 1:
Prints the most recent thermostat data to terminal.
- SEGGER J-Link USB Port:
Used for getting logs from the device or for communicating with it through the command-line interface.
- NFC port with antenna attached:
Optionally used for obtaining the Onboarding information from the Matter accessory device to start the commissioning procedure.
Building and running
This sample can be found under samples/matter/thermostat
in the nRF Connect SDK folder structure.
To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.
Note
When building repository applications in the SDK repositories, building with sysbuild is enabled by default.
If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild
parameter to every build command or configure west to always use it.
Selecting a build type
Before you start testing the application, you can select one of the Matter thermostat custom configurations, depending on your building method. See Custom configurations and Providing CMake options for more information how to select a configuration.
Testing
After building the sample and programming it to your development kit, you can either test the sample’s basic features or use the Matter weather station application to test the thermostat with an external sensor.
Testing basic features
After building the sample and programming it to your development kit, complete the following steps to test its basic features:
Connect the kit to the computer using a USB cable. The kit is assigned a COM port (Windows) or ttyACM device (Linux), which is visible in the Device Manager.
Open a serial port connection to the kit using a terminal emulator that supports VT100/ANSI escape characters (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.
Observe that LED 1 starts flashing (short flash on). This means that the sample has automatically started the Bluetooth LE advertising.
Observe the UART terminal. The sample starts automatically printing the simulated temperature data to the terminal with 30-second intervals.
Press Button 2 to print the most recent temperature data to the terminal.
Keep Button 1 pressed for more than six seconds to initiate factory reset of the device.
The device reboots after all its settings are erased.
Connect the kit to the computer using a USB cable. The kit is assigned a COM port (Windows) or ttyACM device (Linux), which is visible in the Device Manager.
Open a serial port connection to the kit using a terminal emulator that supports VT100/ANSI escape characters (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.
Observe that LED 0 starts flashing (short flash on). This means that the sample has automatically started the Bluetooth LE advertising.
Observe the UART terminal. The sample starts automatically printing the simulated temperature data to the terminal with 30-second intervals.
Press Button 1 to print the most recent temperature data to the terminal.
Keep Button 0 pressed for more than six seconds to initiate factory reset of the device.
The device reboots after all its settings are erased.
Testing with external sensor
After building this sample and the Matter weather station application and programming each to the respective development kit and Nordic Thingy:53, complete the following steps to test communication between both devices:
Connect to both kits with a terminal emulator (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.
Connect to both kits with a terminal emulator that supports VT100/ANSI escape characters (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.
If devices were not erased during the programming, press the button responsible for the factory reset on each device.
On each device, press the button that starts the Bluetooth LE advertising.
Commission devices to the Matter network. See Commissioning the device for more information.
During the commissioning process, write down the values for the thermostat node ID, the temperature sensor node ID, and the temperature sensor endpoint ID. These IDs are going to be used in the next steps (<thermostat_node_ID>, <temperature_sensor_node_ID>, and <temperature_sensor_endpoint_ID>, respectively).
Use the CHIP Tool (“Writing ACL to the
accesscontrol
cluster” section) to add proper ACL for the temperature sensor device. Use the following command, with <thermostat_node_ID>, <temperature_sensor_node_ID>, and <temperature_sensor_endpoint_ID> values from the previous step about commissioning:chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null}, {"fabricIndex": 1, "privilege": 1, "authMode": 2, "subjects": [<thermostat_node_ID>], "targets": [{"cluster": 1026, "endpoint": <temperature_sensor_endpoint_ID>, "deviceType": null}]}]' <temperature_sensor_node_ID> 0
Write a binding table to the thermostat to inform the device about the temperature sensor endpoint. Use the following command, with <thermostat_node_ID>, <temperature_sensor_node_ID>, and <temperature_sensor_endpoint_ID> values from the previous step about commissioning:
chip-tool binding write binding '[{"fabricIndex": 1, "node": <temperature_sensor_node_ID>, "endpoint": <temperature_sensor_endpoint_ID>, "cluster": 1026}]' <thermostat_node_ID> 1
(You can read more about this step in the “Adding a binding table to the
binding
cluster” in the CHIP Tool guide.)The thermostat is now able to read the real temperature data from the temperature sensor device. The connection is ensured by Binding to Matter’s temperature measurement cluster.
Press the button that prints the most recent temperature data from the thermostat device to the UART terminal.
Enabling remote control
Remote control allows you to control the Matter thermostat device from an IPv6 network.
Commissioning the device allows you to set up a testing environment and remotely control the sample over a Matter-enabled Thread or Wi-Fi network.
Commissioning the device
Note
Before starting the commissioning to Matter procedure, ensure that there is no other Bluetooth LE connection established with the device.
To commission the device, go to the Testing Matter in the nRF Connect SDK page and complete the steps for the Matter network environment and the Matter controller you want to use. After choosing the configuration, the guide walks you through the following steps:
Only if you are configuring Matter over Thread: Configure the Thread Border Router.
Build and install the Matter controller.
Commission the device.
Send Matter commands that cover scenarios described in the Testing section.
If you are new to Matter, the recommended approach is to use CHIP Tool for Linux or macOS.
Onboarding information
When you start the commissioning procedure, the controller must get the onboarding information from the Matter accessory device. The onboarding information representation depends on your commissioner setup.
For this sample, you can use one of the following onboarding information formats to provide the commissioner with the data payload that includes the device discriminator and the setup PIN code:
QR Code
QR Code Payload
Manual pairing code
Scan the following QR code with the app for your ecosystem:
MT:O4CT342C00KA0648G00
34970112332
When the factory data support is enabled, the onboarding information will be stored in the build directory in the following files:
The
factory_data.png
file includes the generated QR code.The
factory_data.txt
file includes the QR Code Payload and the manual pairing code.
Upgrading the device firmware
To upgrade the device firmware, complete the steps listed for the selected method in the Performing Device Firmware Upgrade in the nRF Connect examples tutorial of the Matter documentation.
Dependencies
This sample uses the Matter library that includes the nRF Connect SDK platform integration layer:
In addition, the sample uses the following nRF Connect SDK components:
The sample depends on the following Zephyr libraries: