Spotify select source fails intermittently

So I’ve been using Spotify media player as my alarm for a few years now. It used to work perfectly, after a while it started to fail from time to time and in the past two months it fails almost every day.

My script runs at selected time and it does simple stuff:

  • media player select_source

  • media player shuffle to true

  • play media

What happens is that intermittently this script would fail on the first step with error:

HTTP Error for PUT to* [*https://api.spotify.com/v1/me/player/shuffle?state=true*](https://api.spotify.com/v1/me/player/shuffle?state=true) *with Params: {} returned 404 due to Player command failed: No active device found

Obviously, I’ve verified and the value for the source in step 1 is correct. Moreover, if I run the script again it will most likely run just fine. And then a few times after that it would run fine. But then I leave it for a while, and it would fail again :man_shrugging:. The device I am playing on is Amazon Echo.

Does anyone know a way to make this integration more robust?