No Audio after disconnecting external display (HDMI) when it was using HDMI Audio output

Occasionally when disconnecting a HDMI display the sound output device is switched to “Dummy Output” with no chance to switch it back to “Speakers Built-in Audio” (available but no effect, always drops back to dummy) - logging out of the Gnome session seems to fix it.

I would be glad if someone could look into it.