Play Apple Music playlist on Apple TV

I’d like to have an automation that starts an Apple Music Playlist on my ATV. Does anyone here have this figured out?
In my latest attempt I used the apple remote commands in a script. But it’s very unreliable. This is the script.
The Apple Music app is the second app from the top left on my ATV (yours might be located in another spot).

atvmusic:
  alias: Start Music
  sequence:
    - alias: step1
      service: remote.send_command
      data:
        entity_id: remote.appletv
        command:
          - top_menu
    - delay:
        seconds: 3
    - alias: step2
      service: remote.send_command
      data:
        entity_id: remote.appletv
        command:
          - menu
    - alias: step3
      service: remote.send_command
      data:
        entity_id: remote.appletv
        command:
          - right
    - delay:
        seconds: 3
    - alias: step4
      service: remote.send_command
      data:
        entity_id: remote.appletv
        command:
          - select
    - delay:
        seconds: 3 
    - alias: step5
      service: remote.send_command
      data:
        entity_id: remote.appletv
        command:
          - select

I’m not an Apple Music user, but I can tell you what’s possible with the iTunes component. Point your browser to:

http://[Your Itunes Host Here]:8181/playlists

That will give you a JSON list of your playlists with a bunch of records like:

{“id”:“a-3-star-unrated”,“name”:“A: 3+ Star / Unrated”,“loved”:false,“duration_in_seconds”:3056627,“time”:“35:09:03:47”}

where the 2nd parameter is the name you can reference to play the playlist. If your apple music playlist will be usable, it will be listed somewhere in this list.

Once you have that, you can make a call to the play playlist function as follows to play it:

image

I used the lovelace custom button card to make buttons to call my playlists as follows:

    - type: "custom:button-card"
      name: Jazz
      action: service
      service:
        domain: media_player
        action: play_media 
        data:
          entity_id: "media_player.itunes"
          media_content_id: "best-jazz"
          media_content_type: "playlist"

Just create one of those for each playlist you want to use, and iTunes will play it. You can control which AppleTV it plays on by using the custom mini-media-player component to make small speaker controls where you can turn each endpoint on and control it’s volume when streaming as an airPlay speaker as below (mine are grouped into entity cards). You can find the list of all your AirPlay devices in iTunes (AppleTV’s) by going to the url

http://[Your Itunes Host Here]/airplay_devices

    - type: entities
      title: First Floor
      show_header_toggle: false
      entities:
      - entity: media_player.living_room_airtunes_speaker
        type: custom:mini-media-player
        name: Living Rm
        hide_controls: true
        hide_mute: true
        group: true

Good luck, I’d love to hear if this works for Apple Music playlists as well!

1 Like

Nice to see someone replied on this topic. Thank you. I will report back soon if this is working or not.

Cool, hope it helps. The iTunes stuff is a bit tricky to figure out at first because for whatever reason, there’s not much info about it out there… But it works well once you get it going.

By the way, you will probably want to do this to make sure that any playlists you make on mobile show up in iTunes on your Mac too:

I’v decided not to test the setup that is described above. The iTunes component needs a Mac (or PC) running with iTunes. I don’t like that. I will wait and see if something better comes along that doesn’t need iTunes. But thanks for the tips and advice @scstraus

The only other thing I could think of it if you just use the Apple TV directly via remote commands to navigate to the playlist. Hopefully with enough scripting and testing you could get something to work reliably, but it would be much slower to respond than just telling itunes to play what you want. Unfortunately there are not many more Apple Music clients out there than the one in iTunes, the one on Apple TV, and the one on iOS (which I don’ t think there’s a way to control)… If you wanted Spotify or something, you’d probably have more options.

In order to play Apple Music playlist on Apple TV, I use the DRmare Apple Music Converter to help me. And it can keep the high audio quality of Apple Music.

What I do is that I have exposed an input_boolean to Homekit. Then in my Apple Home app, I have defined that when that input_boolean (it’s shown as a switch in the Home app) turns on, it should play My favorites-playlist from Apple Music on X Airplay speakers. The device set as Home hub will distribute to the defined speakers. Works as a treat.

Let me know if you need screenshots. :slight_smile:

4 Likes

You can play Apple Music on Apple TV directly if you use the Apple TV 4.
Open the Music app.
Select a song.
Press and hold the trackpad on the Siri Remote for one second while the song is playing to call up the options menu.
Select Go to Album.
And you can also convert Apple Music to MP3 with an Apple Music converter like TunesKit Audio Converter and you can play them on any model or device.
And you can follow this tutorial: How to play Apple Music on Apple TV