Is it possible to play a music playlist in HA from jellyfin?

So im trying to get a script to play a music playlist on my apple tv (the music is on another server, on jellyfin)
this is a working script to play a song, how do i change it to playlist?

alias: play song
sequence:
  - service: media_player.play_media
    target:
      entity_id: media_player.appletv
    data:
      media_content_id: media-source://jellyfin/track~~6ca03dbeffd5dc24e233769d14ee5d5b
      media_content_type: audio/mp3
mode: single

I have tried changing content id and type but… i guess i be blind noob
really appreciate help any pointers in right directon thanks
sorry if its an stupid question but i tried searching but i couldnt really find anything helpful… thanks so much you guys

2 Likes

Did you ever figure this out?

Same question. When building the scipt in the Visual Editor I can see the Playlists in Jellyfin, but it won’t let me select a playlist, only individual songs within a playlist.

Has anyone ever found a solution?

This would be very useful. As is, the integration is not useable for anything other than notifications/alarms. If an album or a playlist can’t be played, or if no queue can be made, then it’s useless for listening to music as such.

I can control my audio receiver through Home Assistant and can send individual tracks to the receiver from Jellyfin through Home Assistant. The missing piece to the puzzle seems to be the ability to send jellyfin playlists to the receiver via Home Assistant. Just wondering if anyone was ever able to figure this out. Thanks.

I eventually got a playlist working however it is very manual.

alias: Play Shuffled Office Music
description: Play each track in the Jellyfin playlist exactly once, in a random order
triggers:
  - entity_id: input_boolean.office_music
    from: "off"
    to: "on"
    trigger: state
actions:
  - data:
      playlist_tracks:
        - 3604d8e0cd923c77da086370d80448da
        - 2ba910706f3e898eb0214f3e487aba2a
        - 09ff469b253d296fab97c1d6a8b36b32
        - 55881e9cbc27ad22d1da632949893ee7
        - 747be01ff920790485247851c4106737
        - 3eebd55c187011df63541cc347480445
        - 622ce6fb0abd9ba954069804a43156f1
        - 6ddf349a7d9d990b55fc651316563dcb
        - 22abd5c0ee97eaa92ae3f19cfabd83bd
        - b2b7fba1d51a3391c4eece03be5cd3b7
        - a58b1aab05470e2bdf6006d82badd1d1
        - 6b5803c822b36ce6b3f0e4d8403cb1dc
        - 0d9ababfdbb5632fe3ff321993f65fb4
    action: python_script.shuffle_playlist
  - delay: 1
  - repeat:
      count: "{{ state_attr('sensor.shuffled_playlist', 'tracks') | length }}"
      sequence:
        - target:
            entity_id: media_player.vlc_telnet
          data:
            media_content_id: >-
              {{ 'media-source://jellyfin/' +
              state_attr('sensor.shuffled_playlist', 'tracks')[repeat.index - 1]
              }}
            media_content_type: audio/mp4
          action: media_player.play_media

I also had to create a python script to create the shuffle part.

# shuffle_playlist.py

# Retrieve the list of tracks from the data
playlist_tracks = data.get("playlist_tracks", [])

# Fetch a random-like integer from the helper sensor, with a fallback
helper_random_state = hass.states.get("input_number.helper_random")
random_seed = 0  # Default to 0 if the sensor state is None or invalid

# Check if the helper_random_state is valid and has a usable state
if helper_random_state and helper_random_state.state not in (None, "unknown"):
    try:
        random_seed = int(float(helper_random_state.state))
    except ValueError:
        random_seed = 0  # Use 0 if conversion fails

# Manual shuffle algorithm (Fisher-Yates shuffle) using the seed
for i in range(len(playlist_tracks) - 1, 0, -1):
    j = random_seed % (i + 1)  # Generate an index based on the fallback or actual state

    # Swap positions of tracks
    playlist_tracks[i], playlist_tracks[j] = playlist_tracks[j], playlist_tracks[i]

# Set the state of sensor.shuffled_playlist with the shuffled tracks
hass.states.set("sensor.shuffled_playlist", "shuffled", {
    "tracks": playlist_tracks
})

And an Input Helper Random number generator

  • Set up an input helper (like an input_number) in Settings > Devices & Services > Helpers and name it helper_random.
  • Create an automation to update helper_random with random values using the random function which could not be accessed.
alias: Update Random Sensor
trigger:
  - platform: time_pattern
    minutes: "/5"  # Update every 5 minutes
action:
  - service: input_number.set_value
    target:
      entity_id: input_number.helper_random
    data:
      value: "{{ range(0, 1000) | random }}"  # Generates a random number from 0 to 999

I didn’t do this off the top of my head I had the very able GPT Home Assistant as a helper, the full chat is here: https://chatgpt.com/share/671fe257-5748-8000-b08e-bb20be7c1f59

Why is this essential feature so hard?
I mean, what else would you use the jellyfin integration for?
What is the missing part?

Is jellyfin not providing the Streaming URL for Playlists?
Can the HA player not handle the information?

I have raised this issue here!

Could you vote on it?

I can really recommend Music Assistant for this. I have a button on my dashboard that’s plays a Playlist (in my case from YouTube music) on a media player via MA. A jellyfinn integration is available there as well.

YouTube Music is working for you in MA? I tried the cookie method, would work for a while and then stop. Any advise on getting this working would be great! I’ve done the cookie thing before, is there a way to keep it working? Seems like it only lasted a day or two.

Thanks for any help.

Thanks

For me it works quite a while. It seems to be dependent on usage. If I don’t use MA for some days, I need to re-authenticate via a new cookie. Unfortunately, due to a missing API from YT Music, this is currently the only way.