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

@fondberg The initial play starts a lot quicker with the new 2.0.0.b1 version, great!
The sensor ‘sensor.chromecast_devices’ seems to be gone, is that correct?

Yes. The sensor is not enabled by default. You can still add it though manually in the conf.

I am not sure how to do this. Just saw this, but by default it is not commented out https://github.com/fondberg/spotcast#known-issues

I guess I am missing a quite obvious thing here :slight_smile:

As you use the beta version you need to chat k the branch which it is released from. Master branch is still using the sensor as default.

If you want to add the sensor you just add

sensor:
    - platform: spotcast

edited, thanks @JBS for pointing out the typo

Thanks, that was the trick. For others: Be sure to use it like below :smile:

sensor:
  - platform: spotcast

Just found an issue that I wanted to share.
Home assistant is using spotipy_homeassistant-2.4.4.dev1 which is a fork of the spotipy python package, reason is that the author of spotipy has vanished from the face of the earth and don’t merge any pull requests since 2 years. I also use a forked package which is called fondberg_spotipy-2.4.5.dev2. My one contains some bugfixes and works with playback but is backwards compatible.
The problem is that it used to be that the custom components python requirements were installed after hass standard packages.
This seems to not be the case anymore. What this means is that if the hass spotipy is used then it is not possible to play anything with my component.

Does anyone know if a clever trick to fix this? If not I think I perhaps can change the scope of my spotipy and call it something else and avoid the conflict. It would be a pity though.

I will release version 2.0 now because this issue would be the same regardless of version.

Edit: version 2 is released

Edit 2: added random playlist support also but it is not documented yet. Just wanted it for myself. Try it with adding “random” as the uri. Works with random_song also…

1 Like

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!