Hello all,
I am currently evaluating different solutions for my smart home system. At the moment I am testing Home Assistant.
One of the requirements I have is to play predefined sounds via the local audio output when events occur. Explicitly NO text to speech via external providers, NO DLNA to a smart speaker. Only 3.5mm audio jack, only hardcore.
I was very surprised when I couldnât find this feature, which in my eyes is one of the absolute basics, right away.
A quick search found these threads:
https://community.home-assistant.io/t/how-can-i-play-a-sound-as-a-script/
https://community.home-assistant.io/t/playing-a-wave-file/
required-a-step-by-step-guide-on-how-to-play-sounds-and-media-through-a-3-5mm-audio-jack
(no link here because new users are only allowed to post 2 links)
Here, among other things, very adventurous solutions were developed with VLC, Telnet and so on, which are unfortunately not suitable for me. The requirement is quite simple to output a sound via cable, completely offline.
So I searched and tried and found a very simple solution. I would like to present it here, maybe someone has the same problem.
One of the promising approaches from above mentioned topics was to play the sound via âaplayâ. This also works on console / via ssh, but not from an event trigger / automation.
The reason is that the automation is executed in a container where âaplayâ is not available. This may be for security reasons, but it is annoying.
Fortunately, there is another program available: ffplay.
Side note: The list of available commands/programs can be obtained by executing the following shell command from the automation:
ls /usr/bin > /config/commands.txt
You can download the file for example via Samba Addon.
The following steps will lead to success:
-
install Samba addon.
-
connect to the Home Assistant system via Samba (I use Linux, for Windows it is called network share, I think).
-
create a subdirectory in the directory âconfigâ, for example âaudioâ. Possibly you can also do this in âshareâ or âmediaâ, I have not tried. Config will be mounted in all containers in any case.
-
copy all files you want to play into the new created directory âaudioâ.
-
add the following in the "configuration.yaml
shell_command:
play_local_notification: 'ffplay -nodisp -vn /config/audio/beep.wav'
Here the filename is hardcoded, but I want to keep the example simple. If you have more than one file, you should use parameters for the filename.
The parameters â-nodisp -vnâ are necessary because ffplay is a media player, not just audio. But since Home Assistant has no video subsystem, the player will crash when trying to initialize it. The parameters tell the player that only audio is needed.
- restart, then the shell command can be used in any automation.
I havenât figured out how to update the configuration without rebooting, but as I said, just started using the system yesterday.
I hope this helps someone who has the same problem.
Kind regards
Alex