Spotify Playlist Player

hi im on the latest hassio 0.63.3 do i have to add that?

how can you put the images of the playlists?

same for me it ignors my sonos and just plays it on my echo dot

I’ve gotten everything to work but the volume. I originally tried:

volume_level: ‘{{ states.input_slider.spotify_volume.state }}’

But I got this error:

Invalid service data for media_player.volume_set: expected float for dictionary value @ data['volume_level']. Got "'{{ states.input_slider.spotify_volume.state }}"

it appears you may have used data: instead of data_template:

Testing configuration at /config
ERROR:homeassistant.loader:Unable to find component input_slider
ERROR:homeassistant.setup:Setup failed for input_slider: Component not found.

Failed config
General Errors:
- Component not found: input_slider
- Setup failed for input_slider: Component not found.
- Setup failed for script: Invalid config.

What is going wrong ?

edit : input_slider: has to be input_number:

now I only got this left:

Testing configuration at /config
ERROR:homeassistant.config:Invalid config for [script]: expected a dictionary for dictionary value @ data['script']['alias']. Got 'Play selected spotify playlist'
expected a dictionary for dictionary value @ data['script']['sequence']. Got [OrderedDict([('service', 'media_player.volume_set'), ('data', OrderedDict([('entity_id', 'media_player.spotify'), ('volume_level', '‘{{ states.input_slider.spotify_volume.state }}’')]))]), OrderedDict([('service', 'media_player.select_source'), ('data_template', OrderedDict([('entity_id', 'media_player.spotify'), ('source', '{% if is_state("input_select.spotify_source", "Stue") %} Stue {% elif is_state("input_select.spotify_source", "Køkken") %} Køkken {% elif is_state("input_select.spotify_...
expected a dictionary for dictionary value @ data['script']['spotify_music']. Got None. (See /config/configuration.yaml, line 195). Please check the docs at https://home-assistant.io/components/script/
ERROR:homeassistant.setup:Setup failed for script: Invalid config.

It appears that there is something wrong with the script, im not sure if you simply forgot to eddit it to your specific config (it seems like you use the names of my chromecasts?) or if the scripts have gone through som breaking changes since i posted them.

I’m gonna update the config in my original post when I have the time to revamp my HA setup in the future. A lot have happened in HA since july last year, and a lot of people seems to like the player :smiley:.

2 Likes

{% if is_state(“input_select.spotify_source”, “Stue”) %} Stue

Is the last Stue the name of your audio system ? and the first name what is seen on the combobox ?

I cant get it to work…

Error executing service
Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/homeassistant/core.py”, line 1006, in _event_to_service_call
await service_handler.func(service_call)
File “/usr/lib/python3.6/site-packages/homeassistant/components/media_player/init.py”, line 402, in async_service_handler
yield from getattr(player, method[‘method’])(**params)
File “/usr/lib/python3.6/asyncio/futures.py”, line 332, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.6/asyncio/tasks.py”, line 250, in _wakeup
future.result()
File “/usr/lib/python3.6/asyncio/futures.py”, line 245, in result
raise self._exception
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/lib/python3.6/site-packages/homeassistant/components/media_player/init.py”, line 693, in play_media
raise NotImplementedError()
NotImplementedError

spotify:
    sequence:
      - service: media_player.turn_on
        data:
          entity_id: media_player.all
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.all
          volume_level: '{{  states.input_number.spotify_volume_all.state  }}'
      - service: media_player.select_source
        data_template:
          entity_id: input_select.speakers
          source: >
           {% if is_state("input_select.speakers", "All") %} media_player.all
           {% elif is_state("input_select.speakers", "Music") %} media_player.music
           {% elif is_state("input_select.speakers", "Living Room") %} mediaplayer.livingroom
           {% elif is_state("input_select.speakers", "Hallway") %} media_player.hallway
           {% elif is_state("input_select.speakers", "Kitchen") %} media_player.kitchen
           {% endif %}
      - service: media_player.play_media
        data_template:
          media_content_type: playlist
          media_content_id: >
           {% if is_state("input_select.spotifylist", "Morning Commute") %} spotify:user:spotify:playlist:37i9dQZF1DX2MyUCsl25eb
           {% elif is_state("input_select.spotifylist", "Cinematic Chill-Out") %} spotify:user:spotify:playlist:37i9dQZF1DWVFJtzvDHN4L
           {% elif is_state("input_select.spotifylist", "From a Smokey Bar") %} spotify:user:spotify:playlist:37i9dQZF1DWTlzJXLRpd4a 
           {% elif is_state("input_select.spotifylist", "Piano in the Background") %} spotify:user:spotify:playlist:37i9dQZF1DX7K31D69s4M1
           {% elif is_state("input_select.spotifylist", "Productive morning") %} spotify:user:spotify:playlist:37i9dQZF1DX6T5dWVv97mp
           {% elif is_state("input_select.spotifylist", "Morning motivation") %} spotify:user:spotify:playlist:37i9dQZF1DXc5e2bJhV6pu
           {% elif is_state("input_select.spotifylist", "Morning stroll") %} spotify:user:spotify:playlist:37i9dQZF1DWWLToO3EeTtX
           {% elif is_state("input_select.spotifylist", "Soft pop hits") %} spotify:user:spotify:playlist:37i9dQZF1DWTwnEm1IYyoj
           {% elif is_state("input_select.spotifylist", "Deep focus") %} spotify:user:spotify:playlist:37i9dQZF1DWZeKCadgRdKQ
           {% elif is_state("input_select.spotifylist", "Peaceful piano") %} spotify:user:spotify:playlist:37i9dQZF1DX4sWSpwq3LiO
           {% elif is_state("input_select.spotifylist", "Wake up happy") %} spotify:user:spotify:playlist:37i9dQZF1DX0UrRvztWcAU
           {% elif is_state("input_select.spotifylist", "Feeling good") %} spotify:user:spotify:playlist:37i9dQZF1DX9XIFQuFvzM4
           {% elif is_state("input_select.spotifylist", "Comfort zone") %} spotify:user:spotify:playlist:37i9dQZF1DWYWddJiPzbvb
           {% elif is_state("input_select.spotifylist", "Wake up and smell the coffee") %} spotify:user:spotify:playlist:37i9dQZF1DXcxacyAXkQDu
           {% elif is_state("input_select.spotifylist", "Have a great day") %} spotify:user:spotify:playlist:37i9dQZF1DX7KNKjOK0o75
           {% elif is_state("input_select.spotifylist", "Confidence boost") %} spotify:user:spotify:playlist:37i9dQZF1DX4fpCWaHOned
           {% elif is_state("input_select.spotifylist", "Soulful morning") %} spotify:user:spotify:playlist:37i9dQZF1DX8Md3JnnrexB
           {% elif is_state("input_select.spotifylist", "Another one fights the dust") %} spotify:user:spotify:playlist:37i9dQZF1DXcI5whHzonSg
           {% elif is_state("input_select.spotifylist", "Lounge soft house") %} spotify:user:spotify:playlist:37i9dQZF1DX82pCGH5USnM
           {% elif is_state("input_select.spotifylist", "Cocktails") %} spotify:user:spotify:playlist:37i9dQZF1DWWzhxZzVxMP3
           {% elif is_state("input_select.spotifylist", "Happy beats") %} spotify:user:spotify:playlist:37i9dQZF1DWSf2RDTDayIx
           {% elif is_state("input_select.spotifylist", "Soul coffee") %} spotify:user:spotify:playlist:37i9dQZF1DXaXDsfv6nvZ5
           {% elif is_state("input_select.spotifylist", "Just smile") %} spotify:user:spotify:playlist:37i9dQZF1DWVu0D7Y8cYcs
           {% elif is_state("input_select.spotifylist", "Soft morning") %} spotify:user:spotify:playlist:37i9dQZF1DXb5Mq0JeBbIw
           {% elif is_state("input_select.spotifylist", "Smooth morning") %} spotify:user:spotify:playlist:37i9dQZF1DX6FpuSJJgdDF
           {% elif is_state("input_select.spotifylist", "The stress buster") %} spotify:user:spotify:playlist:37i9dQZF1DWUvQoIOFMFUT
           {% elif is_state("input_select.spotifylist", "Sweet songs for sunny days") %} spotify:user:spotify:playlist:37i9dQZF1DX1BzILRveYHb
           {% elif is_state("input_select.spotifylist", "Seize the day") %} spotify:album:4B4nVmQZWZ44Y4yzLDa5n1
           {% elif is_state("input_select.spotifylist", "My list") %} spotify:user:dawnlord:playlist:6YrwtfevNdgc44vI2HiO5j
           {% elif is_state("input_select.spotifylist", "Feel good dinner") %} spotify:user:spotify:playlist:37i9dQZF1DXbm6HfkbMtFZ
           {% elif is_state("input_select.spotifylist", "Soulful dinner") %} spotify:user:spotify:playlist:37i9dQZF1DWZheHO7xislj
           {% endif %}

When I activate a playlist spotify plays it, but it won’t cast to mu chromecast in my kitchen. I get this error.

Error executing service <ServiceCall media_player.select_source: entity_id=['media_player.spotify'], source=>
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/homeassistant/core.py", line 1006, in _event_to_service_call
    await service_handler.func(service_call)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/homeassistant/components/media_player/__init__.py", line 402, in async_service_handler
    yield from getattr(player, method['method'])(**params)
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 331, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 244, in _wakeup
    future.result()
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 244, in result
    raise self._exception
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/homeassistant/components/media_player/spotify.py", line 241, in select_source
    self._player.transfer_playback(self._devices[source],
KeyError: ''

I think the problem is that HASS don’t see my chromecast. If I first cast from my phone then choose a new playlist in HASS, then chromecast plays the new playlist.

Any idea to solve this? It’s pretty annoying that i have to cast first from my phone.

Sorry, it’s a known bug between Chromecast and HASS. From what I’ve read there is no other solution.

@Henrik1986 It sounds like the problem I encountered - and why I have abondening making Spotify work with Chromecasts and the Spotify Component - it’s simply too unreliable.

Yes, as @bonterra notes, HASS can have some difficulties with connecting to chromecasts. But if you really want to troubleshoot it not being the Spotify Component: Take a look at the spotify attributes - I bet you the reason that it’s not working is that the component have forgotten that your chromecast exists - until you cast from your phone. According to the component documentation you are only supposed to do this on the initial setup, but something goes wrong between spotify connect and the component where it simply refuses to remember chromecasts at random. The error is often blamed on spotify connect, but to be honest I don’t give much for that explanation since this is not an issue for any other device I own running Spotify.

If you find that the above seems to be correct in your case you can give Mopipy + Icecast2 a try, I havent have time to try it myself yet, but @robwolff3 did a post about it back in January.

I can see the group. I can change the options, but it doesn’t work. Can anybody help me out ? This is the code:
conf.yaml:

input_number:
      spotify_volume:
        name: Volume
        icon: mdi:volume-high
        min: 0
        max: 1
        step: 0.05
    input_select:
      spotify_playlist:
        name: 'Playlist:'
        options:
          - Zunday
          - Very Chill
          - Rock als achtergrondmuziek
          - Stevig Rocksken
        icon: mdi:spotify
      spotify_source:
        name: 'Geluidsbron:'
        options:
          - Living
          #- Køkken
          #- Lejligheden
          #- iPad
        initial: Living
        icon: mdi:speaker-wireless

automation.yaml

> - alias: 'Set Spotify Volume'
>   trigger:
>     platform: state
>     entity_id: input_number.spotify_volume
>   action:
>     service: media_player.volume_set
>     data_template:
>       entity_id: media_player.spotify
>       volume_level: '{{  states.input_number.spotify_volume.state  }}'  

script yaml:

> spotify_music:
>   alias: Speel Spotify playlist af
>   sequence:
>     - service: media_player.volume_set
>       data:
>         entity_id: media_player.spotify
>         volume_level: '0.40'
>     - service: media_player.select_source
>       data_template: 
>         entity_id: media_player.spotify
>         source: >
>          {% if is_state("input_select.spotify_source", "Living") %} media_player.slaapkamer
>          {% endif %}
>     - service: media_player.shuffle_set
>       data:
>         entity_id: media_player.spotify
>         shuffle: true     
>     - service: media_player.play_media
>       data_template:
>         entity_id: media_player.spotify
>         media_content_type: playlist
>         media_content_id: >
>          {% if is_state("input_select.spotify_playlist", "Zunday") %} spotify:user:faecon:playlist:07oxC0MVnLEC4KrABYiGWC
>          {% elif is_state("input_select.spotify_playlist", "Very Chill") %} spotify:user:faecon:playlist:7oXs3UR9t98O85j9gBYpyG
>          {% elif is_state("input_select.spotify_playlist", "Rock als achtergrondmuziek") %} spotify:user:faecon:playlist:3Pc0LqF9utR6Us3RQQhZCN
>          {% elif is_state("input_select.spotify_playlist", "Stevig Rocksken") %} spotify:user:faecon:playlist:1muozfkT04sR822xe6Zw1r 
>          {% endif %}

where media_player.slaapkamer is my bose soundtouch ( only 1)

I finally got the volume working. I noticed though if you change the volume in Spotify, the volume slider for this player won’t update. Might be a new feature to add.

Is there a way to get the current volume level from the Spotify player in Home Assistant?

Update: I was able to add that feature with this:

- action:
  - data_template:
      entity_id: input_number.spotify_volume
      value: "{{states.media_player.spotify.attributes.volume_level}}"
    service: input_number.set_value
  alias: Spotify Playlist Volume Set
  condition: []
  id: '1523468433728'
  trigger:
  - entity_id: media_player.spotify
    platform: state

Has anyone gotten podcast URI’s to work? Or is this feature not supported yet?

Good morning.

I got my spotify works. However, I don’t understand about the media_player part especially the aliases part. Please kindly advice.

media_player:
  - platform: spotify
    client_id:  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    client_secret:  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    aliases:
         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: 'Web Player (Chrome)' <== Where is the 'xxx' from and stand for? and also "Web Player (Chrome)" <== is this the name of speaker devices in HA example 'name of the media_player in ha I have?
         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: 'All Home Speakers'

Thank you very much. I got it working so nice.

regarding the question above ‘aliases’ I didn’t use that part in my media_player at all.

Makani where did you add this code? Thanks!

Also what is the “ID” in your example.

@makani47
Your automation only updates when you pause or play the spotify. I added a feature to change the sliders while playing. It includes a 10 second delay to prevent input number jumping to “original” value. So when volume changed outside HA it actually takes 10 seconds + time to notice the change to update input_number.

@Dracoy
That code needs to be in “automation:” section. If you want to modify your automations from the front end they need to have unique ID’s. ID can be whatever you come up with.

- alias: Spotify volume (set)
  trigger:
  - platform: state
    entity_id: input_number.spotify_volume
  action:
  - service: media_player.volume_set
    data_template:
      entity_id: media_player.spotify
      volume_level: '{{ states.input_number.spotify_volume.state }}'

- alias: Spotify volume (get)
  trigger:
  - platform: template
    value_template: '{{(states.media_player.spotify.attributes.volume_level | float) != (states.input_number.spotify_volume.state | float) }}'
  action:
    # 10 second delay to prevent input_number jumping to "original" value
    # before it is updated from spotify
  - delay: '00:00:10'
  - service: input_number.set_value
    data_template:
      entity_id: input_number.spotify_volume
      value: "{{states.media_player.spotify.attributes.volume_level}}"
1 Like