-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[router] Add documentation for new router speaker #6671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kahrendt
wants to merge
2
commits into
esphome:next
Choose a base branch
from
kahrendt:router-speaker-documentation
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| --- | ||
| description: "Instructions for setting up router speakers in ESPHome." | ||
| title: "Router Speaker" | ||
| --- | ||
|
|
||
| The `router` speaker platform allows you to switch which [speaker component](/components/speaker/) receives audio at | ||
| runtime. The router acts as a single speaker that an audio producer (such as a [media player](/components/media_player/) | ||
| or a [mixer speaker](/components/speaker/mixer/)) sends audio to, and it forwards that audio to whichever output speaker | ||
| is currently active. Use the [switch output action](#router_speaker-switch_output) to change the active output while | ||
| audio is playing, for example to move playback between an I²S speaker and an | ||
| [SPDIF](/components/speaker/i2s_audio/#spdif-mode) output. | ||
|
|
||
| Every output speaker must use the same audio format. The format is declared on the router so that the producer can keep | ||
| streaming through a switch without reconfiguring its output. | ||
|
|
||
| This platform only works on ESP32 based chips. | ||
|
|
||
| ```yaml | ||
| # Example configuration entry | ||
| speaker: | ||
| - platform: router | ||
| output_speakers: | ||
| - speaker_a_id | ||
| - speaker_b_id | ||
| bits_per_sample: 16 | ||
| num_channels: 2 | ||
| sample_rate: 48000 | ||
| ``` | ||
|
|
||
| ## Configuration variables | ||
|
|
||
| - **output_speakers** (**Required**, list of [IDs](/guides/configuration-types#id)): A list of | ||
| [speakers](/components/speaker/) the router can output to. Must have at least 2 and at most 8 speakers. The first | ||
| speaker listed is the active output when the device boots. | ||
| - **bits_per_sample** (**Required**, positive integer): The bit depth of the audio stream. Must be between `8` and `32`. | ||
| Every output speaker must use this bit depth. | ||
| - **num_channels** (**Required**, positive integer): The number of audio channels. Either `1` or `2`. Every output | ||
| speaker must use this number of channels. | ||
| - **sample_rate** (**Required**, positive integer): The sample rate of the audio stream in Hz. Must be between `8000` | ||
| and `96000`. Every output speaker must use this sample rate. | ||
|
|
||
| ## Automations | ||
|
|
||
| <span id="router_speaker-switch_output"></span> | ||
|
|
||
| ### `router.speaker.switch_output` Action | ||
|
|
||
| This action switches the active output to the specified speaker. The target must be one of the configured | ||
| `output_speakers`. | ||
|
|
||
| ```yaml | ||
| on_...: | ||
| - router.speaker.switch_output: | ||
| target_speaker: speaker_b_id | ||
| ``` | ||
|
|
||
| Configuration variables: | ||
|
|
||
| - **id** (*Optional*, [ID](/guides/configuration-types#id)): The router speaker to control. Defaults to the only one in | ||
| your YAML. | ||
| - **target_speaker** (**Required**, [ID](/guides/configuration-types#id), [templatable](/automations/templates)): The | ||
| output speaker to switch to. Must be one of the configured `output_speakers`. | ||
|
|
||
| > [!NOTE] | ||
| > Switching outputs while audio is playing drops any audio still buffered on the previous output. This produces a brief | ||
| > discontinuity at the moment of the switch. | ||
|
|
||
| ## Example | ||
|
|
||
| Pairing the router with a [template select](/components/select/template/) lets the active output be chosen from the | ||
| frontend (such as Home Assistant). The select's `on_value` trigger calls the switch output action, mapping each option | ||
| to one of the configured output speakers. The two referenced speakers are | ||
| [I²S audio speakers](/components/speaker/i2s_audio/) configured elsewhere in your YAML. | ||
|
|
||
| ```yaml | ||
| speaker: | ||
| - platform: router | ||
| id: router_id | ||
| output_speakers: | ||
| - spdif_speaker_id | ||
| - analog_speaker_id | ||
| bits_per_sample: 16 | ||
| num_channels: 2 | ||
| sample_rate: 48000 | ||
|
|
||
| select: | ||
| - platform: template | ||
| name: "Audio Output" | ||
| optimistic: true | ||
| restore_value: true | ||
| options: | ||
| - "SPDIF (TOSLINK)" | ||
| - "Analog (I2S)" | ||
| on_value: | ||
| - router.speaker.switch_output: | ||
|
kahrendt marked this conversation as resolved.
|
||
| id: router_id | ||
| target_speaker: !lambda |- | ||
| if (x == "SPDIF (TOSLINK)") { | ||
| return id(spdif_speaker_id); | ||
| } | ||
| return id(analog_speaker_id); | ||
| ``` | ||
|
|
||
| ## See Also | ||
|
|
||
| - [Speaker Component](/components/speaker/) | ||
| - [Mixer Speaker](/components/speaker/mixer/) | ||
| - [I²S Audio Speaker](/components/speaker/i2s_audio/) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.