Spotify alarm clock script not quite working

Last week I posted about my spotify integration suddenly stopping working but thankfully it has now started working again. Now I am trying to get it to work exactly as it should but I keep running into small snag and I’m hoping someone can help me find a solution.

I have an alarm clock automation and as part of that it triggers a spotify script to start playing a playlist on shuffle on my Echo device. It doesn’t always happen but sometimes I get the following error:

HTTP Error for PUT to https://api.spotify.com/v1/me/player/play returned 404 due to Player command failed: No active device found

I am wondering if this happens because the spotify integration or something goes to sleep after a period of inactivity?

My script looks like this

    - service: media_player.select_source
      data:
        entity_id: media_player.spotify_chewitt86
        source: "Bedroom Echo"
    - service: media_player.play_media
      data:
        entity_id: media_player.spotify_chewitt86
        media_content_type: "playlist"
        media_content_id: "spotify:playlist:3nNsZuM4lX04UdgWBiluDa"
    - service: media_player.shuffle_set
      data:
        entity_id: media_player.spotify_chewitt86
        shuffle: true
    - service: media_player.media_next_track
      data:
        entity_id: media_player.spotify_chewitt86

Is there a way of say activating/turning on spotify before I then run through the script?

Did you find a resolution for this? I am having the same issue. It looks like the spotify API will deactivate and close the connection after a period of inactivity and you need to reactivate it by playing something from another device. I wonder if there is a way to keep this alive.

Not sure if this is still valid but I was also looking to install some radio / spotify alarm option. What I found in another thread is to first turn the device on, maybe that is an option:

alarm_clock_loop:
alias: Alarm Clock Loop
sequence:

  • service: media_player.turn_on
    data:
    entity_id: media_player.hk_citation_one_9cda11