Spotcast - custom component to start playback on an idle chromecast device

As of today spotcast can easily be installed using HACS

3 Likes

Did you see the latest release has random song as well as random playlist?

Have a look at my post about the spotipy version issue posted a couple of days ago. If you still experience this issue please open an issue on github so I can get a chance to debug this with your help (if you are willing to help out)

Yes! It worked wonderfully. Thank you.

There have been several times when music stops playing at exactly 1 hour of play. Has anyone seen this or know if its a google groups thing, chromecast component, or this component?

I’ve experienced that music stopped after 1 hour. I think it is because the token is valid for 1 hour. I’m not sure how to fix this because the token is set using pychromecast whilst launching the spotify app on the chromecast device. What is needed is to sniff the traffic between a phone or a chrome browser running the web player and see if there are any updates of the token.

I installed using HACS and I think everything is set up correctly as far as username, pass and all that. I’m getting a client error.

400 Client Error: Bad Request for url: https://accounts.spotify.com/api/login

You might have run into the issue with wrong spoitipy version sd described in Spotcast - custom component to start playback on an idle chromecast device

Just wanted to share this script that prevents the bleep-bloop sound when you start casting. Essentially it mutes the media player, plays a random 1 second track to activate the casting device, then unmutes and starts playing. Now the first thing I hear in the morning is my favorite song, so much better than ‘bleep-bloop’ :sunglasses:

start_playlist:
  alias: 'Start playlist'
  sequence:
    - service: media_player.volume_mute
      data:
        entity_id: media_player.<your google home device>
        is_volume_muted: true
    - service: spotcast.start
      data:
        device_name: '<your Spotify device name>'
        uri: 'spotify:track:5V3b2UB9tCAHuqXj2b2EP7'  # track with 1 second of silence 
    - service: media_player.volume_mute
      data:
        entity_id: media_player.<your google home device>
        is_volume_muted: false
    - service: media_player.volume_set  #setting the volume is optional ofcourse
      data:
        entity_id: media_player.<your google home device>
        volume_level: 0.20
    - service: spotcast.start
      data_template:
        device_name: '<your Spotify device name'
        uri: "spotify:playlist:{{ playlist_id }}"
        random_song: true

Calling the script from e.g. a Lovelace button:

        tap_action:
          action: call-service
          service: script.start_playlist
          service_data:
            playlist_id: 37i9dQZF1DX9DHKgiu5R9j
5 Likes

That was a smart script. I’m wondering if I could easier do this from python code.

Probably :wink:

How can I check my spotipy version and replace it with your fork?

That is the big question I also had in my post…
If you can’t find a way I might have to release my fork under a different namespace

New to the forum and Home Assistant. Just got up an running and basically only have some media players and sensors configured. No automation using services yet.

I came across this custom component and it looks interesting. I have some questions though.

First, documentation is not clear for a HA n00b.
“Add the following to your config”
What config? HA configuration.yaml?
Add it as what? media_player, sensor, something else?

Is the main Spotify component required? I don’t expect to be using HA for controlling Spotify.

What I hope to achieve with this custom component is the following, hope it’s possible as an automation.

When I’m home and my Pioneer media_player is on and I open the Spotify app on my phone automatically “spotify connect” it to my chromecast (connected to the Pioneer) and set the correct input on the Pioneer. So not start any specific playlist, play what I choose in the phone app.

Similarly I want the corresponding automation for my girlfriend using her own Spotify account (and phone).

Thanks a lot in advance for any help!

Thank you very much for this component!

However, the token issue (only 1 hour music) is a pity. As an end-user, do I need to write a script that relaunch the Spotcast playback every 60 minutes?

The term configuration that you will come across in Home Assistant docs and forums is the configuration.yaml which is the main configuration for home assistant.
So you can just add the spotcast: as a top level struct (in HA terms it is called platform) in there according to the docs you read.

The Spotify media_player component that is built in is not required.

Regarding your use case with your phone and your chromecast connected to your Pioneer it looks like this component can do a bit of what you need, namely starting spotify on the chromcast device.

If I understand correctly you want an automation if your phone starts spotify, can you elaborate a bit on this?

With this component you can transfer your current playback (if any) to that chromecast see transfer playback.

Hi, I want to again state that this is an open source project that is provided free of charge and is developed on a non-paid basis. As such it is up to the community to help out.
What you can do is help out investigate what is needed to keep the playback for a longer time so we can add it to the components code or any of its libraries it uses.
For example, can you test on the webplayer (https://open.spotify.com) in Chrome by starting playback on a chromecast and then closing the browser, will the playback continue after 60mins? Same test with doing it from the phone and killing the app after playback.
If you find how to extend it I am more that willing to help you with how to add it as code.

Super, thanks! Seems like a plugin I can use indeed. Hope to try it out soon.
OK, I wasn’t aware you could add custom toplevel structs. i thought they all needed to be part of the standard ones.

Basicly the use case is. I’m too lazy to go through the Spotify Connect process everytime I open my Spotify app on the phone when I’m home :smiley:

Hey,

Seem to have a breaking change in 0.99;

Component error: spotcast - No module named ‘pychromecast.controllers.homeassistant’

I heard that. I haven’t had any time to check it out. Was hoping that someone could help out and create a PR for it. But if no one does it I’ll see if I have some time in the weekend

1 Like