Script to change audio output defaults

Please post more information about your PulseAudio output sinks

pactl list short sinks
pacmd dump | grep default-sink

If the default-sink is set to the hdmi output, audio will try to use it for audio output
But if the monitor is unplugged and hdmi output not available PulseAudio will use a fallback sink