Trying to play a media file to google home, what am i missing?

I thought Google home/chromecast only playback https authenticated web accessible media files?

i figured it out. set it up as a call service to play_media and then for content id i put http://HAlocalIPadress:8123/local/Police1.mp3 and then put “music” for the content type.

I also tried it with the https://mydomain.duckdns.org/local/Police1.mp3 and it worked that way as well.

hope this helps someone

4 Likes

I’m still not getting this to work. I’m using the automation editor and no errors in the trace.

Success.

I used this to get an auth URL

I then added that to my HTTPS Nabu Casa link.

It needed the Content Type (set to audio/mp3) and it worked.

:grinning:

[Edit] seems to have stopped working. Not sure if the Auth Key has expired.

:frowning:

2 Likes

Updated my solution in the linked post.

@antimage I am not seeing the linked post.

The information I was missing was what /local was.

I have suggested this gets added to the Google Cast documentation;

To cast media stored in your Home Assistant instance, it needs to be added to the /config/www folder which translates to the /local folder. e.g. a cast location of /local/media/audio/test.mp3 is actually stored in /config/www/local/media/audio/test.mp3 . There is no need to define the host, as Home Assistant works that out for itself.

I am not certain of the last part, but it is true for me.

image

1 Like

Yes, but I think the auth key expires. Using the /local/ folder seems to work all the time.

The NodeRed flow requests a new authkey every time it fires a media_player.play_media requests.
I have my media on a NAS which is mounted to the Home Assistant Media location. The /local/ doesn’t work in my instance. If you are okay with hosting the media in your home assistant instance your solution seems to be fine.

1 Like

For anyone else having trouble with this:

To play a wave file in Node Red, used the Call Service node to an automation created like above in the screenshot @baz123 showed, but the folders are backwards for me. I could not get the file to play using a variety of other methods native to node red.

I found that via the network console suggestion by @antimage
/media/local

No need for the authentication key on the end of the url.

I edited my post to include the info that the Authkey expires and the link you got from the network console no longer works.

What works is the node red flow . where I get a new Authkey everytime I want to play something.
image

image

Hope this helps.

2 Likes

Big @baz123, this is an interesting solution. I’ll test this one right away. So you’ve never had a problem with the auth even after restarting the Home Assistant?

1 Like

Just to check… I have to create the whole automation there? Because I wanted to use this in an automation triggered by an input boolean. Instead of Home Assistant UI I should build everything on Node Red, right? Thanks

yeah, its better to do everything in nodered. you can do half in HA and half in nodered but it just adds to frustration when debugging.

1 Like

thanks a lot, total noob here, let’s try to do it then! thanks!

well, i’m missing something… everything works, except it doesn’t play. i’m trying to play it on my tv, and a 9 sec audio appears on screen but it doesn’t play. I’m missing the Make Payload, it that the reason? As I said I’m a total noob on Node Red, don’t know how to properly set Make Payload using the UI

I’ve been trying for ages to get a local media mp3 file to play when triggered. The only way I have been able to get this to work is using a short lived token that I have to generate manually every 5 hours or so. So I am thrilled that a new media player feature was added in recent updates except it does not work on my RPi 3 setup. The new “Play media” action allows me to select a Google speaker and the local media file, but it doesn’t even make the connect ding on the speaker when triggered like before when it attempts but the media itself fails to play. It’s like nothing happened. I also can never get the text to speech to work which throws an error of “Failed to call service media_player/play_media.” I don’t see this error with the new action, but I’m not sure where to look for it. I have a second action after the “Play media” to change the speaker volume which fails to execute per the log trace “This node was not executed and so no further trace information is available.” I would really like to not have to manually set this every day. It kind of seems contrary to the idea of automation.

So I recalled reading this thread some time ago, and specifically I was interested in the node red approach. I am a total noob with node red, but I tried to copy the approach shown in this thread best of my understanding. I am able to build a https URL with a short lived auth token on it, but the node red flow connects and dings but no media plays. So, I thought I would just copy/paste this URL from a Debug node into my manual automation to test it. And nothing happens when it’s triggered. It’s like the auth key is no good. Does anyone have a working node red flow that uses a local mp3 audio? If I get the URL from the media tab using the browser network tools the URL works as I would expect. Or failing this, how does one use a long lived token to do something like this? I would really like to get this to work and am so disappointed that the new play media action does not work in this case (and apparently for many other cases as well). TIA!

Here is a log entry:

Logger: homeassistant.core
Source: components/cast/media_player.py:658
First occurred: 10:19:41 PM (9 occurrences)
Last logged: 10:39:50 PM

Error executing service: <ServiceCall media_player.play_media (c:33080fedff4293e11e6e3ce5f5f047f8): device_id=['a5d0a56a34474fa4d3ad1b911caa1e50'], entity_id=['media_player.living_room_speaker'], extra=, media_type=music, media_id=https://fakeplaceholder.duckdns.org/media/local/white_noise.mp3?authSig=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI4ZTkzMzc1MjMzYzE0NzE0YWViOGE3OTAxMDVjZGE1MCIsInBhdGgiOiJodHRwczovL215Y3JvZnRob2xtZXMuZHVja2Rucy5vcmcvbWVkaWEvbG9jYWwvd2hpdGVfbm9pc2UubXAzIiwiaWF0IjoxNjQ3MTQ5MzU2LCJleHAiOjE2NDcxNDk2NTZ9.mhQW2T6sQiJ8PZrDTyZXmeEo5HesSfpPyWNjXuv-GMc>
Error executing service: <ServiceCall media_player.play_media (c:ea52a6863e4f731ee31843e3bb69b07d): device_id=['a5d0a56a34474fa4d3ad1b911caa1e50'], extra=, media_type=music, media_id=https://fakeplaceholder.duckdns.org/media/local/white_noise.mp3?authSig=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI4ZTkzMzc1MjMzYzE0NzE0YWViOGE3OTAxMDVjZGE1MCIsInBhdGgiOiJodHRwczovL215Y3JvZnRob2xtZXMuZHVja2Rucy5vcmcvbWVkaWEvbG9jYWwvd2hpdGVfbm9pc2UubXAzIiwiaWF0IjoxNjQ3MTQ5MzU2LCJleHAiOjE2NDcxNDk2NTZ9.mhQW2T6sQiJ8PZrDTyZXmeEo5HesSfpPyWNjXuv-GMc>
Error executing service: <ServiceCall media_player.play_media (c:a181f15bb32291c8f5b1864defeff6f2): device_id=['a5d0a56a34474fa4d3ad1b911caa1e50'], extra=, media_type=music, media_id=https://fakeplaceholder.duckdns.org/media/local/white_noise.mp3?authSig=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI4ZTkzMzc1MjMzYzE0NzE0YWViOGE3OTAxMDVjZGE1MCIsInBhdGgiOiJodHRwczovL215Y3JvZnRob2xtZXMuZHVja2Rucy5vcmcvbWVkaWEvbG9jYWwvd2hpdGVfbm9pc2UubXAzIiwiaWF0IjoxNjQ3MTQ5MzU2LCJleHAiOjE2NDcxNDk2NTZ9.mhQW2T6sQiJ8PZrDTyZXmeEo5HesSfpPyWNjXuv-GMc>
Error executing service: <ServiceCall media_player.play_media (c:74d81e3403eaec85808c7a95c29d9d14): device_id=['a5d0a56a34474fa4d3ad1b911caa1e50'], entity_id=['media_player.living_room_speaker'], extra=, media_type=music, media_id=https://fakeplaceholder.duckdns.org/media/local/white_noise.mp3?authSig=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI4ZTkzMzc1MjMzYzE0NzE0YWViOGE3OTAxMDVjZGE1MCIsInBhdGgiOiJodHRwczovL215Y3JvZnRob2xtZXMuZHVja2Rucy5vcmcvbWVkaWEvbG9jYWwvd2hpdGVfbm9pc2UubXAzIiwiaWF0IjoxNjQ3MTQ5NTg0LCJleHAiOjE2NDcxNDk4ODR9.qxruLTZ8MCJCwtzE_mWB7WW-KJc3tyWeTNYZRbMrUj4>
Error executing service: <ServiceCall media_player.play_media (c:f98e8e585606ef3add19da81c4515544): device_id=['a5d0a56a34474fa4d3ad1b911caa1e50'], extra=, media_type=music, media_id=https://fakeplaceholder.duckdns.org/media/local/white_noise.mp3?authSig=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI4ZTkzMzc1MjMzYzE0NzE0YWViOGE3OTAxMDVjZGE1MCIsInBhdGgiOiJodHRwczovL215Y3JvZnRob2xtZXMuZHVja2Rucy5vcmcvbWVkaWEvbG9jYWwvd2hpdGVfbm9pc2UubXAzIiwiaWF0IjoxNjQ3MTQ5ODc1LCJleHAiOjE2NDcxNTAxNzV9.FbDbJw24es9cVWGzwP6B9ZJKwAGcIdEQ8FO_vjwZz2I>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1654, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1673, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 668, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 949, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 705, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/cast/media_player.py", line 658, in async_play_media
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/pychromecast/quick_play.py", line 77, in quick_play
    controller.quick_play(**data)
  File "/usr/local/lib/python3.9/site-packages/pychromecast/controllers/media.py", line 665, in quick_play
    self.play_media(media_id, media_type, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/pychromecast/controllers/media.py", line 566, in play_media
    raise PyChromecastError()
pychromecast.error.PyChromecastError
1 Like

Exact same thing here. And I can’t get it to play. It’s so frustrating!

I use this method for play media

  1. put media file in media folder
  2. call service : play media
    media_content_id: http://your_HA_IP_Address:8123/media/local/File.mp3
    media_content_type: audio/mp3

Hope this help

1 Like

This works for Yamaha’s MusicCast devices, I just wish the media player and media browser would function like this. I searched for bugs on this topic but did not find anything, perhaps its time to open one.

Edit: I got it working, I had to go into Server Control > General > and set the following to automatic:

I guess now would be a good to time to get my music library in order.

Thanks. That works great for me.
File at:
/config/www/media/bark.mp3

Test Script:

alias: Play Sound File
sequence:
  - service: media_player.play_media
    data:
      media_content_type: audio/mp3
      media_content_id: /local/media/bark.mp3
    target:
      entity_id: media_player.nesthub
1 Like