Old Macdonald - Decentralised Controlled Environment Agriculture System Help

Matter Relay Switch

Overview

The Matter Relay Switch is a Matter-compatible REED device that can be controlled remotely to turn a relay on or off. It can be used to control various devices, such as lights or fans.

This section describes the development of the Matter Relay Switch.

Source Code: GitHub

Prerequisites:

Hardware Assembly

Wiring Relay to ESP32

The Valefod 5V 1-Channel Relay Module is used to control loads up to 10A using a low-power control signal from a microcontroller such as an Arduino or ESP32. It features optocoupler isolation for improved signal integrity and supports both high and low trigger configurations.

The relay has the following terminal layout:

  • Side 1: Control Terminals

    • DC+ (Power Supply Positive): Connect to a 5V power supply.

    • DC- (Power Supply Negative): Connect to the ground of the power supply.

    • IN (Input Signal): Connect to a GPIO pin on the microcontroller to control the relay.

  • Side 2: Switch Terminals

    • COM (Common Terminal): Shared terminal for the relay's switch.

    • NO (Normally Open): Open circuit by default; closes when the relay is activated.

    • NC (Normally Closed): Closed circuit by default; opens when the relay is activated.

The Normally Open (NO) terminal is used when the circuit should remain open (off) by default, requiring activation to close the circuit. The Normally Closed (NC) terminal is used when the circuit should remain closed (on) by default, opening only when the relay is activated.

Wiring Relay to ESP32
Wiring Relay to ESP32
Wiring Relay to ESP32
Wiring Relay to ESP32

Firmware Development

The firmware uses the ESP-IDF framework with the SDK for Matter. It sets up an On/Off endpoint and configures callbacks to manage Matter attributes, enabling GPIO-based relay control.

GPIO Configuration

The header file $IDF_PATH/components/esp_driver_gpio/include/driver/gpio.h can be included with:

#include "driver/gpio.h"

This header file is a part of the API provided by the esp_driver_gpio component. To declare that your component depends on esp_driver_gpio, the following line has to be added to CMakeLists.txt:

REQUIRES esp_driver_gpio

or

PRIV_REQUIRES esp_driver_gpio

Startup Process

The device boots up and loads the firmware, initializing flash memory, configuring system memory, setting up GPIOs, and loading stored data from NVS.

Once initialization is complete, it starts the Matter stack, creates the relay node, and runs the OpenThread stack. Finally, it begins BLE advertising (CHIPoBLE) to enable pairing.

Testing

Testing with CHIP-Tool

Refer to CHIP-Tool for more details.

matter config matter onboardingcodes ble matter esp attribute set 0x1 0x6 0x0 1 matter esp attribute get 0x1 0x6 0x0
Last modified: 26 March 2025