At the moment (April 2024) the following setup works without any add-ons:
- You will need Pulse Audio client binaries (
pacat
,paplay
,pactl
). They used to be present in the main HA container, but were removed. However, all libraries required by those binaries are still present in the main container - Take those binaries from the
hassio_audio
container and copy them to/media
as follows:
docker cp hassio_audio:/usr/bin/pacat /media/
docker cp hassio_audio:/usr/bin/paplay /media/
docker cp hassio_audio:/usr/bin/pactl /media/
These commands can be run either from the host OS (if you have access to it, e.g. you are running HA supervised) or from the Advanced Terminal add-on. While doing this, you can verify whether HA would send the sound to the sound card you are expecting: run pactl info
and verify whether “Default sink” is showing what you are expecting. If you have access to the host OS, the command would be: docker exec -it hassio_audio /usr/bin/pactl info
.
- Now you can define something like this:
shell_command:
play_sound_file: "/media/paplay /media/myfile.ogg"
and use this as a service in automations. One downside: PulseAudio libraries in HA do not support MP3 files. WAV, OGG, FLAC is ok, but not MP3.
I’ve opened a feature request for a proper implementation of the local playback. Consider voting for it: click