Matter Data Model Generator Tool
This tool generates C++ header and source files for Matter clusters and device types directly from Matter specification XML files.
Overview
The generator performs two main steps:
- XML Processing: Parses Matter specification XML files to generate intermediate JSON representations
- Code Generation: Uses the intermediate JSON files to generate C++ header and source files
Prerequisites
- ESP-Matter repository cloned with submodule update (Tool will select default xml files from connectedhomeip submodule directory)
ESP_MATTER_PATHenvironment variable set to your ESP-Matter repository path
Installation
Follow the steps below to set up ESP-Matter and install the required dependencies.
1. Clone ESP-Matter
If you haven't already cloned the repository, follow the official guide:
https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html
2. Set Environment Variable
Set the ESP_MATTER_PATH environment variable to point to your local ESP-Matter directory.
export ESP_MATTER_PATH=/path/to/esp-matter
3. Install Python Dependencies
pip install -r tools/data_model_gen/requirements.txt
Usage
Basic Usage
# Run the complete generation process
# Data Model files generated with default 1.5 Matter specification.
python data_model_gen.py
This will:
- Parse all Matter XML files from the default location (
connectedhomeip/data_model/<default_version>) - Generate intermediate JSON files in default (
out) directory - Generate C++ header and source files in the default output directory (
$ESP_MATTER_PATH/components/esp_matter/data_model/generated)
Note: Generated files may not be properly formatted. Run pre-commit to format them before committing.
Advanced Usage
# Run --help command for more advanced usage
python data_model_gen.py --help
Note: Single device file generation is intended for testing purposes only and may not produce compliant device types. Example:
python data_model_gen.py --device-file <device.xml>
Module-Specific Scripts
Run module scripts using Python’s module interface (-m) from the project root.
Generate XML files
python -m xml_processing.xml_parser
For available options:
python -m xml_processing.xml_parser --help
Generate data model source and header files
python -m code_generation.code_generator
For available options:
python -m code_generation.code_generator --help
Generated Files
Intermediate JSON Files
The tool generates following intermediate JSON files during processing:
clusters.json: Contains clusters with their attributes, commands, events, and other datadevice_types.json: Contains device types with their required clustersdelegate_clusters.json: Lists clusters with delegatesinternally_managed_attributes.json: Lists attributes managed by ConnectedHomeIPplugin_init_cb_clusters.json: Lists clusters with plugin init callbackszap_filter_list.json: Filters attributes, commands, events based on ZAP XML filesmigrated_clusters.json: Lists clusters migrated to the code-driven approach
Output C++ Files
For each cluster and device type, the tool generates:
- Cluster files:
on_off.h,on_off.cppandon_off_ids.hfromon_off.xml - Device files:
extended_color_light.handextended_color_light.cppfromextended_color_light.xml
These files are organized in the output directory structure:
<output-dir>/
├── clusters/
│ ├── on_off/
│ │ ├── on_off_ids.h
│ │ └── on_off.h
│ │ └── on_off.cpp
│ └── ...
└── device_types/
├── extended_color_light_device/
│ ├── extended_color_light.h
│ └── extended_color_light.cpp
└── ...