Switching between speakers and headphones without unplugging the headphones

I want to be able to switch between speakers and headphones without unplugging the headphones.
What I’ve tried:

  1. Disabled auto-mute in alsamixer. With this, speakers can play audio when headphones are plugged in, but the problem is that after about half a minute or so of playback, the computer automatically switches to headphones.
  2. Tried using advice from here How can I disable front panel jack detection? - #5 by jn64
    At first, I tried overwriting just Red Line Out and Headphone, but it did not change anything at all. Since in hdajackretask documentation it says “If you select a “Line out (back)” override, you should also have a “Line out (front)” override.” I’ve also tried overwriting every Line Out I have. After doing that, for some reason, it became even worse. Now when the headphones are plugged in and I try to switch to speakers, it switches back immediately.

Here is a screenshot from hdajackretask:

Screenshot

I don’t know how to undo what it is hdajackretask did configuration-wise, but in GNOME I can just switch back and forth between headphones and loudspeakers using the top-right menu:

I can undo hdajackretask thing, that’s not the problem.
The problem is that the gnome thing doesn’t work. As I said, after changing to speakers in gnome top right menu (as shown on your screenshot), it automatically switches back to the headphones. Without hdajackretask thing it happens not immediately, but roughly after half a minute, or maybe a dozen of seconds, I think it’s somewhat random.

Just a thought, but I wonder if the problem could be with the headphones? Maybe your headphones are generating line noise of some sort that is causing the PC to think you have removed and reconnected your headphones (when really they’ve been connected continuously the whole time). Have you tried with different headphones?

Edit: If all else fails, you could probably find some hardware that would do the trick on, e.g., amazon.com (try searching “3.5mm audio switcher”).

You can install “pavucontrol” and run that (PAVC, Pulseaudio Volume Control), and in the “Output Devices” tab select the “Speakers” as the “Port:” instead of the “Headphones”

I just switched to Speakers without having to unplug my earbud headset and heard my speakers correctly by using PAVC.
I did that on Fedora 42 beta which has a slightly newer pipewire and wireplumber then usual:
pipewire 1.3.82-1 and wireplumber 0.5.8-1

I think you might be half right. Tried different headphones and the behaviour is still the same, but I think it might be a problem with the front headphone jack. Swapping speakers and headphone jacks reverses the problem, so this is not a software issue.
Case solved, thanks.