Ubuntu changing default audio output after suspend

Solution 1:

Fixing PulseAudio switching from TV to Laptop on Suspend

This "undocumented feature" appeared with Ubuntu 16.04 and new version of PulseAudio 8.

Create a new file /lib/systemd/system-sleep/tv-sound and copy in:

#!/bin/sh

case $1/$2 in
  pre/*)
    echo "Going to $2..."
    # Place your pre suspend commands here, or `exit 0`
    # if no pre suspend action required
    sleep 1
    ;;
  post/*)
    echo "Waking up from $2..."
    # Place your post suspend (resume) commands here, or `exit 0` 
    # if no post suspend action required
    sleep 2
    export PULSE_RUNTIME_PATH="/run/user/1000/pulse/"
    sudo -u rick -E pacmd set-card-profile 0 output:hdmi-stereo
    ;;
esac

NOTE: replace user name rick (third line from the bottom) with your user name.

Then mark it executable with the command:

sudo chmod +x /lib/systemd/system-sleep/tv-sound

An additional step might be required if output:hdmi-stereo (the device for most people) is different on your system.