Homey Community Forum

[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!