Just wanted to share how to make switching between headphones and speakers work.
Per default you can manually switch using:
sysctl hw.snd.default_unit=0
sysctl hw.snd.default_unit=1
To make auto sense work you need to add the following to /boot/device.hints:
hint.hdaa.0.nid22.config="as=1 seq=15 misc=0"
hint.hdaa.0.nid23.config="as=1 seq=0"
What we do with this is adding both to the audio set (as) 1. Having both on the same audio set is a requirement for automatic switching to work.
The reason for seq=15 can be read up in snd_hda(4):
The sequence number 15 has a special meaning for
output associations. Output pins with this number a
device type “Headphones” will duplicate (with
automatic mute if jack detection is supported) the
first pin in that association.