Does anyone know if it is possible to play a MP3 (say stored locally on HASS.IO) to a media_player?
Iâve been battling this as well. I recently switched from Home Assistant to Hass.IO, which wasnât easy. Iâve lost my custom UI and audio notifications. Iâve been attempting to get Mopidy working but I canât find much for support. I get as far as Mopidy attempting to play the MP3 but then I get connection errors.
So it is possible to do it?
I have moved from Raspian to Hassio and Yes itâs still working. I have both local file and tts generated mp3 working.
I had mine on /config/www/audio folder. Folder permission 755
Make sure you can reach it from http://yourhaip:8123/local/audio/youraudiofilename.mp3 or what ever audio file extension you use.
https://yourdomain/local/audio/youraudiofilename.mp3 - make sure you forward 443 to 8123 on your firewallâŚ
For tts cache folder
I have it in /config/tts didnât make a chabge on the folder permission.
I tried /tmp/tts but the tts mp3 does not get written.
Hi Vin,
Sorry for the late reply - thank you for the info, so it is possible, YAY! I am trying to play a file when a motion is triggered or a button pressed, but I am starting with a basics, getting the file to play.
I have a media player (Yamaha wireless speaker called media_player.kitchen in HASS.IO) and I was wondering how did you get to play an audio file to it, or even better, have some google voice/preset text âDoorbell was pressedâ sent to the media_player?
Is this even possible or am I expecting way too much from HASS.IO?
EDIT: I think what I am trying to achieve can be done via this:https://home-assistant.io/components/tts/
Question is, how do I âtriggerâ this to happen?
here is a script I use (part of it) to wake me up. the part Iâm attaching says the temperature outside and the weather conditions (raining, partly cloudy etc).
it works great. you might want to set the volume to an appropriate level before sending this commandâŚ
as you can see, i have a sequence. i have a few things that it says, and i put pauses between them. itâs good to note that the pauses have to include the time it takes to say each bit.
morning_brief:
alias: "morning brief"
sequence:
- service: tts.google_say
entity_id: media_player.attic_speaker
data_template:
message: 'Its {{ states.sensor.time.state }} and {{ states.sensor.pws_weather.state }} '
cache: false
- delay:
seconds: 12
entity_id: media_player.attic_speaker
data_template:
message: ' next bit etc '
cache: false
Next you can write an automation that runs this script when triggered ie.
- id: motion_kitchen
alias: motion_kitchen
trigger:
platform: state
entity_id: sensor.kitchen_sensor_burglar
from: '0'
to: '8'
action:
service: homeassistant.turn_on
entity_id: script.morning_brief
To add to the question. Couldnât you play a LOCALLY hosted MP3 without worrying about any port forwarding etc? with tts itâs sometimes nice to have a little chime (alert) that plays before the message and identifies the type of message you are about to hear (motion, weather etc)
guys, if you want to play an mp3 on hassio using the local 3.5 jack on the rpi, just follow my instructions here:
It works pretty well.
If you want to use the Google TTS on any other media player you can have a look at my nabaztag project where I use the mp3s generated by the google tts and send them to a âvirtualâ media player here:
If i can help in any way just ask
This work on HA with VLC, not sure on hass.io
- service: media_player.play_media
data:
entity_id: media_player.speaker
media_content_id: /home/pi/Downloads/play.mp3
media_content_type: 'music'
Grat news, will try this automation when I get home, tts canât exactly sing, so I miss out on the music with notifications
hi,
I was able to play local mp3 files by using the complete path but tking into account that www file is the local file so the complete domain was like this:
âmedia_content_idâ: âhttp://192.168.2.111:8123/local/musica/1.mp3â
Is there any way to play all the files into a folder like a sort of playlist?
Thanks
If your media player supports media_content_type: âplaylistâ in service media_player.play_media
just build your own playlist by adding items in VLC player on your desktop PC.
In my case, I have an instance of mpd addon running, added several files (or urls) to a new playlist on my desktop. Then saved the m3u8 file to the designated location.
Just beware that these playlist items are accessible the same way as on desktop PC (or change the m3u8 file e.g. by notepad++ to fit the location locally).
In hass.io the location is mostly in your âshareâ share folder (when using Samba addon).
Another approach could be, again using mpd media player, using service media_player.select_source.
greetz Bob
Hi, thanks for your help,
Iâm using chromecast to strem the audio, but unfortunately Itâs not working with the playlist approach. this is my json text:
{
âentity_idâ: âmedia_player.juans_roomâ,
âmedia_content_idâ: âhttps://127.0.0.1:8123/local/musica/1231.m3u8â,
âmedia_content_typeâ: âplaylistâ
}
Thanks
Unfortunately, google chromecast is a special kind of media player. IMHO itâs designed to play media mirrored by android apps and does not support playing âlocalâ stuff out of the box. My mpd media player can access playlists located somewhere and plays items from it.
I had a chromecast myself, but it was too restricted for my needs at all.
I am not sure, but https://github.com/balloob/pychromecast/blob/master/pychromecast/controllers/media.py or https://github.com/balloob/pychromecast/tree/master/examples gives some information. But there are only google things like youtube or single mp3s as input.
The hard way to go could be via plex which can cast to chromecast as well. Plex could be automated via hass again.
I have my music copied to my NAS in folders by album. I send all the files in the folder to the chromecast using castnow. (https://github.com/xat/castnow) Works great.
I run my HA on an ODROID-XU4 using Ubuntu 18.04 for the operating system. Thereâs probably an easier way to do this, but hereâs my method.
I copied my music to my NAS using the directory format /artist/album/song.flac or m4a. I mount the music directory from my NAS to the Odroid using NFS at the mount point homeassistant configuration directory/pub/Music. In my case the configuration directory is /home/homeassistant/.homeassistant/.
I made a shell script that I called makemusicyaml that will read the directory tree and make a yaml file for the input_select. Here it is:
find /home/homeassistant/.homeassistant/pub/Music/* -type d -print | sed 's/\/home\/homeassistant\/.homeassistant\/pub\/Music\///g' | sed 's/\x27/\\\x27/g' | sort | sed 's/^/ - /' | grep "/"
To use the yaml file redirect the output to music.yaml, like this:
./makemusicyaml > music.yaml
I created a shell script named âcastâ for passing the music to castnow. I only have one Chromecast and it is always assigned the same IP address. Hereâs the script:
/usr/bin/find /home/homeassistant/.homeassistant/pub/Music/$1/*.m4a
if [ $? -eq 0 ]
then
/usr/local/bin/castnow /home/homeassistant/.homeassistant/pub/Music/$1/*.m4a --address 192.168.1.3 --quiet
else
/usr/bin/find /home/homeassistant/.homeassistant/pub/Music/$1/*.flac
if [ $? -eq 0 ]
then
/usr/local/bin/castnow /home/homeassistant/.homeassistant/pub/Music/$1/*.flac --address 192.168.1.3 --quiet
fi
fi
In my configuration.yaml I added
input_select:
music:
name: Music
options:
!include music.yaml
shell_command:
send2cast: bash /home/homeassistant/.homeassistant/cast {{states('input_select.music')}}
Hereâs a screen shot with the input select pulled down.
Hello, the subject is old, but I would appreciate if you answer.
I get this error.
[s6-init] making user provided files available at /var/run/s6/etcâŚexited 0.
[s6-init] ensuring user provided files have correct permsâŚexited 0.
[fix-attrs.d] applying ownership & permissions fixesâŚ
[fix-attrs.d] done.
[cont-init.d] executing container initialization scriptsâŚ
[cont-init.d] done.
[services.d] starting services
[services.d] done.
starting!
[Info] Read alias: http://192.168.6.200:8123/local/1.mp3
ALSA lib dlmisc.c:283:(snd_dlobj_cache_get0) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_pulse.so ((null): Error loading shared library /usr/lib/alsa-lib/libasound_module_pcm_pulse.so: No such file or directory)
ERROR: Failed to load plugin /usr/lib/ao/plugins-4/libalsa.so => dlopen() failed
play FAIL ao: Could not find a default ao driver
play FAIL sox: Sorry, there is no default audio device configured
[Error] Playing failed ->
Hi. I didnât found what I was looking for in this topic, but it would be nice to give my cents to whoever gets here later.
Use this https://www.home-assistant.io/integrations/media_extractor
I could finally play audio from my HA folder and also youtube video/songs.
what media player are you using?
Hi everybody,
Iâm new with HA and somehow struggling with the playback of a local mp3-file. Iâm using the service media_player.play_media and the file is located on my HA-machine within the media-folder (subfolder audio):
service: media_player.play_media
data:
media_content_id: 'http:/192.168.178.121:8123/media/audio/Achtung-Im-Bad-oder-WC-Fenster.mp3'
media_content_type: music
target:
entity_id: media_player.wohnzimmer_sonos
Unfortunately I canât get any playback. The logfile says:
ERROR (SyncWorker_0) [homeassistant.components.sonos.media_player] Error on play_media with UPnP Error 714 received: Illegal MIME-Type from 192.168.178.54
I would be grateful for any help