Skip to content

Comments

Matter server: primary_interface config option#4070

Closed
elestril wants to merge 2 commits intohome-assistant:masterfrom
elestril:master
Closed

Matter server: primary_interface config option#4070
elestril wants to merge 2 commits intohome-assistant:masterfrom
elestril:master

Conversation

@elestril
Copy link

@elestril elestril commented Jul 6, 2025

Allow to configure primary_interface in addon json

That was probably the intent of #3468, but the run script overrides --primary_interface even when provided in matter_server_args

Closes: #4028

See also: https://community.home-assistant.io/t/home-assistant-cant-add-matter-devices-that-are-in-a-different-vlan/750324/54

[23:15:19] INFO: Using 'end0.2' as primary network interface.
[...]
2025-07-05 23:29:34.356 (MainThread) INFO [matter_server.server.device_controller] Starting Matter commissioning with code using Node ID 19.
2025-07-05 23:29:35.656 (Dummy-2) INFO [chip.ChipDeviceCtrl] Established secure session with Device
2025-07-05 23:29:40.972 (Dummy-2) INFO [chip.ChipDeviceCtrl] Commissioning complete
2025-07-05 23:29:40.973 (MainThread) INFO [matter_server.server.device_controller] Commissioned Node ID: 19 vs 19
2025-07-05 23:29:40.974 (MainThread) INFO [matter_server.server.device_controller] Matter commissioning of Node ID 19 successful.
2025-07-05 23:29:40.974 (MainThread) INFO [matter_server.server.device_controller] Interviewing node: 19
2025-07-05 23:29:41.898 (MainThread) INFO [matter_server.server.device_controller] <Node:19> Setting-up node...
2025-07-05 23:29:41.902 (MainThread) INFO [matter_server.server.device_controller] <Node:19> Setting up attributes and events subscription.
2025-07-05 23:29:42.164 (MainThread) INFO [matter_server.server.device_controller] <Node:19> Subscription succeeded with report interval [1, 60]
2025-07-05 23:29:42.166 (MainThread) INFO [matter_server.server.device_controller] Commissioning of Node ID 19 completed.

Summary by CodeRabbit

  • New Features

    • Added a new configuration option to specify the primary network interface for provisioning Matter devices.
    • Updated English translations to describe the new primary network interface option.
  • Documentation

    • Updated changelog to document the new configuration option and version bump to 8.0.1.
  • Chores

    • Updated configuration file version to 8.0.1.

Allow primary_interface to be manually set in config
Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @elestril

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 home-assistant bot marked this pull request as draft July 6, 2025 06:30
@home-assistant
Copy link

home-assistant bot commented Jul 6, 2025

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.

@elestril elestril marked this pull request as ready for review July 6, 2025 06:32
@home-assistant home-assistant bot dismissed their stale review July 6, 2025 06:32

Stale

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 6, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new optional configuration option, primary_interface, allowing users to specify the primary network interface for the Matter Server. The configuration, translation, and startup script are updated to support and document this option, enabling explicit interface selection instead of relying solely on automatic detection.

Changes

File(s) Change Summary
matter_server/CHANGELOG.md Added changelog entry for version 8.0.1, documenting the new primary_interface configuration option.
matter_server/config.yaml Updated version to 8.0.1; added primary_interface option and schema entry (optional string).
matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run Modified logic to use primary_interface from config if set, otherwise fallback to supervisor API.
matter_server/translations/en.yaml Added translation strings for primary_interface configuration option (name and description).

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Config
    participant StartupScript
    participant SupervisorAPI

    User->>Config: Sets primary_interface (optional)
    StartupScript->>Config: Reads primary_interface
    alt primary_interface is set
        StartupScript->>StartupScript: Use configured value
    else primary_interface not set
        StartupScript->>SupervisorAPI: Query for primary interface
        SupervisorAPI-->>StartupScript: Return detected interface
    end
    StartupScript->>MatterServer: Start with selected primary interface
Loading

Assessment against linked issues

Objective Addressed Explanation
Add configuration option to specify primary network interface for Matter Server (#4028)
Ensure startup logic honors user-specified primary_interface over automatic detection (#4028)
Document and localize the new configuration option (#4028)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 8a9aa96 and dab029d.

📒 Files selected for processing (2)
  • matter_server/CHANGELOG.md (1 hunks)
  • matter_server/config.yaml (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • matter_server/CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • matter_server/config.yaml

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 547c0f1 and 8a9aa96.

📒 Files selected for processing (4)
  • matter_server/CHANGELOG.md (1 hunks)
  • matter_server/config.yaml (3 hunks)
  • matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run (1 hunks)
  • matter_server/translations/en.yaml (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
`*/**(html|markdown|md)`: - For instructional content in documentation, use a di...

*/**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • matter_server/CHANGELOG.md
  • matter_server/config.yaml
`*/**(html|markdown|md)`: - Use bold to mark UI strings. - If "" are used to mark UI strings, replace them by bold.

*/**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • matter_server/CHANGELOG.md
  • matter_server/config.yaml
`*/**(html|markdown|md)`: - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

*/**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • matter_server/CHANGELOG.md
  • matter_server/config.yaml
`*/**(html|markdown|md)`: - Use sentence-style capitalization also in headings.

*/**(html|markdown|md): - Use sentence-style capitalization also in headings.

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • matter_server/CHANGELOG.md
  • matter_server/config.yaml
`*/**(html|markdown|md)`: do not comment on HTML used for icons

*/**(html|markdown|md): do not comment on HTML used for icons

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • matter_server/CHANGELOG.md
  • matter_server/config.yaml
`*/**(html|markdown|md)`: Avoid flagging inline HTML for embedding videos in future reviews for this repository.

*/**(html|markdown|md): Avoid flagging inline HTML for embedding videos in future reviews for this repository.

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • matter_server/CHANGELOG.md
  • matter_server/config.yaml
🔇 Additional comments (4)
matter_server/config.yaml (2)

2-2: LGTM - Version bump is appropriate.

Version bump to 8.0.1 is correctly applied for the new feature addition.


42-42: LGTM - Schema definition is correct.

The schema definition for primary_interface as an optional string is appropriate.

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

56-60: LGTM - Conditional logic correctly implements the new feature.

The implementation properly checks for user-configured primary_interface and falls back to the supervisor API when not set. This addresses the original issue where the run script would override the --primary_interface argument even if specified in matter_server_args.

matter_server/translations/en.yaml (1)

45-49: LGTM - Translation entry is clear and informative.

The translation entry provides appropriate name and description for the primary_interface configuration option, clearly explaining its purpose for overriding the default system primary interface used for provisioning Matter devices.

@agners
Copy link
Member

agners commented Jul 8, 2025

Hm, if you specify --primary-interface in matter_server_args, it really should specify the argument twice, and by default in Python argument parsing (as the Python Matter Server is using), the last one wins. And since matter_server_args get appended at the end of the args list, using matter should actually work. 🤔

Did you use separate fields for the argument (--primary-interface) and the value?

@Gunni
Copy link

Gunni commented Jul 18, 2025

Regardless of whether that works or not, having the option spelled out like this makes it much easier to discover rather than a wormhole of googling and trying to figure out how to isolate matter/thread devices from the internet.

@agners
Copy link
Member

agners commented Aug 7, 2025

Regardless of whether that works or not, having the option spelled out like this makes it much easier to discover rather than a wormhole of googling and trying to figure out how to isolate matter/thread devices from the internet.

The problem is that the primary interface argument is really somewhat misleading: It has very limited significance currently, as it only scopes link-local addresses which we receive from the Android App (see #3468 (comment), or more specifically matter-js/python-matter-server#501).

Ultimately this argument likely will be removed again from the Matter Server, once we have a way to rediscover the Matter device commissioned through Android.

If discovering the configuration is a problem, we can promote the --primary-interface argument in the Matter Server add-on DOCS.md, e.g. by using the GitHub tip markdown syntax to highlight the feature, e.g.:

Tip

If you are using Android to commission Matter devices, the Matter device needs to be on reachable through the network interface considered as primary interface by Home Assistant (check ha network info to see which device is the primary interface). If you are trying to commission a device on a different network than what is considered primary, specify --primary-interface and the interface name in the "Extra Matter Server arguments" configuration option.

That said, I just double checked again, specifying the argument in the extra argument list seems to work. I am closing this PR as adding a dedicated option is not the right approach here.

@agners agners closed this Aug 7, 2025
@csuich2
Copy link

csuich2 commented Aug 7, 2025

That said, I just double checked again, specifying the argument in the extra argument list seems to work. I am closing this PR as adding a dedicated option is not the right approach here.

Can you elaborate on what you did to make it work? We have multiple reports from people (including myself) that adding the argument has no impact and that is verified by the log messages which are using the default interface rather than the specified interface.

@agners
Copy link
Member

agners commented Aug 7, 2025

Can you elaborate on what you did to make it work? We have multiple reports from people (including myself) that adding the argument has no impact and that is verified by the log messages which are using the default interface rather than the specified interface.

I've simply added it to the Extra Matter Server arguments.

The follow log message is a red herring, this is a SDK detected primary interface which has no significance:

[1754569841.127987][9946:9946] CHIP:DL: Found the primary Ethernet interface:eno2

See: #4092 (comment)

@csuich2
Copy link

csuich2 commented Aug 7, 2025

I see, you're saying that the log message is coming from the script which is just indicating what it autodetected, but the service itself is properly using the second primary interface argument which is the one specified by the user?

@agners
Copy link
Member

agners commented Aug 7, 2025

I see, you're saying that the log message is coming from the script which is just indicating what it autodetected, but the service itself is properly using the second primary interface argument which is the one specified by the user?

Exactly, the Python Matter Server code itself is using the last --primary-interface argument.

I've opened a PR to print the primary interface name as known by the Matter Server (see matter-js/python-matter-server#1212). With that it should be easier to verify that the argument indeed is processed correctly.

@Gunni
Copy link

Gunni commented Aug 7, 2025

Does changing primary interface do anything to prevent Thread devices from accessing the internet?

@agners
Copy link
Member

agners commented Aug 8, 2025

Does changing primary interface do anything to prevent Thread devices from accessing the internet?

No. Currently, the primary interface only has influence during commissioning with the Android Companion app.

@csuich2
Copy link

csuich2 commented Aug 9, 2025

No. Currently, the primary interface only has influence during commissioning with the Android Companion app.

I think that's actually what I'm after. When I try to add a Matter device on another vlan it connects to wifi just fine but then fails to be added to Home Assistant. I tried adding another network interface to Home Assistant on that vlan but that didn't work which is how I ended up on this issue.

@agners
Copy link
Member

agners commented Aug 11, 2025

When I try to add a Matter device on another vlan it connects to wifi just fine but then fails to be added to Home Assistant.

... using Android? Yes, then that is what primary interface is helping to solve. You should be able to fix it by adding --primary-interface and <iface> to the extra argument list (as separate things, IIRC).

@elestril
Copy link
Author

elestril commented Sep 1, 2025

Sorry for letting this go stale.

To wrap this up:

matter_server_args:
  - "--primary-interface=end0.2"

does achieve the same thing, and using the = syntax avoids awkwardly splitting in two separate args.

Log from mainline version, using this config (relevant lines):

[11:08:30] INFO: Starting Matter Server...
[..]
[11:08:33] INFO: Using 'end0' as primary network interface.
[..]
2025-09-01 11:08:43.170 (MainThread) INFO [matter_server.server.server] Matter Server initialized
2025-09-01 11:08:43.170 (MainThread) INFO [matter_server.server.server] Using 'end0.2' as primary interface (for link-local addresses)
2025-09-01 11:08:43.173 (MainThread) INFO [matter_server.server.server] Starting the Matter Server...
[..]
2025-09-01 11:08:43.886 (MainThread) INFO [matter_server.server.server] Matter Server successfully initialized.
2025-09-01 11:10:04.004 (MainThread) INFO [matter_server.server.device_controller] Starting Matter commissioning using Node ID 1 and IP fe80::42ae:30ff:fea5:db64%end0.2.
2025-09-01 11:10:05.873 (Dummy-2) INFO [chip.ChipDeviceCtrl] Established secure session with Device
2025-09-01 11:10:11.373 (Dummy-2) INFO [chip.ChipDeviceCtrl] Commissioning complete
2025-09-01 11:10:11.374 (MainThread) INFO [matter_server.server.device_controller] Matter commissioning of Node ID 1 successful.

So the 11:08:33 log is indeed a red herring.

I would still argue that primary_interface should be a first class documented config option, not hidden in extra args. But it does work without it.

@snovotill
Copy link

This problem continues to manifest in Incus OCI host-networking deployments.
home-assistant/core#152848

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.

Matter Server: --primary-interface not recognizing VLAN

5 participants