Get library items

Use this action to retrieve items from your Music Assistant library. It gives you programmatic access to concise information about your library items, which you can use to build a queue of tracks for playback.

This action returns its result in a response variable, which you can use in later steps of the same automation or script. It does not change anything on a player.

Using this action from the user interface

If you prefer building automations and scripts visually, Home Assistant walks you through this action step by step. You pick what to target, tweak a few options, and save. No YAML knowledge required.

To get library items from an automation or a script:

  1. Go to Settings > Automations & scenes.
  2. Open an existing automation or script, or select Create automation > Create new automation.
  3. If you’re setting up a new automation, add a trigger in the When section. Scripts don’t need a trigger. They run when something else calls them.
  4. In the Then do section, select Add action.
  5. From the search box, search for and select Music Assistant: Get library items.
  6. Fill in the options you want to use.
  7. In the Response variable field, enter a name to store the data in, such as library_items.
  8. Select Save.

This action does not support targets. In the UI, you are not prompted to choose an area, device, entity, or label. You select the Music Assistant instance through the Music Assistant instance option instead.

Options in the UI

Music Assistant instance

The Music Assistant instance to retrieve the items from.

Media type

The media type to request the items for.

Favorites only

Only return items that are marked as favorites.

Search

An optional search string to filter the library items.

Limit

The maximum number of items to return.

Offset

The point in the list to start returning items from.

Order by

The field to sort the list by.

Album type filter (albums library only)

When the media type is album, restrict the results to these album types.

Enable album artists filter (only for artist library)

When the media type is artist, only return album artists.

Using this action in YAML

If you work directly in YAML, or you want to know exactly what Home Assistant does under the hood, this section has the technical reference. It lists the field names you use in YAML, their types, and which ones are required.

In YAML, refer to this action as music_assistant.get_library. A basic example looks like this:

ActionActions are used in several places in Home Assistant. As part of a script or automation, actions define what is going to happen once a trigger is activated. In scripts, an action is called *sequence*. [Learn more]
action: music_assistant.get_library
data:
  config_entry_id: 01JEXNDHT21V0BHJXM7A5SZANV
  media_type: track
response_variable: library_items

Options in YAML

config_entry_id string Required

The ID of the Music Assistant instance to retrieve the items from. Select the instance from the dropdown in the visual editor, then switch to YAML to read the value.

media_type string Required

The media type to request the items for. One of: artist, album, audiobook, playlist, podcast, track, or radio.

favorite boolean

Only return items that are marked as favorites.

search string

An optional search string to filter the library items.

limit integer

The maximum number of items to return.

offset integer

The point in the list to start returning items from.

order_by string

The field to sort the list by, such as name, year, or random.

album_type string | list

When the media type is album, restrict the results to these album types. One or more of: album, single, compilation, ep, or unknown.

album_artists_only boolean

When the media type is artist, only return album artists.

Response data

The action returns an items list with the matching library items, along with the limit, offset, order_by, and media_type you requested. Each item includes details such as its name and URI, which you can pass to the Play media action.

This example starts playback of ten random tracks:

ScriptScripts are components that allow you to specify a sequence of actions to be executed by Home Assistant when turned on. [Learn more]
sequence:
  - action: music_assistant.get_library
    data:
      config_entry_id: 01JEXNDHT21V0BHJXM7A5SZANV
      media_type: track
      limit: 10
      order_by: random
    response_variable: random_tracks
  - action: music_assistant.play_media
    target:
      entity_id: media_player.kitchen_speaker
    data:
      media_id: "{{ random_tracks['items'] | map(attribute='uri') | list }}"
      media_type: track
      enqueue: replace

Still stuck?

The Home Assistant community is quick to help: join Discord for real-time chat, post on the community forum with the action you’re calling and what you expected to happen, or share on our subreddit /r/homeassistant.

Tip

AI assistants like ChatGPT or Claude can also explain actions or suggest the right one when you describe what you want in plain language.

Related actions

These actions work well alongside this one:

  • Search Music Assistant: Performs a global search on the Music Assistant library and all providers.

  • Play media: Plays media on a Music Assistant player with fine-grained control options.