Add get_queue action for Sonos (#34459)

* initial commit

* add raw

* add trailing pipe

* tiny tweak

---------

Co-authored-by: c0ffeeca7 <38767475+c0ffeeca7@users.noreply.github.com>
This commit is contained in:
Pete Sage 2024-08-28 10:19:59 -04:00 committed by GitHub
parent 54d292841d
commit 5ce443e82c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -342,6 +342,47 @@ Force start playing the queue, allows switching from another stream (such as rad
| `entity_id` | yes | String or list of `entity_id`s that will start playing. It must be the coordinator if targeting a group.
| `queue_position` | yes | Position of the song in the queue to start playing from, starts at 0.
### Action `sonos.get_queue`
Returns the media_players queue.
| Data attribute | Optional | Description |
| ---------------------- | -------- | ----------- |
| `entity_id` | no | media_player entity id. |
This example script does the following: get the queue, loop through in reverse order, and remove media containing the words "holiday".
{% raw %}
```yaml
- action: sonos.get_queue
target:
entity_id: media_player.living_room
response_variable: queue
- variables:
queue_len: '{{ queue["media_player.living_room"] | length }}'
- repeat:
sequence:
- variables:
title: '{{ queue["media_player.living_room"][queue_len - repeat.index]["media_title"].lower() }}'
album: '{{ queue["media_player.living_room"][queue_len - repeat.index]["media_album_name"].lower() }}'
position: '{{ queue_len - repeat.index }}'
- if:
- '{{ "holiday" in title or "holiday" in album }}'
then:
- action: sonos.remove_from_queue
target:
entity_id: media_player.living_room
data:
queue_position: '{{position}}'
until:
- condition: template
value_template: '{{queue_len == repeat.index}}'
```
{% endraw %}
### Action `sonos.remove_from_queue`
Removes an item from the queue.