Skip to content

feat(matter_server): allow configuring custom primary network interface#4623

Open
txptr wants to merge 4 commits into
home-assistant:masterfrom
txptr:feature-matter-server-custom-network-interface
Open

feat(matter_server): allow configuring custom primary network interface#4623
txptr wants to merge 4 commits into
home-assistant:masterfrom
txptr:feature-matter-server-custom-network-interface

Conversation

@txptr

@txptr txptr commented May 23, 2026

Copy link
Copy Markdown

Description

This PR introduces an optional configuration option matter_server_primary_interface to the Matter Server add-on. This allows users to manually specify the primary network interface used by the Matter Server (e.g., enp0s19), rather than relying solely on the Supervisor's automatic detection.

Motivation & Context

In complex network environments (such as setups with multiple network interfaces, untagged/tagged VLANs, or multiple gateways), the automatic network interface detection by the Home Assistant Supervisor can sometimes select the wrong interface for the Matter Server.

Currently, trying to append --primary-interface via matter_server_args results in duplicate arguments where the automatically detected one takes precedence, making it impossible for users to override it. This PR solves the issue by offering a dedicated, clean UI configuration field.

How Has This Been Tested?

  • Empty configuration (Default): Verified that the add-on falls back seamlessly to the Supervisor's automatic detection. No breaking changes for existing users.
  • Valid interface provided: Verified that the custom interface is correctly injected and used by the Matter Server.
  • Invalid/Typo interface provided: Verified that the built-in safety check (ip link show) detects the missing interface, logs a proper warning/error, and safely falls back to the system default instead of crashing the add-on loop.

Checklist

  • Follows architecture guidelines for Home Assistant add-ons.
  • Includes English translations for the new configuration option.
  • Implementation is fully backwards-compatible.
  • Input validation included to prevent boot-loops caused by user typos.

Summary by CodeRabbit

  • New Features

    • Optional setting to manually specify the Matter Server’s primary network interface or leave empty to use the system default.
    • Added a user-facing name and description for this setting.
  • Bug Fixes / Behavior

    • Better validation and clearer error logging for a user-specified interface.
    • Improved automatic detection fallback; startup now aborts with an explicit error if no primary interface is found.

@home-assistant home-assistant Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @txptr

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant

Copy link
Copy Markdown

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant
home-assistant Bot marked this pull request as draft May 23, 2026 06:58
@txptr
txptr marked this pull request as ready for review May 23, 2026 07:04
@home-assistant
home-assistant Bot dismissed their stale review May 23, 2026 07:04

Stale

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fdda410c-51ea-402f-be1a-6f796f0be091

📥 Commits

Reviewing files that changed from the base of the PR and between ec71a61 and 0599828.

📒 Files selected for processing (1)
  • matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run

📝 Walkthrough

Walkthrough

This PR adds an optional add-on config matter_server_primary_interface, English translation strings, and startup-script logic to validate a configured interface or otherwise detect the primary interface from the supervisor or the default route (and abort if none found).

Changes

Primary Network Interface Configuration

Layer / File(s) Summary
Add primary network interface configuration option
matter_server/config.yaml, matter_server/translations/en.yaml
Adds an optional matter_server_primary_interface schema field and English translation strings.
Startup: validate configured interface
matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run
Startup script verifies a user-configured matter_server_primary_interface via ip link show, logs on missing interface, and uses it only if valid.
Startup: guarded automatic detection
matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run
When no valid configured interface, script queries supervisor /network/info, falls back to ip --json route show default + jq to determine default-route device, and exits if result is empty or \"null\".

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title directly and accurately describes the main change: adding the ability to configure a custom primary network interface for the Matter Server add-on.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
matter_server/translations/en.yaml (1)

68-70: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

The description documents non-functional behavior.

The translation promises that users can "manually specify" the primary network interface, but the runtime script does not read or use the matter_server_primary_interface configuration value (see issue raised in config.yaml). Until the runtime implementation is added, this description misleads users about the option's functionality.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@matter_server/translations/en.yaml` around lines 68 - 70, The translation for
matter_server_primary_interface claims a manual override but the runtime does
not read or use that config key; update the translation text to avoid promising
functionality that doesn't exist (e.g., remove "Manually specify" and indicate
it's reserved/unused) OR implement the runtime support that reads
matter_server_primary_interface and applies it when selecting the primary
interface; locate the setting by the symbol matter_server_primary_interface and
either change its description in en.yaml to reflect current behavior or add code
in the runtime (configuration parsing and interface selection) to honor that
key.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@matter_server/translations/en.yaml`:
- Around line 68-70: The translation for matter_server_primary_interface claims
a manual override but the runtime does not read or use that config key; update
the translation text to avoid promising functionality that doesn't exist (e.g.,
remove "Manually specify" and indicate it's reserved/unused) OR implement the
runtime support that reads matter_server_primary_interface and applies it when
selecting the primary interface; locate the setting by the symbol
matter_server_primary_interface and either change its description in en.yaml to
reflect current behavior or add code in the runtime (configuration parsing and
interface selection) to honor that key.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 33f15d78-4aaf-4118-9146-da232d3b3035

📥 Commits

Reviewing files that changed from the base of the PR and between b4adbd5 and 9aaa7d1.

📒 Files selected for processing (2)
  • matter_server/config.yaml
  • matter_server/translations/en.yaml

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run (1)

144-151: ⚡ Quick win

Consider quoting variables instead of disabling shellcheck warnings.

Lines 145 and 151 use unquoted ${primary_interface} with shellcheck SC2086 explicitly disabled. While the practical risk is low (network interface names don't contain spaces or glob characters), following bash best practices by quoting variables improves code maintainability and prevents potential future issues.

♻️ Proposed fix: Quote the variables
-    # shellcheck disable=SC2086
-    if [ -z ${primary_interface} ]; then
+    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')"
     fi
 
-    # shellcheck disable=SC2086
-    if [ -z ${primary_interface} ] || [ ${primary_interface} == "null" ]; then
+    if [ -z "${primary_interface}" ] || [ "${primary_interface}" == "null" ]; then
         bashio::exit.nok "No primary network interface found!"
     fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run` around lines
144 - 151, The checks and tests around the primary_interface variable disable
SC2086 instead of quoting; update the run script to quote variable expansions
for primary_interface (e.g., replace unquoted uses in the if tests that
currently read [ -z ${primary_interface} ] and [ ${primary_interface} == "null"
] with quoted expansions like [ -z "${primary_interface}" ] and [
"${primary_interface}" = "null" ] or the bash equivalent), and ensure any other
references in this block use "${primary_interface}" so ShellCheck SC2086 can be
removed safely; keep the same logic (fallback ip/jq assignment to
primary_interface and subsequent null check) but use quoted comparisons.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run`:
- Around line 144-151: The checks and tests around the primary_interface
variable disable SC2086 instead of quoting; update the run script to quote
variable expansions for primary_interface (e.g., replace unquoted uses in the if
tests that currently read [ -z ${primary_interface} ] and [ ${primary_interface}
== "null" ] with quoted expansions like [ -z "${primary_interface}" ] and [
"${primary_interface}" = "null" ] or the bash equivalent), and ensure any other
references in this block use "${primary_interface}" so ShellCheck SC2086 can be
removed safely; keep the same logic (fallback ip/jq assignment to
primary_interface and subsequent null check) but use quoted comparisons.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e4f0def9-64ad-437d-adbc-209cf3b97f71

📥 Commits

Reviewing files that changed from the base of the PR and between 9aaa7d1 and 7b6de40.

📒 Files selected for processing (1)
  • matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run`:
- Around line 144-149: The fallback detection is only run when primary_interface
is empty, so if Supervisor sets primary_interface to the literal string "null"
the fallback is skipped and the later abort triggers; change the first guard so
it treats "null" the same as empty (i.e., update the if that checks
primary_interface before running the fallback to check for -z OR equality to
"null"), leaving the later abort check intact and keeping the fallback
assignment (primary_interface="$(ip --json route show default | jq --raw-output
'.[0].dev')") in the same block.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5728d18e-4a8f-4a35-8bbd-61dd49873fc2

📥 Commits

Reviewing files that changed from the base of the PR and between 7b6de40 and ec71a61.

📒 Files selected for processing (1)
  • matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run

Comment thread matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run Outdated
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@agners

agners commented Jun 11, 2026

Copy link
Copy Markdown
Member

Currently, trying to append --primary-interface via matter_server_args results in duplicate arguments where the automatically detected one takes precedence, making it impossible for users to override it.

At least for the Python Matter Server this is actually not true, see also #4070 (comment). From my perspective this flag does not make sense for this and the other reasons I brought forward in that PR.

As for the matter.js server I am not sure. But if we add this flag, I'd definitely do it imminent promotion of matter.js to default (#4642).

@Apollon77

Copy link
Copy Markdown
Contributor

Yeah matter.js works a bit different here. For us this is basically the main "MDNS listen and send interface". so yes it is basically also used to handle link local scoping but mainly because we should only get announces from that interface, so yes here it makes more sense.

@txptr we plan the relewae of the server 9.0 for next week and I would like to plan this in for after this. So it would be great if you could then next week after merging the 9.0 PR then add changelog for a 9.0.1

@txptr

txptr commented Jun 12, 2026

Copy link
Copy Markdown
Author

@Apollon77 thank you. I will definitely do this.

@agners

agners commented Jun 12, 2026

Copy link
Copy Markdown
Member

@txptr what I would prefer is if we'd have a generic network interface isolation based on macvlan or ipvlan for apps which run on host network. This idea exists since a while, see home-assistant/architecture#1034. I created a prototype today, and at least in my testing it worked fine with Matter over Thread devices (see home-assistant/architecture#1034 (comment)).

Would this suite your use case as well?

@txptr

txptr commented Jun 14, 2026

Copy link
Copy Markdown
Author

@Apollon77 @agners

Thank you all for taking time for my pr and your insightful feedback.

I completely agree that the proposed larger overhaul - introducing native macvlan or isolated network support directly into the Supervisor - is conceptually the most elegant and robust long-term solution. It would fundamentally solve mDNS, multicast, and routing issues for complex addons across the entire ecosystem.

However, since implementing such a core architectural change in the Supervisor will understandably take considerable time to specify, develop, and thoroughly test, I would love to propose my current PR as a pragmatic, low-risk bridge solution (quick win).

My patch:

  • Fixes an acute pain point for Matter users right now.
  • Requires zero changes to the Supervisor core.
  • Is fully backward-compatible.

Once the grand network reform for the Supervisor is ready and rolled out, the matter_server_primary_interface configuration flag can easily be deprecated and removed.

I am happy to adjust my PR based on whichever direction the core team decides to prioritize, but I believe delivering this relief to users today would be highly beneficial while we work towards the ideal architecture.

You decide :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants