-
Notifications
You must be signed in to change notification settings - Fork 0
/
music_assistant_blueprint.yaml
192 lines (167 loc) · 7.03 KB
/
music_assistant_blueprint.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
blueprint:
domain: automation
name: Music Assistant - Voice (Official)
source_url: https://github.com/music-assistant/blueprints/blob/main/music_assistant_blueprint.yaml
description: '
![Image](https://github.com/music-assistant/blueprints/blob/main/assets/music-assistant.png?raw=true)
# Play media using voice commands
### Usage
All sentences must:
* start with the words `Play` or `Listen to` followed by the item type `artist/track/album/playlist/radio station` and then the name of the item
* for album and track be optionally followed by `by (the) artist` and then the artist name
* then be optionally followed by an area name or device name
* then, for artist, track, album or playlist, be optionally followed by the phrase `using radio mode`
#### Acceptable variations
There are acceptable variations to some words and inclusion of the word `the` is optional.
#### Examples
```
Play the artist Pink Floyd in the kitchen
Listen to album Jagged Little Pill in the study
Listen to the album Greatest Hits by the artist James Taylor in the kitchen
Play track New Years Day in the bedroom
Play track New Years Day in the bedroom using radio mode
Play the song A Hard Days Night by Billy Joel in the bedroom
Listen to the playlist Classic Rock in the study
Listen to the radio station BBC Radio 1 in the bedroom
Play the album Classical Nights on the Bedroom Sonos Speaker
Listen to the record Classical Nights on the Bedroom Sonos Speaker
Play the band U2
```
'
input:
default_player_entity_id_input:
name: Default Media Player
selector:
entity:
filter:
integration: music_assistant
domain: media_player
triggers:
- trigger: conversation
command:
- "(play|listen to) [the ](album|ep|record|compilation|single) {media_name} [by [the ](artist|band|group) {artist}] (in|on|using) [the ]{area_or_player_name}[ (with|using) {radio_mode}]"
id: album
- trigger: conversation
command:
- "(play|listen to) [the ](track|song) {media_name} [by [the ](artist|band|group) {artist}] (in|on|using) [the ]{area_or_player_name}[ (with|using) {radio_mode}]"
id: track
- trigger: conversation
command:
- "(play|listen to) [the ](artist|band|group) {media_name} (in|on|using) [the ]{area_or_player_name}[ (with|using) {radio_mode}]"
id: artist
- trigger: conversation
command:
- "(play|listen to) [the ]((radio station)|(radio)|(station)) {media_name} (in|on|using) [the ]{area_or_player_name}"
id: radio
- trigger: conversation
command:
- "(play|listen to) [the ]playlist {media_name} (in|on|using) [the ]{area_or_player_name}[ (with|using) {radio_mode}]"
id: playlist
conditions: []
actions:
- variables:
default_player_entity_id: !input default_player_entity_id_input
trigger_id: "{{ trigger.id }}"
media_name: "{{ trigger.slots.media_name }}"
media_type: |
{% if 'radio' in media_name or 'Radio' in media_name %}
radio
{% else %}
{{ trigger_id }}
{% endif %}
artist: "{{ trigger.slots.artist }}"
area_or_player_name: "{{ trigger.slots.area_or_player_name }}"
assist_device_id: "{{ trigger.device_id }}"
radio_mode_str: "{{ trigger.slots.radio_mode or '' }}"
radio_mode: "{{ 'radio' in radio_mode_str.lower() }}"
player_entity_id_by_player_name: >
{{ expand(integration_entities('music_assistant')) |
selectattr("attributes.mass_player_type", 'defined') |
selectattr("attributes.friendly_name", 'equalto', area_or_player_name) |
join(', ', attribute="entity_id") }}
player_entity_id_by_area_name: >
{{ expand(area_entities(area_or_player_name)) |
selectattr("attributes.mass_player_type", 'defined') |
selectattr("attributes.friendly_name", 'equalto', area_or_player_name) |
join(', ', attribute="entity_id") }}
player_entity_id_by_assist_area: |
{% if assist_device_id and area_id(assist_device_id) %}
{{ expand(area_entities(area_id(assist_device_id))) | selectattr("attributes.mass_player_type", 'defined') | join(', ', attribute="entity_id") }}
{% else %}
None
{% endif %}
mass_player_entity_id: |
{% if player_entity_id_by_player_name %}
{{ player_entity_id_by_player_name }}
{% elif player_entity_id_by_area_name %}
{{ player_entity_id_by_area_name }}
{% elif player_entity_id_by_assist_area %}
{{ player_entity_id_by_assist_area }}
{% else %}
{{ default_player_entity_id }}
{% endif %}
mass_player_name: "{{ state_attr(mass_player_entity_id, 'friendly_name') }}"
- choose:
- conditions:
- condition: template
value_template: "{{ media_type == 'album' }}"
sequence:
- action: music_assistant.play_media
metadata: {}
data:
media_id: "{{ media_name }}"
artist: "{{ artist }}"
media_type: "{{ media_type }}"
radio_mode: "{{ radio_mode }}"
target:
entity_id: "{{ mass_player_entity_id }}"
- conditions:
- condition: template
value_template: "{{ media_type == 'track' }}"
sequence:
- action: music_assistant.play_media
metadata: {}
data:
media_id: "{{ media_name }}"
artist: "{{ artist }}"
media_type: "{{ media_type }}"
radio_mode: "{{ radio_mode }}"
target:
entity_id: "{{ mass_player_entity_id }}"
- conditions:
- condition: template
value_template: "{{ media_type == 'artist' }}"
sequence:
- action: music_assistant.play_media
metadata: {}
data:
media_id: "{{ media_name }}"
media_type: "{{ media_type }}"
radio_mode: "{{ radio_mode }}"
target:
entity_id: "{{ mass_player_entity_id }}"
- conditions:
- condition: template
value_template: "{{ media_type == 'radio' }}"
sequence:
- action: music_assistant.play_media
metadata: {}
data:
media_id: "{{ media_name }}"
media_type: "{{ media_type }}"
target:
entity_id: "{{ mass_player_entity_id }}"
- conditions:
- condition: template
value_template: "{{ media_type == 'playlist' }}"
sequence:
- action: music_assistant.play_media
metadata: {}
data:
media_id: "{{ media_name }}"
media_type: "{{ media_type }}"
radio_mode: "{{ radio_mode }}"
target:
entity_id: "{{ mass_player_entity_id }}"
- set_conversation_response: "{{ trigger.slots.media_name }} playing on {{ mass_player_name }}"
mode: single