I’ve been struggling getting my voice assistants to working properly with Music Assistant for a while. There us an LLM script floating around the kind of worked, but I had to mess around a lot with the prompt and even after a lot of tweaking the results were very inconsistent. Partly this was due to there being too many parameters that were just too complicated for the LLM to correctly assign (in fact I struggled to do it manually just to test it).
After a lot of messing around, I’ve come up with a much simpler script that I have almost 100% success rate with.
alias: LLM Universal Music Player
description: Plays any music request and explicitly sets shuffle mode
fields:
query:
description: Artist, song, album, or playlist name
example: Pulp
area_name:
description: The area where the music should play
example: Kitchen
shuffle:
description: True to shuffle, False to play in order. Defaults to false
example: false
sequence:
- variables:
target_area: "{{ area_name | area_id }}"
- sequence:
- action: media_player.shuffle_set
target:
area_id: "{{ target_area }}"
data:
shuffle: "{{ bool(shuffle, false) }}"
- action: music_assistant.play_media
target:
area_id: "{{ target_area }}"
data:
media_id: "{{ query }}"
enqueue: replace
mode: single
In my system prompt (Ollama integration) I also have the following:
## Playing music
To play music use this tool: llm_universal_music_player.
If I ask for a specific area, pass in that area, otherwise pass in the area that you are located in. Pass in the name of the area using the area_name parameter.
For the query parameter, put either the Song Name, Artist Name, Album Name or Playlist Name. If I just ask to play some music with no other requirements, set the query to "500 Random Tracks" and pass in shuffle=true.
If I specifically ask you to shuffle, set that field to true, otherwise leave it as false.
## Stopping Music
There is no way to "stop" the music per se. Instead, if I ask you stop the music, pause it. You can still tell me you stopped the music, because the effect is the same.
The reasons that this works better:
- No complicated entity IDs. It just uses the area which is much simpler
- No media type - it doesn’t get confused and pass in album when it should be a track etc.
I spent a long time messing with this and hopefully this can save someone some time!
Edits:
- changed from “slugify” to “area_id” when converting from area name to id