From 5ce443e82ca99bc9cc3b12b52ff2de25f1d6929f Mon Sep 17 00:00:00 2001 From: Pete Sage <76050312+PeteRager@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:19:59 -0400 Subject: [PATCH] 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> --- source/_integrations/sonos.markdown | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/source/_integrations/sonos.markdown b/source/_integrations/sonos.markdown index b86a2ff9801..5a5e439eea0 100644 --- a/source/_integrations/sonos.markdown +++ b/source/_integrations/sonos.markdown @@ -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.