Launching and using Spotify in automations

Hi there and thanks @happyleaves for the new Spotify component!

I would like to use it in automations - specifically, I want to be able to press one button and:

  1. turn on my Yamaha AVR
  2. set its source to the one Spotify plays to (Apple TV)
  3. start Spotify*
  4. set the source in the component so it controls the app on the device I want (not sure where to run this)…
  5. tell Spotify to output audio to the Apple TV*

I can do the first 2, but is it possible to do 3-5 (probably not with Home Assistant)?
It seems you have to have Spotify already running somewhere, and you can’t set the source if it’s not running.

Some of this is outside the scope of Home Assistant, but wondering if anyone has any ideas.
(I’m thinking I might have to leave Spotify running on my Linux PC that’s connected to my amp, to avoid the Apple TV complexity.)

I don’t have an ATV but my Yamaha AVR has spotify built in

For the media player I can set

  data:
    entity_id: media_player.kitchen_avr
    source: Spotify

In the spotify component I can choose source as my Yamaha AVR

source: RX-V479

It seems to be quite slow in response to commands (pause/play seems to take at least 5 seconds) so perhaps you need a delay between activating device and setting input, then setting spotify component to source you want to control.

This works for me using a script for the action.

automation…

- alias: spottytest
  trigger:
    platform: xxxx
  action:
  - service: media_player.turn_on
    entity_id: media_player.kitchen_avr
  - service: media_player.select_source
    data:
      entity_id: media_player.kitchen_avr
      source: Spotify
  - delay: 10
  - service: script.turn_on
    entity_id: script.yam_spt_tst

Script.

yam_spt_tst:
  sequence:
- service: media_player.select_source
  data:
    entity_id: media_player.spotify
    source: RX-V479
- service: media_player.play_media
  data:
    entity_id: media_player.spotify
    media_content_id: 'spotify:user:113469951:playlist:7r2Md6JaYjE5TQZCwPCSKn'
    media_content_type: 'playlist'

I spent the last while installing Spotify on my always-on Ubuntu HTPC, so now I have an always-on Spotify, and the HTPC is connected to my Yamaha RX-V671 via 3.5mm audio (AVR does not have Spotify built in).
This makes things much simpler.
I now have a one-button Spotify through my home speakers script… nice!

listen_to_spotify:
  alias: Listen to Spotify
  sequence:
    - service: media_player.turn_on
      entity_id: media_player.yamaha_zone_2
    - service: media_player.select_source
      data:
        entity_id: media_player.yamaha_zone_2
        source: HTPC Music
    - service: media_player.select_source
      data:
        entity_id: media_player.spotify
        source: htpc

1 Like