python-matter-server
repository·main·Indexed 21 days ago
https://github.com/matter-js/python-matter-serverA certified Matter controller implementation that provides a WebSocket-based server and client, serving as the backbone for Matter integration in Home Assistant and other projects. It utilizes the official Matter (formerly CHIP) SDK. Note: This project has been rewritten and moved to matterjs-server; version 8.1.2 is the final release of python-matter-server.
What's inside python-matter-server
- The Open Home Foundation Matter Server is an officially certified software component used to create a Matter controller. It implements a Matter Controller Server over WebSockets, utilizing the official Matter (formerly CHIP) SDK as its base. It provides both a server and a client implementation and serves as the foundation for Matter support in Home Assistant, though it is designed to be used in other projects as well.
Migrate to matterjs-server
mainIMPORTANT: Deprecation Notice
The
python-matter-serverhas been rewritten and moved to matterjs-server.Version 8.1.2 is the final version of
python-matter-server, its libraries, and the docker-container. This repository will no longer receive updates or support. Users are strongly encouraged to migrate to the new server as soon as possible.Install only the Python client library
mainIf you do not need to run the Matter Server itself but want to interact with an existing server via its Websockets API, you can install only the client library. The client library depends on the
chip/matter clusterspackage, which is platform-independent.Note: The server library requires the Matter Core SDK (CHIP), which is OS and architecture-specific. While wheels are provided for Linux (amd64 and aarch64) on PyPI, macOS users may need to build their own wheels using the SDK version used by the clusters package.
pip install python-matter-serverSet up the Matter Server development environment
mainTo develop with the Matter Server, you must use a recent Linux or MacOS machine. Windows is not supported.
- Clone the repository to your local machine.
- Run the setup script:
scripts/setup.sh. - Ensure a
/datadirectory exists and has the necessary permissions for the user running thepython-matter-server.
# Clone the repo and run setup ./scripts/setup.sh # Ensure data directory exists mkdir /dataConnect the Matter Dashboard to a WebSocket server
mainWhen running the Matter Dashboard, you must provide the WebSocket URL to connect to the Matter Server. The URL depends on your deployment method:
- Local Python Matter Server: Use
ws://localhost:5580. - Home Assistant Add-on: Use a URL like
ws://homeassistant.local:5580.
Configuring the Home Assistant Add-on for Network Access: If using the Home Assistant add-on, you must explicitly enable the WebSocket port for network access:
- Navigate to the Matter Server add-on info page.
- Go to the Configuration tab.
- Under the Network section, select "show disabled ports".
- Enter the desired port for the WebSocket server (e.g.,
5580). - Click Save and restart the add-on when prompted.
- Local Python Matter Server: Use
Install and run the Matter Server
mainDepending on your use case, there are different ways to run the Matter Server:
- Home Assistant Users: Use the official Matter Server add-on. Refer to the Home Assistant documentation for setup instructions.
- Standalone Docker: You can run the Matter Server as a standalone container. See the Docker documentation for specific instructions.
- Developers: To run the server or client in a local development environment, refer to the Development documentation.
Configure networking for Matter Server
mainMatter relies on IPv6 link-local multicast protocols. To ensure successful communication, follow these networking guidelines:
- Network Topology: Use a flat network or ensure the Matter Server, devices, border routers, and commissioning devices (phones) are all on the same (v)LAN. Matter multicast does not work across different LANs or VLANs.
- Multicast Settings: Disable "Multicast optimizations" on professional networking gear (e.g., Unifi, Omada) as they can block Matter traffic.
- mDNS: Do not enable mDNS forwarders on your network, as they can corrupt or hinder Matter packets.
- IGMP/MLD Snooping: If your hardware supports it, experiment with IGMP/MLD snooping settings, as they can either help or hinder traffic.
- IPv6: The host network interface must have IPv6 support enabled.
Enable Bluetooth commissioning in Docker
mainTo use local commissioning via Bluetooth, you must pass the host's D-Bus socket to the container and provide the necessary command-line arguments. If you override the default command, you must include the default arguments (like
--storage-path) to ensure the server starts correctly.docker run -d \ --name matter-server \ --restart=unless-stopped \ --security-opt apparmor=unconfined \ -v $(pwd)/data:/data \ -v /run/dbus:/run/dbus:ro \ --network=host \ ghcr.io/matter-js/python-matter-server:stable --storage-path /data --paa-root-cert-dir /data/credentials --bluetooth-adapter 0Run the Matter Server using a Docker container image
mainYou can run the Matter Server using the official Docker container image. Note that the underlying host operating system must meet the requirements for Matter and Thread (see
os_requirements.md). For Home Assistant users, using the official Matter Server add-on on Home Assistant OS is strongly recommended over a self-managed container to avoid communication issues with Thread devices.By default, network data (fabric information) is stored in a
/datadirectory inside the container. You should map this to a persistent directory on your host.mkdir data docker run -d \ --name matter-server \ --restart=unless-stopped \ --security-opt apparmor=unconfined \ -v $(pwd)/data:/data \ --network=host \ ghcr.io/matter-js/python-matter-server:stableRun the Matter Server using Docker Compose
mainUse the following Docker Compose configuration to manage the Matter Server.
Key Requirements:
network_mode: host: Required for mDNS to work correctly.security_opt: ["apparmor:unconfined"]: Needed for Bluetooth via D-Bus.volumes:- Map a host directory to
/data/for persistent storage. It is recommended to use an.envfile to set theUSERDIRenvironment variable. - Map
/run/dbus:/run/dbus:roto enable Bluetooth via D-Bus.
- Map a host directory to
Note on Command Overrides: If you use the
command:key to pass custom arguments, you must also include the default command-line arguments used by the image.services: # python-matter-server matter-server: image: ghcr.io/matter-js/python-matter-server:stable container_name: matter-server restart: unless-stopped # Required for mDNS to work correctly network_mode: host security_opt: # Needed for Bluetooth via dbus - apparmor:unconfined volumes: # Create an .env file that sets the USERDIR environment variable. - ${USERDIR:-$HOME}/docker/matter-server/data:/data/ # Required for Bluetooth via D-Bus - /run/dbus:/run/dbus:ro # If you adjust command line, make sure to pass the default CMD arguments too: #command: --storage-path /data --paa-root-cert-dir /data/credentials --bluetooth-adapter 0Supported operating systems for Matter Server
mainThe Matter Server requires 64-bit architectures. The following operating systems are supported:
- MacOS: Version 14 or higher (arm-based CPU) is recommended for development. It works out of the box when used with a Python
venv. - Linux: A very recent distribution and kernel are required. The host must be able to process ICMPv6 Router Advertisements.
- Home Assistant OS: Version 10 and newer is fully supported as the Matter Server is provided as an add-on with all necessary fixes included.
- Unsupported: Non-64-bit architectures, other operating systems, and WSL (Windows Subsystem for Linux) are not supported.
- MacOS: Version 14 or higher (arm-based CPU) is recommended for development. It works out of the box when used with a Python
Set up the Matter Dashboard for development
mainTo develop the Matter Dashboard, you must first ensure that the Python Matter Server dependencies are installed on your system. Then, run the setup script to install the dashboard's dependencies.
After setup, you can start the development server. The dashboard will be accessible at
http://localhost:5010. Upon opening the dashboard, you will be prompted to provide your WebSocket server URL.# Install dependencies (requires python matter server dependencies to be present) script/setup # Run the development server script/develop