Change audio device

Is there a way to programmatically change the audio output device on the Mac, especially to a HomePod? Preferably not through UI scripting which has not work reliably for me. I have also tried a commandline utility to do it, but it has no effect for airplay devices.