This application note describes how to create a simple smart lamp device and connect it to NavQ Plus using the Matter protocol.
1. Matter Protocol
The Matter protocol, formerly known as Project CHIP (Connected Home over IP), is an open-source smart home connectivity standard developed by the Connectivity Standards Alliance (CSA). It aims to create a unified and secure standard for smart home devices, allowing them to seamlessly communicate with each other and integrate into different ecosystems.
Matter protocol is designed to address the interoperability challenges faced by consumers, device manufacturers, and smart home platforms. By adopting a common networking protocol, Matter enables devices from different brands to work together, regardless of their underlying technology or communication method. This simplifies the setup process, enhances device compatibility, and provides a more cohesive and user-friendly smart home experience.
Matter protocol is built upon existing IP-based technologies, such as Ethernet, Wi-Fi, and Thread, and leverages standard internet protocols like IPv6 and TCP/UDP. It aims to provide reliable and secure connectivity while ensuring data privacy and minimizing latency.
With the support of major industry players, including Apple, Google, Amazon, and other members of the CSA, the Matter protocol is expected to become a widely adopted standard, driving the growth and development of the smart home industry.
2. Home Assistant
Home Assistant is an open-source home automation platform that allows you to control and automate various smart devices and services within your home. It provides a unified interface to interact with devices from different brands and protocols, enabling seamless integration and automation.
Home Assistant supports a wide range of devices, including lights, thermostats, cameras, sensors, and more. Home Assistant also offers a user-friendly web-based interface and mobile apps for convenient control and management of your smart home.
With Home Assistant, you can create custom automations, set up schedules, and create complex routines to control your devices based on different triggers and conditions. It also integrates with popular voice assistants like Amazon Alexa and Google Assistant, allowing you to control your smart home using voice commands.
Home Assistant has a large and active community of users and developers who contribute to its continuous improvement. It offers extensive customization options, flexibility, and compatibility with a wide range of smart home devices, making it a popular choice for DIY smart home enthusiasts.
3. Prerequisites
Before proceeding with the setup, make sure you have the following:
NAVQ Plus #1: This will serve as the Matter device and will be referred to as server in further steps. Console commands will have the 'server' prompt.
NAVQ Plus #2 or a Linux PC: This will serve as the Matter client and will be referred to as client in further steps.
4. Software Setup
To ensure the proper operation of the Matter Python library with the NAVQ Plus, please use the NAVQ+ BSP Release 1.1.10 or a higher version.
If you have any previous Matter configuration files that are no longer required, it is recommended to clean them up. Use the following command to remove the chip-tool
data:
user@server:~$ sudo rm -rf /tmp/chip_*
5. Lighting Demo
The BSP ships with a lighting demo written in C. You can run it by issuing the following command on NAVQ Plus #1:
user@server:~$ sudo chip-lighting-app
In the output you will see:
Pin Code: 202021
Discriminator: 3840
Manual pairing code: 34970112332
Link to QR code image
Let's attempt to connect to the Matter device on NAVQ Plus #1 from NAVQ Plus #2 (or a Linux PC) using Node ID 12 and the pairing code obtained in the previous step:
user@client:~$ chip-tool pairing code 12 34970112332
You will see Device commissioning completed with success
when the pairing process is complete.
We can now attempt to control our smart lamp running on NAVQ Plus. Let's switch it on and off.
user@client:~$ chip-tool onoff on 12 1 user@client:~$ chip-tool onoff off 12 1
6. Getting Matter QR Code
When you run chip-lighting-app
or the Python script, the program output will include a link to a QR code for connecting your device via Matter. The link will be in the following format: https://project-chip.github.io/connectedhomeip/qrcode.html?data=MT%3A-24J042C00KA0648G00
To display the QR code, open the provided link in your web browser.
You will need this QR code when connecting devices to Home Assistant or other Matter software.
7. Automated WiFi Configuration
If you want Matter to configure the WiFi network on your NAVQ Plus automatically, run the demo from the previous step with the --wifi
parameter:
user@server:~$ sudo chip-lighting-app --wifi
Use the following command for pairing:
user@client:~$ chip-tool pairing ble-wifi 12 mywifi mypassword 20202021 3840
Replace
12
with the actual Node ID;
Replace
mywifi
with your WiFi network's SSID;
Replace
mypassword
with your WiFi network's password.
The PIN code for this demo setup is 20202021, and the discriminator is 3840.
This command will configure the WiFi on your NAVQ Plus, allowing you to issue commands to control the lamp:
user@client:~$ chip-tool onoff on 12 1 user@client:~$ chip-tool onoff off 12 1
8. Smart Lamp
In the previous step, we only sent commands without actually controlling anything. Now, let's use Matter's ON and OFF commands to control the Status LED on the NAVQ Plus.
We will use Python to create this quick demo.
To begin, create a lighting.py
file and open it in an editor:
user@server:~$ vim lighting.py
Modify the file contents as follows:
from chip.server import ( GetLibraryHandle, NativeLibraryHandleMethodArguments, PostAttributeChangeCallback, ) from chip.exceptions import ChipStackError import sys import os @PostAttributeChangeCallback def attributeChangeCallback( endpoint: int, clusterId: int, attributeId: int, xx_type: int, size: int, value: bytes, ): if endpoint == 1: if clusterId == 6 and attributeId == 0: if len(value) >= 1 and value[0] == 1: print("[PY] light on") os.system("echo 1 > /sys/class/leds/status/brightness") else: print("[PY] light off") os.system("echo 0 > /sys/class/leds/status/brightness") chipLib = GetLibraryHandle(attributeChangeCallback) input('Press enter to quit') sys.exit(0)
This script accepts Matter connections and controls the status LED. Please refer to the application note Controlling Status LED from Linux for detailed instructions on how to control the status LED.
Save the file, close it, and then execute the following command to run the script:
user@server:~$ sudo python3 lighting.py
To control the status LED, send ON/OFF/TOGGLE commands from the client machine:
user@client:~$ chip-tool onoff on 12 1 user@client:~$ chip-tool onoff off 12 1
Here's how our server will appear when ON and OFF commands are received:
Please refer to the Setting up Home Assistant with Matter plugin on NAVQ Plus application note to replace the Matter client with a Home Assistant server using the Matter plugin (currently in beta state).