[TUTORIAL] Whole house audio and text to speech announcements to HomePod Mini and other AirPlay speakers

This tutorial shows you how to use your Homey to create a whole-house audio system with AirPlay (and AirPlay 2) speakers and also how to make text-to-speech announcements on AirPlay speakers including HomePod and HomePod Mini, Airport Express etc.

You will need:

  • A computer running MacOS
  • Some AirPlay speakers such as HomePod Mini

The rest is just software! First, you’ll need to get some things installed:

Follow the instructions to set up the TriggerCMD agent on your Mac and use your secret token from triggercmd to configure your TriggerCMD app via the app settings on Homey.

The key to getting this whole thing working is that TriggerCMD can run AppleScript locally on the Mac and AirFoil is fully scriptable with AppleScript and it can control AirPlay speakers and direct audio from apps running on the Mac to one or any combination of them (in perfect sync, too).

So to get this to work, you need to create a bunch of commands in TriggerCMD using the GUI editor in the agent running on the Mac. You will need one for each command you want to send to AirFoil - so one to connect and another to disconnect each speaker, and perhaps one to increase the volume and another to decrease the volume of each speaker. Maybe also commands to change the audio source for AirFoil if you want to switch between different apps such as iTunes or VLC.

Each command just runs an AppleScript. Follow the instructions here to create .scpt files and then you can create TriggerCMD commands that look like this:

osascript /[yourPathToScriptsFolder]/Scripts/Kitchen_Connect.scpt

These commands can then be run from your Homey by adding a TriggerCMD flow card in the Then section of a flow and choosing the TriggerCMD command you created from the list.

Full details on how to control AirFoil using AppleScript are here.

The same approach can be used to open apps, start, stop, pause and control playback, change audio sources etc. You can combine with logic in Homey to your heart’s content.

I have a whole-house audio system using HomePod Minis that plays BBC Radio 4 (which you otherwise can only manually stream from a phone because the BBC radio stations aren’t on TuneIn which is integrated with Apple). I have virtual devices for each of the radios and a counter variable for the number of radio clients and when it becomes > 0, I use the approach above to start VLC on the Mac and tell it to start streaming BBCR4 from a web URL. Flows connected to each radio virtual device connect and disconnect speakers using AirFoil and also change the counter. When the counter is 0 again I tell VLC to stop streaming. I also use Octan remotes from nodon to control the radio in each room - these have on / off / vol+ / vol- buttons all implemented using the approach above.

Speech to text announcements

As a handy extra, once you’ve got the ability to connect and disconnect speakers on the Mac and direct audio, you can use the System audio source on AirFoil to send speech produced on the Mac to any AirPlay device from Homey (via more TriggerCMD commands). This time each TriggerCMD command can just directly execute the AppleScript to say something. For example, my TriggerCMD command to warn me that the downstairs doors and windows are not secure when I go to bed at night looks like this:

osascript -e 'say "Warning. Downstairs is not secure." using "Daniel"'

Happy hacking!

3 Likes

God damn! I’m testing this tomorrow. Does it work with Spotify? Great work!

Cool, hope you find this useful. I should work with any source you can control enough using TriggerCMD / AppleScript on the Mac. Not sure how true that is of Spotify. I’d be interested to hear how you get on.

Hii,

Nice! I got everything working. I’m going to buy one more airport express 2. Got it working on Mac mini, speakers from my apple tv and 1 airport express!! I’m moving to a new home within a month… will install this definitely. Finally Spotify on homey! YES ! great work.


So i can trigger a playlist from spotify with TriggerCMD as follows:

osascript -e 'tell application "Spotify" to play track "spotify:playlist:37i9dQZF1DXc3KygMa1OE7" '

There is a lot of code pre programmed. The buttons from spotify are all in TriggerCMD already and thats fairly easy. I am missing the shuffle command. And try to fix that in the up coming weeks.

I need to do some testing on muting / unmuting single speakers when a motion sensor is triggered.