Trying to use voice assist to play music from Sonos libary

So i was trying to play music from my jellyfin library but after reading about https://community.home-assistant.io/t/play-plex-media-on-your-media-player-using-assist-voice-command/598912
i thought not possible but just changing plex// to jellyfin// (oh life is never that simple)

So i have adapted the blueprint a bit to the below to try and get music playback working. I’m sure People have better ideas or working solutions that this, but can’t find any.

Any help getting this better, or able to search “track” by “artist” rather than just “track” and hoping its the first in list.

blueprint:
  name: Play Sonos media using Assist
  description: >
    Play any Sonos media on a media player of your choice.
    The media player has to support this action.
  domain: automation
  input:
    media_player:
      name: Media player
      description: Media player on which to start Sonos playback
      selector:
        entity:
          domain: media_player
    media_player_friendly_name:
      name: Media player friendly name.
      description: The name of the media player you want the automation to trigger on. E.g. 'bedroom TV'
      default: Dave
    search_1st_library_name:
      name: 1st search library
      description: The libary to search for a match first
      default: ALBUMARTIST
    search_2nd_library_name:
      name: 2nd search library
      description: The libary to search for a match second
      default: ALBUM
    search_3rd_library_name:
      name: 3rd search library
      description: The libary to search for a match third
      default: TRACK

mode: restart
max_exceeded: silent

variables:
  target_media_player: !input media_player
  target_search_1st_library_name: !input search_1st_library_name
  target_search_2st_library_name: !input search_2nd_library_name
  target_search_3rd_library_name: !input search_3rd_library_name

trigger:
  - platform: conversation
    command:
      - Play {sonos_media_name} on {media_player_assist_name}

action:
  - alias: "Check if friendly media player name is used"
    condition: template
    value_template: "{{ media_player_friendly_name == media_player_assist_name}}"
  - service: media_player.play_media
    continue_on_error: true
    target:
      entity_id: !input media_player
    data:
      media_content_type: artist
      media_content_id: 'A:ALBUMARTIST/{{ trigger.slots.sonos_media_name}}'
  - wait_template: "{{ is_state(target_media_player, 'playing') }}"
    timeout: "00:00:04"
    continue_on_timeout: true
  - if:
      - "{{ not wait.completed }}"
    then:
      - service: media_player.play_media
        continue_on_error: true
        target:
          entity_id: !input media_player
        data:
          media_content_type: album
          media_content_id: 'A:ALBUM/{{ trigger.slots.sonos_media_name}}'
  - wait_template: "{{ is_state(target_media_player, 'playing') }}"
    timeout: "00:00:04"
    continue_on_timeout: true
  - if:
      - "{{ not wait.completed }}"
    then:
      - service: media_player.play_media
        continue_on_error: true
        target:
          entity_id: !input media_player
        data:
          media_content_type: track
          media_content_id: 'A:TRACKS/{{ trigger.slots.sonos_media_name}}'

So for anyone stumbling on to this. I made the following automation which works well enough for now. I want to maybe do some fuzzy matching in nodered, or wait for music assistant to have a search search function.

- alias: 'Play Album Artist Player'
  initial_state: 'false'
  trigger:
    - platform: conversation
      command:
        - Play {album_name} by {artist_name} on {media_player_name}
  action:
    - service: media_player.play_media
      continue_on_error: true
      target:
        entity_id: {{ trigger.slots.media_player_name }}
      data:
        media_content_type: album
        media_content_id: 'A:ALBUM/{{ trigger.slots.sonos_album_name }}'
    - wait_template: "{{ is_state(target_media_player, 'playing') }}"
      timeout: "00:00:02"
      continue_on_timeout: true
    - if:
        - "{{ not wait.completed }}"
      then:
        - service: media_player.play_media
          continue_on_error: true
          target:
            entity_id: {{ trigger.slots.media_player_name }}
          data:
            media_content_type: artist
            media_content_id: 'A:ALBUMARTIST/{{ trigger.slots.sonos_artist_name }}'
    - wait_template: "{{ is_state(target_media_player, 'playing') }}"
      timeout: "00:00:02"
      continue_on_timeout: true
    - if:
        - "{{ not wait.completed }}"
      then:
        - service: media_player.play_media
          continue_on_error: true
          target:
            entity_id: {{ trigger.solts.media_player_name }}
          data:
            media_content_type: title
            media_content_id: 'A:TRACKS/{{ trigger.slots.sonos_track_name }}'
    - wait_template: "{{ is_state(target_media_player, 'playing') }}"
      timeout: "00:00:02"
      continue_on_timeout: true
    - if:
        - "{{ not wait.completed }}"
      then:
        - service: tts.marytts_say
          data_template:
            entity_id: !input media_player
            message: "I'm sorry, I could not find {{ trigger.slots.sonos_album_name }} by {{trigger.slots.sonos_artist_name}} to play"