Guest User

Untitled

a guest
Nov 14th, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.47 KB | None | 0 0
  1. alias: Play on Music Assistant
  2. sequence:
  3.   - variables:
  4.       v_media_type: |-
  5.         {% if f_track %}
  6.           track
  7.         {% elif f_album %}
  8.           album
  9.         {% elif f_artist %}
  10.           artist
  11.         {% endif %}
  12.       v_search: |-
  13.         {% if f_track %}
  14.           {{ f_track }}
  15.         {% elif f_album %}
  16.           {{ f_album }}
  17.         {% elif f_artist %}
  18.           {{ f_artist }}
  19.         {% endif %}
  20.       v_players: |-
  21.         {{ f_areas|map('area_entities')
  22.         |map('select', 'in', integration_entities('mass'))
  23.         |map('list')|sum(start = []) }}
  24.   - variables:
  25.       result:
  26.         message: |-
  27.           {% if v_players|count > 0 %}
  28.             Playing {{ v_search }} {{ iif(f_radio_mode is defined and f_radio_mode, ' radio', '') }}
  29.           {% else %}
  30.             No suitable players found.
  31.           {% endif %}
  32.   - if:
  33.       - condition: template
  34.         value_template: "{{ v_players|count > 0 }}"
  35.     then:
  36.       - action: mass.search
  37.         metadata: {}
  38.         data:
  39.           limit: 1
  40.           name: "{{ v_search }}"
  41.           artist: "{{ iif(v_search != f_artist, f_artist, '') }}"
  42.           album: "{{ iif(v_search != f_album, f_album, '') }}"
  43.           media_type:
  44.            - "{{ v_media_type }}"
  45.         response_variable: search_result
  46.       - action: mass.play_media
  47.         metadata: {}
  48.         data:
  49.           media_id: "{{ search_result[v_media_type + 's'][0].uri }}"
  50.           media_type: "{{ v_media_type }}"
  51.           radio_mode: "{{ f_radio_mode is defined and f_radio_mode }}"
  52.           artist: "{{ f_artist }}"
  53.           album: "{{ f_album }}"
  54.         target:
  55.           entity_id: "{{ v_players }}"
  56.       - action: media_player.shuffle_set
  57.         metadata: {}
  58.         data:
  59.           shuffle: true
  60.         target:
  61.           entity_id: "{{ v_players }}"
  62.   - stop: Result
  63.     response_variable: result
  64. description: ""
  65. icon: mdi:music
  66. fields:
  67.   f_artist:
  68.     selector:
  69.       text: null
  70.     name: Artist
  71.     required: false
  72.   f_album:
  73.     selector:
  74.       text: null
  75.     name: Album
  76.     required: false
  77.   f_track:
  78.     selector:
  79.       text: null
  80.     name: Track
  81.     required: false
  82.   f_areas:
  83.     selector:
  84.       area:
  85.         entity:
  86.           integration: mass
  87.         multiple: true
  88.     name: Areas
  89.     required: true
  90.   f_radio_mode:
  91.     selector:
  92.       boolean: {}
  93.     default: false
  94.     name: Radio mode
  95.     description: Toggle to play songs inspired by given request.
  96.  
Advertisement
Add Comment
Please, Sign In to add comment