diff --git a/matter_server/config.yaml b/matter_server/config.yaml index a1f56d00d..739a42b01 100644 --- a/matter_server/config.yaml +++ b/matter_server/config.yaml @@ -35,6 +35,7 @@ schema: enable_test_net_dcl: bool? ble_proxy: bool? bluetooth_adapter_id: int? + matter_server_primary_interface: str? matter_server_args: - str? matter_server_env_vars: diff --git a/matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run b/matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run index 540a0e81a..f3feda28c 100755 --- a/matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run +++ b/matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run @@ -122,18 +122,33 @@ if bashio::config.true "enable_test_net_dcl"; then extra_args+=('--enable-test-net-dcl') fi -primary_interface="$(bashio::api.supervisor 'GET' '/network/info' '' 'first(.interfaces[] | select (.primary == true)) .interface')" - -# Try fallback method (e.g. in case NetworkManager is not available) -# shellcheck disable=SC2086 -if [ -z ${primary_interface} ]; then - bashio::log.warning 'Trying fallback method to determine primary interface' - primary_interface="$(ip --json route show default | jq --raw-output '.[0].dev')" +# Check if the user configured a custom primary interface +if bashio::config.has_value 'matter_server_primary_interface'; then + custom_interface=$(bashio::config 'matter_server_primary_interface') + + # Check if the configured interface actually exists in the system + if ip link show "$custom_interface" > /dev/null 2>&1; then + bashio::log.info "Using manually configured network interface: ${custom_interface}" + primary_interface="$custom_interface" + else + bashio::log.error "The configured network interface '${custom_interface}' was not found on the host!" + bashio::log.warning "Falling back to automatic interface detection." + fi fi -# shellcheck disable=SC2086 -if [ -z ${primary_interface} ] || [ ${primary_interface} == "null" ]; then - bashio::exit.nok "No primary network interface found!" +# Run automatic detection if no custom interface was set or if the custom one failed +if [ -z "${primary_interface}" ]; then + primary_interface="$(bashio::api.supervisor 'GET' '/network/info' '' 'first(.interfaces[] | select (.primary == true)) .interface')" + + # Try fallback method (e.g. in case NetworkManager is not available) + if [ -z "${primary_interface}" ] || [ "${primary_interface}" = "null" ]; then + bashio::log.warning 'Trying fallback method to determine primary interface' + primary_interface="$(ip --json route show default | jq --raw-output '.[0].dev')" + fi + + if [ -z "${primary_interface}" ] || [ "${primary_interface}" == "null" ]; then + bashio::exit.nok "No primary network interface found!" + fi fi if bashio::config.true "ble_proxy"; then diff --git a/matter_server/translations/en.yaml b/matter_server/translations/en.yaml index 5becc2567..35cfd140e 100644 --- a/matter_server/translations/en.yaml +++ b/matter_server/translations/en.yaml @@ -65,5 +65,8 @@ configuration: Install custom Python Matter SDK wheels version (not applicable when using Beta flag). NOTE: The API might not be compatible with the Python Matter server. + matter_server_primary_interface: + name: "Primary Network Interface" + description: "Manually specify the primary network interface for the Matter Server (e.g., enp0s19). Leave empty to use the system default." network: 5580/tcp: Matter Server WebSocket server port.