Hassio and local audio

yes see https://community.home-assistant.io/t/tts-using-built-in-rpi3-analogue-audio-output-with-hassio/32475/20 Basically this work for me also
{
“entity_id”: “media_player.mpd”,
“media_content_type”: “music”,
“media_content_id”: “local:track:test.mp3”
}

1 Like

Thanks! It worked for me. I can call the service and play the local mp3 files.

However, when I tried to play the mp3 file in a automation.yaml, it doesn’t work.

  • action:
    • data:
      entity_id: media_player.mpd
      media_content_id: local:track:test.mp3,
      media_content_type: music
      service: media_player.play_media

I have an error that logged “Error doing job: Task exception was never retrieved”. Any suggestions?

mine looks like this:

action:
..- service: media_player.play_media
....data:
......entity_id: media_player.mpd
......media_content_id: local:track:test.mp3  
......media_content_type: 'music'

Note I have just added the … to get some spacing

Thanks!!! All good now. I just needed to restart the mopidy music service. Thanks again for the assistance. :slight_smile:

Hey @arretx did you solve the MPD unavailable issue? I am having the same problem

I have the same issue concerning the unavailable media_player. What i did learn from the logs though is that the mediaplayer is trying to acces the wrong url:

it’s trying to reach: https://xxxxx.duckdns.org:8123/api/tts_proxy/etc

the correct url is:
https://xxxxx.duckdns.org/api/tts_proxy/etc

I tried everything, but i can’t get mopidy to get the url request right, but this is probably the reason it returns ‘unavailable’.

I am using hass.io. I didn’t have a www directory inside config so I created it. However, when I dropped my files into that directory I was unable to retrieve them using a URL. Do I need to do anything special when using duckdns?

solved: I didn’t realize you have to restart ha after creating the folder.

Here is how I solved to play MP3/WAV files using mopidy on a HASS.IO system:

https://www.amalytix.com/en/home-assistant-with-conbee-ii-deconz-xiaomi-aqara-and-hass-io-from-scratch/#play-audio-1

This worked a treat for me! Way better than VLC / Modipy

FYI you need to update your config.json to include this line to get it to work properly:

“arch”: [“armhf”, “armv7”, “aarch64”, “amd64”, “i386”],

1 Like

you are a life saver ! … install of the Addon worked after your suggestion. However I wasn’t able to call the service. I used the below format but its not even allowing me to save it. Under developer tool “call service” area. when i select the service and put the data. it says incorrect json. I also tried in the automation and tried to call this service there but it is not even saving the data portion of the service. What am i doing wrong.

service: hassio.addon_stdin
data:
addon: local_audio_player
input: “http://localhost:8123/local/doorbell.mp3

Hit and trial and got it to work. Used below json format to call the service .

The only issue now is the audio plays but it cuts off before it completes. For example. say, the audio file is 3 seconds. but it cuts off after 2 sec. does anyone know why its happening?

{
“addon”: “local_audio_player”,
“input”: “http://<local_ip>:8123/local/audio/03-back-door-open.mp3”
}

Hello, i’m working to play local audio file through audio jack in my home assistant running in docker and then i ended up here.
Is this solution still aplicable? Because i tried to install this addons after following steps over here, but no addons shows up. Can you please help me? Thanks.

1 Like

Hi, I’m also running home assistant/HASSIO in docker. I’ve installed the add on.

I added BestLibre repository to the add-on store and then installed the Mopidy add on from there.

It seems to be running an all, but I don’t see a media player in developer tools to play the audio from. Am I supposed to be seeing media_player.mpd somewhere or is it added separately?

I think you should try to add media_player.mpd in the configuration.yaml file.

Thanks mate. I suppose that is pretty obvious, thanks for the reply.

So… I’m a pretty big newbie here. I’ve got HA running in Docker on a Raspberry pi, and I have managed to use ESPHome to connect a temperature sensor. Now I am working on some door sensors, and I would like to trigger some audio files locally stored on the Pi when a door is opened. This seemed like just the ticket. I fixed the “arch” issue, but the installation failed with the following error:

20-05-18 20:54:58 ERROR (SyncWorker_8) [supervisor.docker.addon] Can't build local/armv7-addon-audio_player:1.5: COPY failed: stat /var/lib/docker/tmp/docker-builder437573016/run.sh: no such file or directory

I’m not even sure where to start with that error - can anyone point me in the right direction? I thought maybe somehow it was looking in the wrong directory during the installation, so I tried fiddling with the addresses in the docker file, but I had no luck. Any help would be greatly appreciated! Thank you so much!

My original add-on to play local audio files through the Pi’s jack has not been working for a few years which I didn’t mind because our dog goes absolutely mental when he recognizes a doorbell but I finally decided to fix the add-on and try again.
Here it is: Hassio_addons/local_audio_player at master · dingedan/Hassio_addons · GitHub. You can now install it through the repo as well.

1 Like

I got this working to play local audio by calling the service from an HA script - thank you Daniel - but I am using a USB audio speaker (powered by USB) that has no volume control, and it defaults to max volume.

Can you give me any hints as to how I could adapt it to pass a volume level at which the audio will be played, please? Or even hack in volume level somewhere, as a first step?

(Although I got it working I don’t have much idea how it works, e.g. which command gets run to actually play the audio)

(One of my goals for using this, other than fully local playback so it works when the Internet is down, is to be able to play (e.g. an alarm) at a low volume and repeat it with a higher volume).

Hi Dingle,

I’m currently integrating your solution into my installation. Since I’m completely new to Home Assistant it is important for me to understand what exactly I am doing. I believe I now understand your solution with the exception of two details:

1:
run.sh:

    # removing JSON stuff
    input="$(echo "$input" | jq --raw-output '.')"

What does this line do?
According to the documentation of the jq command it shouldn’t do anything to the string with the given parameters.

2:
config.json

  "audio": true,

and
Dockerfile

RUN apk add --no-cache jq sox alsa-plugins-pulse

According to the HA documentation the “audio” parameter means “Mark this add-on to use internal audio system. We map a working PulseAudio setup into container.”.
According to the SoX documentation Pulse Audio is the default sound driver SoX tries to use.
So why do we need to install alsa-plugins-pulse when home assistant provides Pulse Audio and SoX prefers to use it?

It would be really nice of you to clarify these things so I can avoid doing something I don’t completely understand.

Best Regard
Zebi

As discussed in this thread I forked Dingle’s solution, adapted it to the current Home Assistant version and wrote a bit of documentation.
You can find it here: