Cast Media or Pandora to Chromecast Audio

My ultimate goal is to have pandora play on my chromecast audio homegroup (two chrome cast audio devices linked together) when I enter home. I’m having trouble getting any media to cast. Any ideas how to do this?

I currently have this in automation. I made a input_select button to test it out but nothing works.

- alias: Start Music
  trigger:
    platform: state
    entity_id: input_select.music_test
    to: "Start"
  action:
    service: media_player.play_media
    data:
      entity_id: media_player.audiounlimited
      media_id: http://xxxxxxxx.com/wp-content/uploads/2016/05/eye.mp3
      media_type: audio/mp4

This thread might help you find the Eye of the Tiger… :sunglasses: (Your previous post had the full URL and I couldn’t resist…)

HAHA! You picked out exactly the test song I was planning to use!

Don’t give me too much credit; your original post requesting help had the full URL in the code example; I just clicked on it. :smile: Hope the other thread helps. I’ve been meaning to try it out but I have so many other things to work on first. Just got my iBeacons set up and trying to get the manual alarm control panel to work properly. Then I am on to Echo integration. Of course @brusc came out with another video on HA and Tasker so I have to do that now!

Curses! :laughing:

I completed this using tasker & autoremote, as I couldn’t find a way to get HA to play/CA content that wasn’t local source. Currently, I have it set up to cast Pandora, Spotify, & Amazon Music.

Sorry to jump on the thread but @tc23 could you explain abit more how you got this working as im looking at a similar thing Thanks

No problem.

First follow the directions on this link to get your py script and AutoRemote command setup:

Next, get the Tasker Task setup on on your android device (I’m using my Nexus 9 rooted). Rooted is important for me, because I need it to disable the lock screen & wake from Doze. The Tasker Task is a combination of Keyguard plugin, Secure Settings plugin, AutoRemote, & AutoInput. After receiving the command from the py script/AutoRemote, the device wakes & disables the lock screen (using Keyguard & Secure Settings), launches the respective app, then uses AutoInput to pick the group that I want to cast too. Depending on the App (I’m looking at you Amazon Music) casting isn’t available, so I have to use Cast Screen, which is a little hacky, but works nonetheless.

It’s a little roundabout, but it’s the only thing I found to get streaming music to play to CA from HASS. If there is a better solution that I’ve missed, or if you need more detailed instructions, please let me know!

@tc23 thanks buddy I will take a look.

A screenshot of the tanker task would help if you have time first. Do you mind writing out instructions with the different programs you use and where to download? I bought tasked and auto input but I’m a bit stuck now. Thanks!

Maybe also your Python script? Not sure where the url comes from thanks!

1 Like

There’s a great video on this in @brusc series of HomeAssistant videos on YouTube.

I got tasker to work. I need to figure out the how HA integrates now.

Do you mind sharing the HA setup? I’ll post when works!

Who are you replying to? I just posted a video to help, I’m not actually using this at the moment.

So just to confirm, you got the Tasker Profiles & Tasks to work, or you got the app up and running? Tasker is a really amazing and powerful app, however there is a bit of a learning curve. The Tasker plugins that I use for this particular Tasker Profile are:

Keyguard: https://play.google.com/store/apps/details?id=com.balda.keyguard&hl=en

Secure Settings: https://play.google.com/store/apps/details?id=com.intangibleobject.securesettings.plugin&hl=en

AutoRemote: https://play.google.com/store/apps/details?id=com.joaomgcd.autoremote&hl=en

AutoInput: https://play.google.com/store/apps/details?id=com.joaomgcd.autoinput&hl=en

The video that @rpitera posted is for Tasker to HA flow. The article that I posted earlier in the thread pertains to HA to Tasker flow. For my particular setup, I am going from HA to Tasker.

The URL comes from your device specific AutoRemote URL.

My HA setup is set up as a switch that runs the either On.py or Off.py script. The script send an AutoRemote message to the specific Android device, which acts as a trigger to run the Music Casting task (or conversely turn it off).

Please let me know if any of that makes senses. If you are having any trouble with understanding Tasker/navigating it, I would suggest looking at the subreddit /r/Tasker, as the people there are immensely helpful.

Robert, was responding to TC. Thank you for the video, I was studying that last night too!

This morning at 8 AM I was able to figure out all the tasker profile and tasks. i realized secure setting was an app and that is what tripped me out.

When I go home today, I’m going to try to figure out the home assistant integration when I go home. Do you mind sharing your on.py and off.py script? Just so I can see how you did that.What you did is brilliant. I’m almost there! Thank you all!

No worries, here is a sample of the script.

import requests
requests.get(’[URL]’, verify=False)

The URL is from the device specific AutoRemote URL that I previously mentioned. When you go to that URL and put text in the “Message” box (for example the text could say “Pandora”), the URL string will include the specific message that you want to send via AutoRemote. That URL then goes into the ‘[URL]’ part of the requests.get (you do not need the brackets, but you do need the single quotation marks). You will need a script for both an On or Off command, the only difference being the text that you put in the “Message” box for the AutoRemote URL, thereby sending different commands to the Android device.

Note: I was getting a bad SSL handshake, so that is why I include the verify=False.

I can’t wait to go home and test it out thanks!

TC! I was able to get everything to work thank you! Do you mind putting a screenshot of your tasker “Task Edit” page? I’m just curious on the settings used as mine seem to be finnikey depending on if you have pandora open or not.

Here is my Spotify Cast task. Let me know if this is what you are looking for. Thanks!

I think the key is the wait! Thank you!

No problem! I think there is also an option in AutoInput to wait until the specified elements are on the screen, but I have never used that feature (although I should probably investigate it)