SwitchSound is a plugin that offers the possibility to create buttons that activate the playback of audio files present locally. Each button is linked (and will play) a single audio file or a folder of audio files in shuffle. In the latter case, pressing the button will randomly select and play one of the audio files present in the specified path. For each button you can adjust the volume of the audio playback. The volume cannot be adjusted during playback but only before pressing the button.
Log in ssh to the raspberry and install omxplayer with this command. Omxplayer is the music player that will play your sounds.
sudo apt-get install mpg321
Log in ssh to the raspberry and create a folder "sounds" in this path:
/home/pi/
To create folders and transfer your audio files, you can use an SFTP application. I use Cyberduck. https://cyberduck.io/
After installing the player and uploaded our favorite sounds, let's create the Homekit buttons corresponding to our audio files. Let's open the Homebridge configuration and create the new SwitchSound platform as follows:
{
"platform": "SwitchSound",
"name": "SwitchSound",
"debug": false,
"defaultSoundPlayer": "/usr/bin/omxplayer.bin",
"accessories": [
{
"accessory": "SwitchSound",
"id": "000000000001",
"name": "Server Pronto",
"soundFile": "/home/pi/sounds/restart/",
"soundOptions": [],
"shuffle": 1,
"loop": false,
"volume": 66,
"debug": false,
"sequence": false
},
{
"accessory": "SwitchSound",
"id": "000000000002",
"name": "Allarme",
"soundFile": "/home/pi/sounds/varie/AlarmSound2.mp3",
"soundOptions": [],
"loop": false,
"volume": 66,
"debug": false,
"sequence": false
}
]
}
accessory
<string> required: identifies the accessory. It must always be SwitchSoundid
<string> required: identifies the serial code of the accessory. You can write whatever you wantname
<string> required: identifies the name of the button that will appear in HomeKitsoundFile
<string> required: identifies the path of the audio file to be connected and playing. In case of multiple files in shuffle, you can stop at the foldersoundOptions
<string> optional: For the more experienced, it is possible to pass additional parameters to omxplayershuffle
<bool> optional: activates shuffle mode. In this case it is necessary to indicate the path of a folder within the soundFile parameterloop
<bool> optional: play the audio file endlessly until the user turns off the button from HomeKitvolume
<int> required: It is necessary to indicate a starting volume (0-100)debug
<bool> optional: enable debug mode with more output instructionssequence
<bool> optional: offers the possibility to play an audio file several times consecutively. Useful for short audio files
If the playback of your audio files does not work, it may be necessary to assign permissions to the user with whom you started homebridge (if different from pi).
Run these commands:
sudo passwd INSERT_YOUR_USERNAME_HOMEBRIDGE
sudo usermod -a -G video INSERT_YOUR_USERNAME_HOMEBRIDGE
Now reboot your raspberry.