Sound server component/entity

Hello

I know about the PulseAudio Loopback Switch from @Cinntax, witch is a fine and nice little switch to change the audio output if you have multiple audio sources or speakers and you want to be able to route the audio between them. Once set up, this switch works very good.

However, the problem is setting it up. I guess many people don’t know what a loopback in the PulseAudio terminology is. If you want to use the Loopback Switch, the next think you need to do, is create a null sink, where you then pipe your audio in and of course you have to load the module-cli-protocol. Next you have to find out about the sink_names and the source_names and therefore use pactl list sinks and pactl list sources. Interestingly, the source_name is not actually the name of the sink you have set up before, but becomes name.monitor. So what I want to say, it will keep you busy for quite some time.

What I think about, is adding a new Entity module (is that the correct name for something like media_player) to HA, that I would probably name sound_server. This Entity would need a new type of card on the HA web interface (I have no idea how to do that yet). And within that a new entity that I would call pulseaudio. Of course further components e.g. for Windows can be added later. This pulseaudio component could use the pulsectl package to interface with the pulseaudio sound server and directly expose the desired features, like changing sinks for sources or changing the volume.

What I would need help with is setting up the base sound_server entity. Up to now I have only written components.

You nailed the pulseaudio config right on the head- exactly right. I’m thrilled to see someone else taking the same approach as me, as it has served me very well over the years. I actually have the following setup (as an example):
mpd -> null sink -> (LOOPBACK null sink.monitor to remap-sink) -> remap sink represents 2 of 8 channels on the sound card. I do agree that it’s quite an advanced setup within pulseaudio- not for the faint of heart.

So I really only have to load/unload the loopback module to route any given source to any given sink. I’ve been meaning to do a blog post on it, because it’s been a near flawless setup for me over the years. Pulseaudio even does a very nice job of synchronizing the audio between the various output sinks.

In terms of a new type component- I’m not entirely convinced that we need a brand new component type. I suppose that would open the door for OTHER sound servers besides pulseaudio, but not sure what demand there is for that (maybe one for direct ALSA I suppose).

I had, at one time, envisioned a “pulseaudio hub” that would simply inspect/discover the live pulseaudio configuration, and expose all of the settings as existing sensors,switches,etc. When you say “changing the sinks for sources”, are you thinking it’d use the same loopback module that I’m using, or were you thinking more along the lines of actually re-assigning sink-inputs? Or maybe a combine sink? Just curious what the use cases are.