Shell_command to play local sounds

Hi all. Hope someone can help me here. I’m trying to trigger a local sound file (.wav) to play as an action when my doorbell is pressed.

My home-assistant is running on a Raspberry Pi with hassos installed following the guide here: https://www.home-assistant.io/installation/raspberrypi#install-home-assistant-operating-system

If I log in with ssh (using the add-on) and use aplay to trigger the sound it works perfectly.

However, if I try and do the same thing using a shell_command I get an error like:

Error running command: `/root/doorbell.sh`, return code: 127.

I’ve tried moving my shell script and file into /user/hassio too (which was the only user home folder I could see) with no effect.

I guess the ssh add-on is running in a totally separate container environment or with a different user or something?

I also tried installing e.g. mopidy add-on to run locally but it’s no longer available as an add-on for arm platforms.

Any suggestions?

for reference, the shell script looks like this:

#!/bin/sh
/usr/bin/aplay /media/doorbell.wav

and has a+x perms
-rwxr-xr-x 1 root root 45 Feb 11 22:46 doorbell.sh

I have same problem here. No problem running it from terminal directly, but it fails as a shell_command.

I am trying to do the exact same thing you are, and have reached a similar barrier.

Were you able to find a solution?

I changed approach and hacked together a local add-on to do this.

To use it you’ll need something like this in your config.yaml

notify:
  - name: doorbell
    platform: rest
    resource: http://local-simple-sound-player:8099/play
    message_param_name: filename

and an automation like:

- id: ring_doorbell
  alias: there's someone at the door
  trigger:
    platform: state
    entity_id: sensor.doorbell_button_action
    to: "single"
  action:
    service: notify.doorbell
    data:
      message: bell.mp3
1 Like

Gah, just installed it to read “This add-on is not compatible with the processor of your device or the operating system you have installed on your device.”

ok, updated config.json to match my Pi (armv7), getting closer…

OMG

It works

Weeks I have been working on this.

Thank you kindly owlz84Stuart Lynn I have a door chime. :smiley:

With a bit of a delay, if my experience is representative :laughing:

It’s not bad actually, approx 700ms or so? For what I want it for (triggering from door sensors, motion sensors etc) it’s OK.

More baffling at this stage is why it won’t play any of the other WAV or MP3 files that I have put into the media folder. Have set permissions to 777 and they are small/basic files (the original MacOS sounds, i.e. quack, ding, etc, 4kb files or so) but for whatever reason however many times I restart/reboot/fiddle w my automations.yaml file I get this with any other file:

FileNotFoundError: [Errno 2] No such file or directory: ‘./media/quack.wav’
[2021-03-16 21:10:58,327] ERROR in app: Exception on /play [GET]

Is the “bell.mp3” filename baked into things with this add-on?

EDIT - I’m realising now (and still only half understand) that the files I am seeing via SAMBA are not the actual files that are being used in situ by Home Assistant (I’m running Home Assistant OS). Have tested this by substituting a quack sound as ‘bell.mp3’ and doing a full restart, and yet still I get your original bell, and not my quack. Will need to get head around how Home Assistant OS is containerising things so I can get the files where they need to go. Still, making progress! I can make a specific sound, which is miles of progress from where I was!

EDIT2 - had a look in the Dockerfile, figured out what’s going on in that the media folder is being imported at the time of initial installation rather than on the fly. Door is now quacking. Wife will be home soon and unlikely to be impressed with a quacking door, but I am pumped for what I have accomplished. :sunglasses:

:rofl::rofl::rofl:

Yes, it’s copied in when building the container. The fact it seems that nothing can see the home assistant file system is why I built the add-on.

Hi, first tanks a lot for sharing this piece of work, really usefull.
Already installed, update config, and build automation, but I’m not getting it to work.
I tried nofify.doorbell with doorbell.mp3 on services in developer tools to further test but I get nothing.
Any idea? on how to debug it?
thanks
[edit] speakers cable malfunctioning. It’s working. great job thank very much
bests

i have fixed some stuff and pull requested you

GitHub - owlz84/hassio-soundplayer Check my pull requests (kamilk91) i made it much faster.