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

Had to sign up to the HA-forum to say a massive big thanks to Niklas for making this possible :slight_smile: !!

It is working just perfectly now.

Liamstears, using Spotcast right now so it is working.

Now to look into the topic of modifying the GUI to suit a more personal style.

Thanks, to be honest I did think the problem would be me Iā€™m just not sure what has caused it, was working fine until I did some router work and changed some ipā€™s etc and now its not working

Seems as though it cannot connect to the external network but everything else works fine including all nest and other google integrations so really donā€™t know what went wrong here

Dude! Thanks for that. It works like charm!

:partying_face: :partying_face: :partying_face:

Sharing my automation for other users:

- alias: "Good morning Music"
  trigger:
    - platform: time
      at: '07:00:00'
  action:
    - service: media_player.turn_on
      entity_id: media_player.onkyo
    - delay: '00:00:10'
    - service: media_player.volume_set
      data:
        entity_id: media_player.onkyo
        volume_level: 0.3
    - delay: '00:00:01'        
    - service: media_player.select_source
      data:
        entity_id: media_player.onkyo
        source: pc
    - service: spotcast.start
      data:
        device_name: 'Music'
        uri: 'spotify:playlist:6XiUX0D4w2SP1cL770Zp34' 
1 Like

This is just what I needed for my automations! Thank you!!

Matt

Excellent thanks so much!

Hello everybody!

Iā€™m writing here before eventually creating an issue on Github.
I have an issue with the service spotcast.start. Here is my script :

sequence:
  - service: spotcast.start
    data:
      entity_id: media_player.enceinte_sejour
      uri: 'https://open.spotify.com/playlist/2YtF5Pi7JG5hjoOt0iBUpy'

When I run it, I have this error :

http status: 403, code:-1 - https://api.spotify.com/v1/me/player/play?device_id=d5ea8XXXXXXXXXXXXXXdc06a7d: Player command failed: Restriction violated, reason: UNKNOWN

I hear the ā€œconnectedā€ sound on the Mini but then this error. This error happens with a playlist created by myself, but with a Spotify playlist (Release radar etc.), it works ! Same behaviour with the Spotify playlist card.

Iā€™ve also tested with the usual uri : spotify:playlist:2YtF5Pi7JG5hjoOt0iBUpy

Maybe Iā€™m missing somethingā€¦ Thanks for your help !

Apologize for this question, but i havent been able to figure it out: im creating a scene and want to play a playlist on a speaker. But i can only choose 1 device in the source, despite having multiple google home devices in my home and seeing them in HA. image

What am i doing wrong?

Gold component , thank You very much :slight_smile:

It is possible to play latest podcast from automation/script with Spotcast on a given device? It would be great to add in the automations for the morning.

Great component that has worked well for me. However for some reason in a new script, it does start the device to play music with the selected uri, but it returns a state for the media_player as ā€œunknownā€ when it has been off for an extended period (in this case the night). Which means the automation for turning on the amplifier that looks for ā€œplayingā€ doesnā€™t work and neither does the conditional player I have in the frontend. If I run the script again, some time later it does work, if I run it again immediately it usually still doesnā€™t. I may be able to solve it by using the ā€œunknownā€ state, but I would rather have it start up with the correct state. Anything I should change to have this happen?
core-2021.1.5, supervisor-2021.01.7, Spotcast 3.4.6

# Play wake up sounds as selected
script: 
  wakeup_sound:
    variables:
      wakeup_uri: >
        {% if is_state("input_select.wake_up_sounds", "Birds") %} spotify:track:5vg5nnqYefY17aJZPmO0AI
        {% elif is_state("input_select.wake_up_sounds", "Frogs") %} spotify:user:kenaisea:playlist:6KnSydeZaP2eQwl60VoPgr
        {% elif is_state("input_select.wake_up_sounds", "Crickets") %} spotify:user:mimiwogu:playlist:0vpYZLnwJs8dhy1HJhezX1
        {% elif is_state("input_select.wake_up_sounds", "Rain") %} spotify:user:sonymusicentertainment:playlist:7sXrmazSWcD5jGDX64EpqG
        {% elif is_state("input_select.wake_up_sounds", "Ocean") %} spotify:user:gary96:playlist:4JuHQCzZqpDyVmk39hlMBq
        {% elif is_state("input_select.wake_up_sounds", "Nature") %} spotify:user:spotify:playlist:37i9dQZF1DX4PP3DA4J0N8
        {% endif %}
    sequence:
# Play if sounds are turned on in the frontend
      - condition: state
        entity_id: input_boolean.wake_up_sounds_on
        state: 'on'
# Only if no music is playing already
      - condition: state
        entity_id: binary_sensor.allow_alarm_start
        state: 'on'
      - service: spotcast.start
        data:
          device_name: 'Slaapkamer Stereo'
          uri: '{{ wakeup_uri }}'
      - wait_template: '{{ is_state("media_player.slaapkamer_stereo", "playing") }}'
        timeout: '00:00:30'
        continue_on_timeout: 'true'
      - service: media_player.volume_set
        data:
          entity_id: media_player.slaapkamer_stereo
          volume_level: '{{ ((states("input_number.wake_up_sound_volume") | int /100)) | int }}'

Love this component - great work - have controls all over my house!

One question - Iā€™m now trying to add this as an action within a script (eg turn music on and fade up lights in the morning)

Below yaml doesnā€™t work as it says ā€˜value should be a string for a dictionary value @ data entity_idā€™ - any ideas what Iā€™ve done wrong here??

service: spotcast.start
data:
  uri: 'spotify:playlist:5GN320bEvQsxJxP0Zb30rx'
  random_song: true
  entity_id: media_player.master_bedroom_display

Thank you so much for this component, works like a charm and have been using it with the default account for a while now. Now I am trying to expand it so that my wife and I can both use it with each our account. When adding the account to the script, however, I get the error below:

    Ny automatisering: Error executing script. Unexpected error for call_service at pos 1: 'NoneType' object has no attribute 'get'
    While executing automation automation.ny_automatisering

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 250, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 457, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1484, in _execute_service
    await self._hass.async_add_executor_job(handler.job.target, service_call)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/spotcast/__init__.py", line 281, in start_casting
    access_token, expires = get_token_instance(account).get_spotify_token()
  File "/config/custom_components/spotcast/__init__.py", line 130, in get_token_instance
    dc = accounts.get(account).get(CONF_SP_DC)
AttributeError: 'NoneType' object has no attribute 'get' 

Removing account from the script works as it has so far with the default user/account. What I am trying to do here is use the two accounts so that when my automation is triggered, it does not pause the music playing elsewhere in the house. So thinking of doing something like ā€œif my spotify is playing, use my wifes spotify in the automation and vice versaā€. Is there a better way to achieve this?

Thanks so much

You need to configure the accounts in configuration.yaml like here fondberg/spotcast: Home assistant custom component to start Spotify playback on an idle chromecast device (github.com).
Then you call it like this: fondberg/spotcast: Home assistant custom component to start Spotify playback on an idle chromecast device (github.com)

This is a problem with the updates in the core mediaplayer_spotify integration. It is very slow

Nope, I canā€™t see an issue with what you pasted.

Hello,
This component sounds great, unfortunatley i cannot make it work. I am very new to HA and tons of questions are poping up :stuck_out_tongue:

i have managed to get the sp_dc and the sp_key.

then pasted them in config/configuration.yaml via file editor.

What i need to after that?
sorry for the so basic question. i have tried to follow the documentation on the readme file for this component but i cannot get it to work

thank you in advance.
if someone has the time to help me a bit i will appreciate it a lot.

I have the Spotify integration on my HA as well as Chromecast Audio integration.

Spotcast is one of the best custom component I have used. Thank you very much! I have been using it for months now.
Unfortunately, for the last couple of days I am struggling to make it work again.
I am keep getting an error 'Could not find a version that satisfies the requirement spotify_token==1.0.0ā€™.
Spotcast refuses to load upā€¦ :frowning:

I am using Home Assistant OS 5.11 on a Virtual Machine (Old Windows 10 laptop).
*I have tried removing and reinstalling spotcast
*Changed the sp_dc sp_key multiple times (incognito, new login etcā€¦)

Any suggestions please how to proceed or what to do?
Thanks :slight_smile:

solved it on my own :stuck_out_tongue:

Hey, anyone have any idea?

Solved it by forcing ipv4. (If I could know that 3 weeks ago, I tried everything!!!)