Send local content URL to Chromecast Audio

I am attempting to configure HASS and a Chromecast Audio device to play sounds on the same RPi3 via a share URL. I have the chromecast set up to play an iHeart Radio stream for the dog when I leave, which works, but I can’t get it to play a local media file as an alert sound. Has anyone set this up? Any suggestions on alternate config I need to do?

IHeart radio config - working

  • service: media_player.play_media
    entity_id: media_player.living_room_music
    data:
    media_content_id: [stream url]
    media_content_type: audio/mp3

Local url mp3 file

Both content urls will start playing in my browsers without issue.

I got this to work by installing a plex media server on the raspberry pi. Then used plex to get a stream url that is used on the configuration of home assistant.

I tested with " python -m SimpleHTTPServer " and it worked great… think I might use it to cast voice notifications.

  - service: media_player.play_media
    entity_id: media_player.chromecast_audio
    data:
      media_content_id: http://<<hass_host>>:8000/test.mp3
      media_content_type: audio/mp3
1 Like

I tried that but it was not working for me. I will have to try again, thanks!

I managed to get it working using python -m http.server 8080 (since I’m using Python 3.5) and the following code -

automation 4:
# If you select “FireplaceBurning”, play the “FireplaceBurning.avi” file
- alias: Play FireplaceBurning Lullaby
trigger:
platform: state
entity_id: input_select.lullaby
to: “FireplaceBurning AVI”
action:
- service: media_player.turn_on
- delay: 0:0:02
- service: media_player.play_media
data:
media_content_id: http://192.168.1.56:8080/FireplaceBurning.avi
media_content_type: video/avi

# If you select "Heavy Rain MP3", play the "Heavy Rain MP3" file
- alias: Play Heavy Rain Lullaby
  trigger:
    platform: state
    entity_id: input_select.lullaby
    to: "Heavy Rain MP3"
  action:
    - service: media_player.turn_on
    - delay: 0:0:02
    - service: media_player.play_media
      data:
        media_content_id: http://192.168.1.56:8080/Heavy Rain.MP3
        media_content_type: audio/mp3

If you select "None, turn the Chromecast off

- alias: Stop the Lullaby

  trigger:
    platform: state
    entity_id: input_select.lullaby
    to: "None"

  action:
    service: media_player.turn_off

Define our dropdown list

input_select:
lullaby:
name: Lullaby
options:
- Heavy Rain MP3
- FireplaceBurning AVI
- None
initial: None
icon: mdi:weather-rainy

I could not get it to work at all with either streaming or MP4 files however AVI and MP3 work great.

@jasonmscollins How exactly did you do that mate ? I have a plex media server running in my Synology NAS which I can play from Web address. And from Plex ofcourse I can cast any media to Chromecast. But from hass, I can’t trigger any media via Chromecast; while my chomecast is discovered in hass but plex is not discovered there though. But I dont think that should be problem as I wanted to play the media from plex through Chromecast. So, I think Plex need not to be discovered in hass ??

The problem I find the media link which I need to play… If I try via the dev-service > media_players.play_media and then trying to cast the media_content_id as “http://:32400/library/metadata/397”. Should it be the right address ?

I got the metadata information from the dev-state > Chromecast > media_information… But it seems it is not the right address :frowning:

By the way, if I directly paste the link in a web, it opens up a xml file instead of opening the media.

Thanks
Tarikul

@tarikul did you ever get this working? im looking at geeting a chromecast and of course these days i buy tech to fit in with my HA_

Hi Jason, to play local media via Chromecast from home assistant, in my case it worked only if I ran Python simplehttpserver. I couldn’t get Plex work properly to meet my requirement.

However, as I didn’t like the idea of running the simple http server in background. I completely moved to Kodi media centre where I can even play YouTube video from Hass. In deed, some days, I quickly upload a video in YouTube in private mode, get the ID and straightaway play at home to instruct or inform something via the TV :slight_smile: when I am at office…
Thanks

I am able to play a remote URL mp3 file using google cast. But when I run the python simple HTTP server, the file does not play. If I pate the URL (http://localhost:8000/garagedooropen.mp3) in a browser tab, the audio plays fine, so the URL is correct. Any ideas, maybe one of you guys has encountered this?

1 Like

I was able to run under Ubuntu like this:

I run simple http server under my ha_audio folder, not sure which makes any difference or not
python3 -m http.server 8091

And this is how I run service:

- service: media_player.play_media
  data:
    entity_id: media_player.audio_house_speakers
    media_content_id: http://192.168.1.22:8091/ha_audio/SomeAudioFile.mp3
    media_content_type: audio/mp3

Hi! Is it possible to stream a url to a radio channel to my Chromecast audio. I can’t get it to work with this setup.

alias: Google audio p4
trigger:
  platform: state
  entity_id: input_boolean.radio_p4
  state: 'on'
action:
  - service: media_player.play_media
    entity_id: media_player.kk
    data:
      media_content_id: http://tunein.com/radio/P4-Malm%C3%B6hus-1020-s47336/

It is possible. I stream an iHeartRadio station to my google home when I’m not around so the dogs don’t have to hang out in silence.

    - service: media_player.play_media
      entity_id: media_player.google_home
      data:
        media_content_id: "http://wegr-fm.akacast.akamaistream.net/7/628/20075/v1/auth.akacast.akamaistream.net/wegr-fm"
        media_content_type: "audio/mp3"
2 Likes

I was having a similar issue until I used the same syntax that @Bahnburner used. Thanks @Bahnburner

Glad I could help.

Thanx to both @Bahnburner and @adamderuwe . It works!

Were you ever able to get this to work with TuneIn? All I get is Default Media Receiver Idle

Didn’t try, but i had the same problem in the begining. I solved it by open my live stream with vlc. In VLC I looked at information and found a direct link to the stream. I hope it can help you.

however this is my setup and it works

alias: Google audio på p4 köket
trigger:
  platform: state
  entity_id: input_boolean.radiomalmo_p4
  state: 'on'
action:
  - service: switch.turn_on
    entity_id: switch.google_audio_kket
  - delay: 00:00:03
  - service: media_player.play_media
    entity_id: media_player.kk
    data:
      media_content_id: "http://http-live.sr.se/p4malmo-mp3-192"
      media_content_type: "audio/mp3"

Thank you! I will give it a shot

Is it possible to cast a link from Spotify to google audio? Can’t get it to work and I think it is because account and password. Someone that have succeed with this?

2 Likes

Hi

Are you running SSL as well? will the python -m http.server 8080 interfere with HA?

Also can you please guide me on how to set it up? I cannot play my mp3 files to my chromecast audio.

Thanks