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

What’s your automation? Normally, if the device is playable from Spotify, it should be working, but since Denon seems to have their proprietary software, they might have a funky way to communicate with the Spotify connect API

Thanks for your reply and you’re right. Since posting I’ve done more testing and research. It seems it has more to do with the Echo Dot than this integration. Meaning, if the Echo Dot goes to standby (which it does after x minutes), I won’t be able to reach it using Spotcast as it gives me this forbidden api call.

I’ve also installed the custom:spotify-card now, and that shows even more clearly what’s going on as all my playlists are greyed out when the Echo Dot has gone to its standby mode. However, if I’m still logged into that Spotify account (I have several since I have Spotify Premium Family) on my phone or laptop it does keep the session alive somehow - but that’s not the workaround I want.

So my workaround for now is to either say “Alexa, play” and the Echo Dot wakes up and I can use my scripts (or playlists) from HA - or, and this option works best for me now, have a routine in the Alexa app that plays a silent 5 second track at a specific time (around the kids bedtime). That way I can use Spotcast/spotify-card when it’s needed.

did you try a media_player.turn_on service call from home assistant? It could potentially wake up the device and make it available again for Spotcast. If it does work, we could try to include this logic of sending a wake call before going further in certain cases directly into Spotcast code.

Yes, I did try that and it doesn’t “wake” the Echo up so it’s active for HA. Only seems to get to that state when something is being played on the Echo (and that needs to be done via the Alexa app?)

I did do a tweak to my setup as I created a “wake up” button (shortcut) on my mini media player card which turns on a virtual switch in Smartthings which my Alexa routine then reacts too and plays that 5 second silent track. So it’s not perfect, but works for me for now :wink:

I guess someone else in the same situation as me can figure out if it really is an Alexa (Echo) issue, an integration (alexa_media_player) issue or just something else…

1 Like

Hi all,

I have a request quite strange. Maybe someone can help me to understand if it is possible (or if it has to be developed):

a nice user finded a way to integrate spotcast with a notifier (this one if you are asking ) so now if music is playing it is paused and then restored after tts messages (so cool !). I still have one little downsize : when music is from my wife account it is paused, but after the tts message my account is used (reducing waf factor).

I’m not a programmer so I’ve searched this answer before doing this post without any result: the account used is somehow “exposed” and can ben “saved” and “restored” as variable?

Thank you in advance

I’ve recently installed spotcast and have good first results with it. However, there is one thing that has been puzzling me:

My main audio devices to listen to Spotify on throughout the house are Google Nest/Home devices. I have a few Minis, a few Hubs and a Nest Audio. If these devices were recently used to Spotify something they’re active and I can just use spotcast.start to start a playlist on that device. However, if they’re idle then trying to use spotcast.start will give me this error message:

Failed to call service spotcast/start. http status: 404, code:-1 - https://api.spotify.com/v1/me/player/play?device_id=(device id number): Device not found, reason: None

But the confusing thing is that when the player is idle I can click on the media player card, go into the player’s media browser from the details popup, navigate to the same Spotify playlist I want to play from there, and click on it to play. Then it will play without having to first ‘activate’ the player. It does appear it is possible to start playback on an idle device this way.

So there is something different between going through the media browser, versus using spotcast.start by itself. Can someone tell me what the media browser does first that makes the player active? If I know what it is, I can just add it myself to a script and start my playback of playlists through spotcast that way.

2 Likes

Same here.

Hey guys,

in my configuration i added this:
spotcast:
sp_dc: !secret primary_sp_dc
sp_key: !secret primary_sp_key
accounts:
niklas:
sp_dc: !secret niklas_sp_dc
sp_key: !secret niklas_sp_key

but I can only see the main account in my entity card, can anyone know how can I change between accounts?
does the account name needs to make sense? or can I write anything? should It be the same name as other HA users in HA or does anything else can cause the problem?

I installed Spotcast and configured the sp keys in yaml. Also installed spotify integration and setup the account

Restarted homeassistant.

The spotcast Lovelace card stays at loading…

Please help how to fix this

1 Like

Does HA itself have to be exposed to the internet for the official spotify integration and spotcast to work?

Using this integration i get, inside other ‘sensors’ the sensor.playlists_sensor which contains some of my favorite playlists and i would like to use this sensor in some automations.
My question is, how to have this sensor updated after i change/add/remove items in my favorite playlists?
What i see actually is that the sensor has always the same playlists…

I have been following a thread between @jazzyisj and @fondberg about the possibility of having a sensor with all your favorite Spotify playlists. I am not sure if this sensor exists or not and if there is, how to use it? And if not, have you found some way to have all your playlists in one sensor so that you can use it in automations?
Anyone who knows about it or interested please reply…

In response to the 10 playlist problem you mentioned in your PM to me. I have been meaning to put in a feature request on the spotcast git to make this a configurable value. I’ll try to get to that later today.

In the meantime in this file /config/custom_components/spotcast/sensor.py change this → limit: 10 to whatever reasonable value you want. I changed it to 40. You will have to change this every time you update spotcast!

As for using the sensor have a look at these files in my config. On is a template select where I load my spotify playlist names into a select entity to choose my playlist in the UI, and the other is the script where I use the selected value from that entity to look up the spotfiy UIR in the playlists sensor to use in my spotcast.start call.

Mine are likely more complicated than yours will need to be because I juggle 3 Spotify accounts and I also use Spotify categories as selectable playlists.

Chew on these and if you can figure it out, cool beans. If not get back to me and I’ll walk you through it.

1 Like

Thanks… i’ll try to customize for my use. I’ll let you know if there is something to understand better…

One question: how you convert the names of the playlists in the URI spotcast compatible?
The sensor gives us the names of the playlists, not the URI. @jazzyisj

That’s done in the uri variable in the spotify play script. Something like this should work for you.

            {% set playlists = state_attr('sensor.playlists_sensor','playlists') %}
            {% if playlists != none %}
              {% for item in playlists %}
                {% if item.name == playlist %}
                  {{ item.uri }}
                {% endif %}
              {% endfor %}
            {% endif %}
1 Like

Hey guys, I’ve just installed spotcast and configured it to use my tokens etc. Confirmed the creds are good. However getting this following error when calling the service as a test.

Logger: pychromecast.controllers
Source: /usr/local/lib/python3.9/site-packages/pychromecast/controllers/media.py:596
First occurred: 19:02:26 (3 occurrences)
Last logged: 19:40:16

PLAY command requested but no session is active.

The last line of the error perplexes me as I thought the point was to create a session when none is active?

Just as a little further info to this. I am trying to call spotcast from a mini-media player card.

type: custom:mushroom-media-player-card
entity: media_player.kitchen_speakers
layout: vertical
icon: mdi:spotify
fill_container: true
use_media_info: true
use_media_artwork: true
show_volume_level: true
volume_controls:
  - volume_mute
  - volume_set
media_controls:
  - play_pause_stop
  - previous
  - next
collapsible_controls: false
tap_action:
  action: call-service
  service: spotcast.start
  service_data:
    device_name: Kitchen Speakers
    uri: spotify:playlist:37i9dQZF1DX7QOv5kjbU68
  target: {}

@jazzyisj Sorry to disturb you, but i have some troubles to convert your script to only one account (mine) and more where to put the templates script? In sensors part of the main configuration?

I have a fresh HA docker installation.
I have created a script to play my playlist ‘Neil’s Work Music’ to a Google Home Hub, but I am getting an error saying ‘NoneType’ object is not subscriptable.

The following log entries are generated:

Logger: homeassistant.components.script.play_neils_work_music
 . . . .
Play Neil's Work Music: Error executing script. Unexpected error for call_service at pos 1: 'NoneType' object is not subscriptable
Traceback (most recent call last):
Logger: homeassistant.components.websocket_api.http.connection
 . . . . . 
[139827962018256] 'NoneType' object is not subscriptable

In a previous HA installation, this same script worked, so it looks like I am missing something in the new installation.

I can see the Google Home Hub as a media player in HA and can cast to it using the Spotify smart phone app.

I looked up the Google Home Hub spotify ID and specified that in the script and also tried using the Device Name, but none of these options worked.

Are there some other tests I can do to confirm that the Spotify integration and spotcast are installed correctly?