---
title: "Sonos"
description: "Integrazione degli altoparlanti wireless Sonos con TapHome. Controllo del volume, della riproduzione, delle playlist e delle stazioni radio tramite."
url: "https://taphome.com/it/compatibility/sonos/"
language: it
lastmod: 2026-10-08
generator: hugo
ai:
  topics: ["data-pp","audio","wifi","upnp","multi-room"]
  questions: ["Come integrare gli altoparlanti Sonos con TapHome?","Quali controlli di riproduzione offre il template Sonos per TapHome?","Come collegare Sonos tramite HTTP a TapHome?","Come riprodurre una playlist o stazione radio specifica su Sonos tramite TapHome?","Perché il comando play non funziona su un altoparlante Sonos raggruppato?","Come impostare un timer di spegnimento su Sonos tramite TapHome?","Posso usare le playlist Spotify con Sonos in TapHome?","Quali modelli Sonos sono compatibili con TapHome?","Posso raggruppare o separare le zone Sonos da TapHome?"]
---

# Sonos

Comunicazione: Packet Parser → HTTP

- [Pagina prodotto Sonos](https://www.sonos.com)

> Indirizzo di rete
> 
> TapHome raggiunge il dispositivo all'indirizzo inserito durante l'importazione. Assegna al dispositivo un indirizzo fisso — una prenotazione IP nel router, oppure il suo nome mDNS se lo supporta —, altrimenti l'integrazione smette di funzionare quando il router cambia l'indirizzo.
> 
> [Preparazione della rete](https://taphome.com/it/docs/setup/network-preparation/)

## Guida all'integrazione

Sonos è un sistema audio wireless premium progettato per la riproduzione multi-room. TapHome comunica con gli altoparlanti Sonos sulla rete locale tramite UPnP/SOAP sulla porta 1400 — non è necessaria alcuna connessione cloud né autenticazione. Il template è universale e funziona con tutti i modelli di altoparlanti Sonos (Era 100, Era 300, One, Five, Beam, Arc, Ray, Move, Roam, Sub e altri).

Il template offre il controllo completo della riproduzione (play, pausa, stop, salto), gestione del volume e della disattivazione audio, selezione della modalità di riproduzione, timer di spegnimento e fino a 10 pulsanti preimpostati per playlist e stazioni radio. Un set di 14 attributi di servizio espone le informazioni sul dispositivo e il brano attualmente in riproduzione.

## Configurazione

L'altoparlante Sonos si connette tramite Wi-Fi. Durante l'importazione del template TapHome, inserisci l'indirizzo IP dell'altoparlante (segnaposto predefinito `192.168.0.1`). L'altoparlante deve trovarsi sulla stessa rete della TapHome CCU.

> [!TIP]
> Gli altoparlanti Sonos supportano il **discovery mDNS** con il pattern hostname `Sonos-{MAC}.local` (indirizzo MAC senza due punti). L'utilizzo di un hostname previene problemi di connettività quando l'indirizzo IP dell'altoparlante cambia dopo un rinnovo DHCP.

Apri l'app TapHome e usa l'**IP Scanner** (Impostazioni → Rete → Scansione). Lo scanner rileverà i dispositivi sulla tua rete e mostrerà sia l'indirizzo IP che l'hostname mDNS (es. `Sonos-B8E9375A1C02.local`). Usa l'hostname al posto dell'indirizzo IP per una connessione più affidabile.

## Funzionalità del dispositivo

### Controllo del volume

Il template espone il volume come dispositivo dimmer. Il volume viene letto tramite l'azione SOAP RenderingControl `GetVolume` (intervallo 0–100) e diviso per 100 per produrre il valore dimmer 0,0–1,0. La scrittura di un nuovo volume invia `SetVolume` con il livello desiderato. Il volume viene interrogato ogni 2,5 secondi.

Due PushButton aggiuntivi — **Volume Up** e **Volume Down** — consentono la regolazione relativa del volume. Questi sono gestiti dalla logica lato CCU anziché da azioni SOAP dirette, permettendo l'integrazione con interruttori a parete fisici o smart rule.

### Disattivazione audio

La disattivazione audio è esposta come interruttore. Lo stato viene letto tramite `GetMute` e scritto tramite `SetMute` sul canale Master. Quando la disattivazione è attiva, l'uscita audio viene silenziata senza modificare il livello del volume.

### Controllo della riproduzione

Sei PushButton controllano il trasporto della riproduzione:

- **Play** — invia AVTransport `Play` (Speed=1)
- **Pause** — invia AVTransport `Pause`
- **Stop** — invia AVTransport `Stop`
- **Next** — invia AVTransport `Next` per passare al brano successivo
- **Previous** — invia AVTransport `Previous` per tornare al brano precedente
- **Play/Pause** — alterna tra play e pausa in base allo stato di trasporto corrente (gestito dalla logica lato CCU)

### Stato della riproduzione

Un sensore binario in sola lettura indica se l'altoparlante sta attualmente riproducendo. Il template legge `GetTransportInfo` e mappa gli stati di trasporto: `PLAYING` e `TRANSITIONING` vengono mappati a 1 (in riproduzione), mentre `STOPPED`, `NO_MEDIA_PRESENT` e `PAUSED_PLAYBACK` vengono mappati a 0 (non in riproduzione). Interrogazione ogni 2,5 secondi.

### Modalità di riproduzione

La modalità di riproduzione è un interruttore multi-valore con sei modalità:

| Valore | Modalità | Descrizione |
|--------|----------|-------------|
| 0 | Normal | Riproduzione sequenziale |
| 1 | Repeat All | Ripetizione dell'intera coda |
| 2 | Repeat One | Ripetizione del brano corrente |
| 3 | Shuffle No Repeat | Riproduzione casuale senza ripetizione |
| 4 | Shuffle | Riproduzione casuale con ripetizione |
| 5 | Shuffle Repeat One | Riproduzione casuale, ripetizione del brano corrente |

I valori 6–9 sono slot di riempimento non utilizzati nella configurazione dell'interruttore multi-valore e non hanno alcuna funzione.

### Timer di spegnimento

Due PushButton configurano i timer di spegnimento tramite l'azione SOAP AVTransport `ConfigureSleepTimer`:

- **Sleep Timer (1 hour)** — imposta il timer a `01:00:00`
- **Sleep Timer (15 min)** — imposta il timer a `00:15:00`

Allo scadere del timer, l'altoparlante interrompe automaticamente la riproduzione.

### Preset playlist e radio

Il template fornisce 10 PushButton preimpostati — 5 per playlist e 5 per stazioni radio. Ogni pulsante ha una **variabile dispositivo** che l'utente deve configurare con il nome della playlist o della stazione desiderata. Lo script gestisce automaticamente la ricerca, la gestione della coda e la riproduzione.

**Playlist (pulsanti 1–5):** Ogni pulsante playlist utilizza una variabile dispositivo `playlist_name`. Lo script cerca nelle **playlist Sonos** (Code salvate) tramite il contenitore ContentDirectory `SQ:`, con corrispondenza esatta del `dc:title` (sensibile alle maiuscole). Quando viene trovata una corrispondenza, lo script svuota la coda corrente, accoda la playlist e avvia la riproduzione.

Per configurare un pulsante playlist:

1. Apri l'app TapHome → vai al dispositivo playlist → **Variabili dispositivo**
2. Imposta `playlist_name` sul nome esatto di una playlist Sonos
3. Per creare una playlist Sonos: app Sonos → accoda brani → **Salva coda come playlist**

> [!WARNING]
> Sono supportate solo le **playlist Sonos** (Code salvate). Una playlist Sonos può contenere brani della maggior parte dei servizi di streaming — Apple Music, Tidal, Amazon Music, YouTube Music, Deezer e altri. **Spotify è l'eccezione** — Spotify utilizza un percorso di integrazione proprietario e i suoi brani non possono essere aggiunti alle Code salvate Sonos. Per creare una playlist Sonos: apri l'app Sonos, accoda i brani desiderati e salva la coda come playlist.

**Stazioni radio (pulsanti 1–5):** Ogni pulsante radio utilizza una variabile dispositivo `radio_name`. Lo script cerca nei **Sonos Favorites** tramite il contenitore ContentDirectory `FV:2`, con corrispondenza esatta del `dc:title` (sensibile alle maiuscole) e filtraggio per il protocollo radio streaming (`x-sonosapi-stream`).

Per configurare un pulsante radio:

1. Apri l'app TapHome → vai al dispositivo radio → **Variabili dispositivo**
2. Imposta `radio_name` sul nome esatto della stazione come appare nei Sonos Favorites
3. Per aggiungere una stazione ai Favorites: app Sonos → sfoglia TuneIn o iHeartRadio → tocca l'icona cuore/stella

> [!TIP]
> Il nome deve corrispondere esattamente (sensibile alle maiuscole). Apri l'app Sonos, vai su **My Sonos → Favorites** e copia il nome della stazione carattere per carattere. Sono supportate solo le stazioni radio in streaming — i contenuti audio on-demand dai Favorites non funzioneranno.

### Diagnostica di servizio

Il template espone 14 attributi di servizio dall'XML di descrizione del dispositivo (`/xml/device_description.xml`):

- **Info dispositivo** — nome modello, URL modello, numero di serie, indirizzo MAC, hostname, UDN (Unique Device Name)
- **Software** — versione software, generazione software, revisione hardware, versione API, versione API minima
- **Configurazione Sonos** — nome stanza, nome visualizzato
- **In riproduzione** — brano corrente (titolo, artista, album estratti dai metadati DIDL-Lite tramite `GetPositionInfo`)

L'attributo del brano corrente decodifica i TrackMetaData codificati in XML e restituisce una stringa multi-riga con titolo, artista e informazioni sull'album. Se i metadati non sono disponibili (es. ingresso line-in), restituisce "Not supported".

### Limitazioni

Il template controlla **un solo altoparlante** alla volta. Il raggruppamento e la separazione delle zone multi-room non è supportato — utilizzare l'app Sonos per gestire i gruppi. Se l'altoparlante fa parte di un gruppo, il template deve puntare al **coordinatore del gruppo** (vedere Risoluzione dei problemi di seguito).

### Funzionalità aggiuntive

L'API UPnP di Sonos espone 16 servizi con funzionalità oltre l'implementazione corrente del template. Il servizio RenderingControl supporta regolazioni di bassi, alti e loudness, nonché la modalità notturna sui modelli soundbar. Il servizio AVTransport offre controllo crossfade, ricerca per tempo o numero di brano e gestione completa della coda (aggiunta, rimozione, riordinamento dei brani). Sono disponibili anche pianificazione delle sveglie e impostazioni dell'equalizzatore per configurazioni surround/subwoofer. I modelli portatili (Move, Roam) mostrano lo stato della batteria. Queste funzionalità possono essere aggiunte in un futuro aggiornamento del template.

> [!NOTE]
> Sonos sta gradualmente passando dall'API UPnP/SOAP (porta 1400) a una nuova API REST locale. All'inizio del 2026, UPnP rimane pienamente funzionante su tutti i modelli, inclusi Era 100, Era 300 e Arc Ultra. Se Sonos dovesse limitare UPnP in un futuro aggiornamento del firmware, il template dovrà essere aggiornato alla nuova API.

## Risoluzione dei problemi

### L'altoparlante non risponde

1. Verifica che l'altoparlante Sonos sia acceso e connesso al Wi-Fi
2. Prova a usare l'hostname mDNS (`Sonos-{MAC}.local`) al posto dell'indirizzo IP — l'IP potrebbe essere cambiato dopo un rinnovo DHCP
3. Apri `http://{speaker-ip}:1400/xml/device_description.xml` in un browser — se risponde con XML, l'altoparlante è raggiungibile
4. Verifica che la TapHome CCU e l'altoparlante Sonos siano sulla stessa rete / VLAN

### I comandi di riproduzione falliscono con errore 800

I gruppi multi-room Sonos instradano tutti i comandi di riproduzione attraverso il **coordinatore del gruppo**. Se il template punta a un altoparlante che non è il coordinatore, i comandi di trasporto (Play, Pause, Next, Previous) falliranno. Assicurati che l'indirizzo IP in TapHome punti al coordinatore del gruppo, oppure rimuovi l'altoparlante dal gruppo per renderlo un dispositivo indipendente.

### Le modifiche del volume non si riflettono

1. Conferma che il template stia interrogando — il volume viene letto ogni 2,5 secondi tramite `GetVolume`
2. Se un altro controller (app Sonos, Apple AirPlay) ha modificato il volume, TapHome rileverà il nuovo valore al prossimo ciclo di interrogazione
3. Verifica che l'altoparlante non sia in un gruppo dove il volume è controllato dal coordinatore del gruppo

> [!WARNING]
> Gli altoparlanti Sonos accettano comandi UPnP solo da dispositivi sulla **stessa sottorete**. Se la TapHome CCU si trova su una VLAN diversa, assicurati che il traffico multicast/UPnP sia instradato tra le VLAN, oppure posiziona entrambi i dispositivi sullo stesso segmento di rete.

## Dispositivi disponibili 24

Questi dispositivi compaiono in TapHome dopo l'importazione.

Sonos Modulo

Attributi di servizio

|                     |
|---------------------|
| Nome modello        |
| URL modello         |
| Versione SW         |
| Generazione SW      |
| Revisione HW        |
| Numero di serie     |
| Indirizzo MAC       |
| Nome host           |
| UDN                 |
| Versione API        |
| Versione API minima |
| Nome stanza         |
| Nome visualizzato   |
| Brano corrente      |

Variabili personalizzate

|                              |
|------------------------------|
| `deviceDescription` (string) |

Attributi di servizio

Model name

```taphome
VAR response := SENDHTTPREQUEST("/xml/device_description.xml");
deviceDescription := response.Content;

PARSEXML(deviceDescription, "//root:modelName[1]");
```

Model url

```taphome
PARSEXML(deviceDescription, "//root:modelURL[1]");
```

SW version

```taphome
PARSEXML(deviceDescription, "//root:softwareVersion[1]");
```

SW generation

```taphome
PARSEXML(deviceDescription, "//root:swGen[1]");
```

HW revision

```taphome
PARSEXML(deviceDescription, "//root:hardwareVersion[1]");
```

Serial number

```taphome
PARSEXML(deviceDescription, "//root:serialNum[1]");
```

Mac address

```taphome
PARSEXML(deviceDescription, "//root:MACAddress[1]");
```

Host name

```taphome
VAR macAddress := PARSEXML(deviceDescription, "//root:MACAddress[1]");
"Sonos-" + REPLACE(macAddress, ":", "") + ".local"
```

UDN

```taphome
PARSEXML(deviceDescription, "//root:UDN[1]");
```

API version

```taphome
PARSEXML(deviceDescription, "//root:apiVersion[1]");
```

Min API version

```taphome
PARSEXML(deviceDescription, "//root:minApiVersion[1]");
```

Room name

```taphome
PARSEXML(deviceDescription, "//root:roomName[1]");
```

Display name

```taphome
PARSEXML(deviceDescription, "//root:displayName[1]");
```

Current track

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#GetPositionInfo\"";
VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:GetPositionInfo xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:GetPositionInfo></s:Body></s:Envelope>";

VAR response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);

IF response.IsSuccess
    VAR responseXml := response.Content;
    VAR metaData := DECODE(PARSETEXT(responseXml, "<TrackMetaData>", "</TrackMetaData>"), "xml");
    
    IF(metaData = "NOT_IMPLEMENTED")
        RETURN("Not supported");
    END

    IF(LENGTH(metaData) = 0)
        RETURN("");
    END

    VAR title := PARSEXML(metaData, "//dc:title");
    VAR artist := PARSEXML(metaData, "//dc:creator");
    VAR album := PARSEXML(metaData, "//upnp:album");
    
    VAR result := "";
    
    IF(LENGTH(title) > 0)
        result := "Title: " + title + "\n";
    END
    
    IF(LENGTH(artist) > 0)
         result := result + "Artist: " + artist + "\n";
    END
    
    IF(LENGTH(album) > 0)
        result := result + "Album: " + album;
    END

    RETURN(result);
ELSE
    RETURN("Error");
END
```

Volume Dimmer Lettura e scrittura

numeric Unità: %

Lettura livello

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:RenderingControl:1#GetVolume\"";
VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:GetVolume xmlns:u=\"urn:schemas-upnp-org:service:RenderingControl:1\"><InstanceID>0</InstanceID><Channel>Master</Channel></u:GetVolume></s:Body></s:Envelope>";

VAR response := SENDHTTPREQUEST("MediaRenderer/RenderingControl/Control", "POST", body, header);

IF response.IsSuccess
    VAR responseXml := response.Content;
    RETURN(PARSEXML(responseXml, "//CurrentVolume") / 100.0);
ELSE
    ADDERROR(response.Content);
    RETURN(NaN);
END
```

Scrittura livello

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:RenderingControl:1#SetVolume\"";
VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:SetVolume xmlns:u=\"urn:schemas-upnp-org:service:RenderingControl:1\"><InstanceID>0</InstanceID><Channel>Master</Channel><DesiredVolume>" + ROUND(Le*100) + "</DesiredVolume></u:SetVolume></s:Body></s:Envelope>";

SENDHTTPREQUEST("MediaRenderer/RenderingControl/Control", "POST", body, header);
```

Brano successivo Pulsante Lettura e scrittura

action

Scrittura stato pulsante

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Next\"";
VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Next xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:Next></s:Body></s:Envelope>";

SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
```

Pausa Pulsante Lettura e scrittura

action

Scrittura stato pulsante

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Pause\"";
VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Pause xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:Pause></s:Body></s:Envelope>";

SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
```

Play Pulsante Lettura e scrittura

action

Scrittura stato pulsante

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Play\"";
VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>";

SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
```

Brano precedente Pulsante Lettura e scrittura

action

Scrittura stato pulsante

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Previous\"";
VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Previous xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:Previous></s:Body></s:Envelope>";

SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
```

Stop Pulsante Lettura e scrittura

action

Scrittura stato pulsante

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Stop\"";
VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Stop xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:Stop></s:Body></s:Envelope>";

SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
```

Volume su Pulsante Lettura e scrittura

action

Scrittura stato pulsante

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:RenderingControl:1#SetRelativeVolume\"";

VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:SetRelativeVolume xmlns:u=\"urn:schemas-upnp-org:service:RenderingControl:1\"><InstanceID>0</InstanceID><Channel>Master</Channel><Adjustment>5</Adjustment></u:SetRelativeVolume></s:Body></s:Envelope>";

SENDHTTPREQUEST("MediaRenderer/RenderingControl/Control", "POST", body, header);
```

Volume giù Pulsante Lettura e scrittura

action

Scrittura stato pulsante

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:RenderingControl:1#SetRelativeVolume\"";

VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:SetRelativeVolume xmlns:u=\"urn:schemas-upnp-org:service:RenderingControl:1\"><InstanceID>0</InstanceID><Channel>Master</Channel><Adjustment>-5</Adjustment></u:SetRelativeVolume></s:Body></s:Envelope>";

SENDHTTPREQUEST("MediaRenderer/RenderingControl/Control", "POST", body, header);
```

Muto Interruttore Lettura e scrittura

boolean

Valori / Stati: ON · OFF

Lettura stato interruttore

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:RenderingControl:1#GetMute\"";
VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:GetMute xmlns:u=\"urn:schemas-upnp-org:service:RenderingControl:1\"><InstanceID>0</InstanceID><Channel>Master</Channel></u:GetMute></s:Body></s:Envelope>";

VAR response := SENDHTTPREQUEST("MediaRenderer/RenderingControl/Control", "POST", body, header);

IF response.IsSuccess
    VAR responseXml := response.Content;
    RETURN(PARSEXML(responseXml, "//CurrentMute"));
ELSE
    ADDERROR(response.Content);
    RETURN(NaN);
END
```

Scrittura stato interruttore

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:RenderingControl:1#SetMute\"";
VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:SetMute xmlns:u=\"urn:schemas-upnp-org:service:RenderingControl:1\"><InstanceID>0</InstanceID><Channel>Master</Channel><DesiredMute>" + St + "</DesiredMute></u:SetMute></s:Body></s:Envelope>";

SENDHTTPREQUEST("MediaRenderer/RenderingControl/Control", "POST", body, header);
```

Modalità di riproduzione Interruttore multivalore Lettura e scrittura

enum mapped

Valori / Stati: Normal · Repeat all · Repeat one · Shuffle no repeat · Shuffle · Shuffle repeat one

Lettura stato interruttore

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#GetTransportSettings\"";
VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:GetTransportSettings xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:GetTransportSettings></s:Body></s:Envelope>";

VAR response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);

IF response.IsSuccess
    VAR responseXml := response.Content;
    VAR mode := PARSEXML(responseXml, "//PlayMode");
    RETURN(SWITCH(mode , "NORMAL", 0, "REPEAT_ALL", 1, "REPEAT_ONE", 2, "SHUFFLE_NOREPEAT", 3, "SHUFFLE", 4, "SHUFFLE_REPEAT_ONE", 5, -1));
ELSE
    ADDERROR(response.Content);
    RETURN(NaN);
END
```

Scrittura stato interruttore

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#SetPlayMode\"";

VAR mode := SWITCH(Mu, 0, "NORMAL", 1, "REPEAT_ALL", 2, "REPEAT_ONE", 3, "SHUFFLE_NOREPEAT", 4, "SHUFFLE", 5, "SHUFFLE_REPEAT_ONE", "NORMAL");

VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:SetPlayMode xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><NewPlayMode>" + mode +"</NewPlayMode></u:SetPlayMode></s:Body></s:Envelope>";

VAR response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
```

Timer spegnimento (1 ora) Pulsante Lettura e scrittura

action

Scrittura stato pulsante

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#ConfigureSleepTimer\"";

VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:ConfigureSleepTimer xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><NewSleepTimerDuration>01:00:00</NewSleepTimerDuration></u:ConfigureSleepTimer></s:Body></s:Envelope>";

SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
```

Timer spegnimento (15 min) Pulsante Lettura e scrittura

action

Scrittura stato pulsante

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#ConfigureSleepTimer\"";

VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:ConfigureSleepTimer xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><NewSleepTimerDuration>00:15:00</NewSleepTimerDuration></u:ConfigureSleepTimer></s:Body></s:Envelope>";

SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
```

Stato riproduzione Contatto reed Solo lettura

boolean mapped

Lettura

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#GetTransportInfo\"";
VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:GetTransportInfo xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:GetTransportInfo></s:Body></s:Envelope>";

VAR response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);

IF response.IsSuccess
    VAR responseXml := response.Content;
    VAR state := PARSEXML(responseXml, "//CurrentTransportState");
    RETURN(SWITCH(state , "PLAYING", 1, "TRANSITIONING", 1, "STOPPED", 0, "NO_MEDIA_PRESENT", 0, "PAUSED_PLAYBACK", 0, 0));
ELSE
    ADDERROR(response.Content);
    RETURN(NaN);
END
```

Play/Pausa Pulsante Lettura e scrittura

action

Scrittura stato pulsante

```taphome
VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#GetTransportInfo\"";
VAR body := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:GetTransportInfo xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:GetTransportInfo></s:Body></s:Envelope>";

VAR response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);

IF response.IsSuccess
    VAR responseXml := response.Content;
    VAR state := PARSEXML(responseXml, "//CurrentTransportState");
    VAR isPlaying := SWITCH(state , "PLAYING", 1, "TRANSITIONING", 1, "STOPPED", 0, "NO_MEDIA_PRESENT", 0, "PAUSED_PLAYBACK", 0, 0);
    
    IF(isPlaying)
        VAR headerPause := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Pause\"";
        VAR bodyPause := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Pause xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:Pause></s:Body></s:Envelope>";

        SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", bodyPause, headerPause);
    ELSE
        VAR headerPlay := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Play\"";
        VAR bodyPlay := "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>";

        SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", bodyPlay, headerPlay);
    END
ELSE
    ADDERROR(response.Content);
    RETURN(NaN);
END
```

Playlist 1 Pulsante Lettura e scrittura

action

Variabile: `playlist_name` — Nome esatto di una playlist Sonos (Saved Queue). Distingue maiuscole e minuscole.

Scrittura stato pulsante

```taphome
######################
# check playlist name is not empty
IF(ISNULL(playlist_name) OR LENGTH(playlist_name) = 0)
   ADDERROR("Please set playlist name in device variables");
   RETURN(-1);
END

######################
# get player uuid
VAR response := SENDHTTPREQUEST("xml/device_description.xml");
VAR content := response.Content;
VAR playerUuid := PARSETEXT(content, "<UDN>uuid:", "</UDN>");

IF(ISNULL(playerUuid))
    ADDERROR("Failed to get player UUID");
    RETURN(-2);
END
######################

######################
# fetch playlists
VAR playlistUri := NULL;
VAR numberOfPlaylists := -1;
VAR readPlaylists := 0;

DO
    VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:ContentDirectory:1#Browse\"";
    VAR body := "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\"><ObjectID>SQ:</ObjectID><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter></Filter><StartingIndex>" + readPlaylists + "</StartingIndex><RequestedCount>10</RequestedCount><SortCriteria></SortCriteria></u:Browse></s:Body></s:Envelope>";

    response := SENDHTTPREQUEST("MediaServer/ContentDirectory/Control", "POST", body, header);
    content := response.Content;
    
    IF(numberOfPlaylists = -1)
        numberOfPlaylists := TODOUBLE(PARSETEXT(content, "<TotalMatches>", "</TotalMatches>"));
    END
    
    VAR returnedPlaylists := TODOUBLE(PARSETEXT(content, "<NumberReturned>", "</NumberReturned>"));
    readPlaylists := readPlaylists + returnedPlaylists;
    
    VAR playlistsXml := DECODE(PARSETEXT(content, "<Result>", "</Result>"), "xml");
    playlistUri := PARSEXML(playlistsXml, "//DIDL-Lite:container[dc:title='" + playlist_name + "']/DIDL-Lite:res");
    
    IF(!ISNULL(playlistUri) AND LENGTH(playlistUri) > 0)
        BREAK;
    END
LOOP WHILE readPlaylists < numberOfPlaylists
    
######################
IF(ISNULL(playlistUri) OR LENGTH(playlistUri) = 0)
    ADDERROR("Unable to find playlist with name '" + playlist_name + "'. Only Sonos playlists are supported.");
    RETURN(-3);
END

######################
# clear play queue
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#RemoveAllTracksFromQueue\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:RemoveAllTracksFromQueue xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:RemoveAllTracksFromQueue></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to RemoveAllTracksFromQueue (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-4);
END
######################

######################
# add playlist to queue
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:AddURIToQueue xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><EnqueuedURI>" + playlistUri + "</EnqueuedURI><EnqueuedURIMetaData></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>0</EnqueueAsNext></u:AddURIToQueue></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to AddURIToQueue (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-5);
END
######################

######################
# set play uri
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:SetAVTransportURI xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><CurrentURI>x-rincon-queue:" + playerUuid + "#0</CurrentURI><CurrentURIMetaData></CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to SetAVTransportURI (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-6);
END
######################

######################
# play
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Play\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to Play (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-7);
END
######################
```

Playlist 2 Pulsante Lettura e scrittura

action

Variabile: `playlist_name` — Nome esatto di una playlist Sonos (Saved Queue). Distingue maiuscole e minuscole.

Scrittura stato pulsante

```taphome
######################
# check playlist name is not empty
IF(ISNULL(playlist_name) OR LENGTH(playlist_name) = 0)
   ADDERROR("Please set playlist name in device variables");
   RETURN(-1);
END

######################
# get player uuid
VAR response := SENDHTTPREQUEST("xml/device_description.xml");
VAR content := response.Content;
VAR playerUuid := PARSETEXT(content, "<UDN>uuid:", "</UDN>");

IF(ISNULL(playerUuid))
    ADDERROR("Failed to get player UUID");
    RETURN(-2);
END
######################

######################
# fetch playlists
VAR playlistUri := NULL;
VAR numberOfPlaylists := -1;
VAR readPlaylists := 0;

DO
    VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:ContentDirectory:1#Browse\"";
    VAR body := "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\"><ObjectID>SQ:</ObjectID><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter></Filter><StartingIndex>" + readPlaylists + "</StartingIndex><RequestedCount>10</RequestedCount><SortCriteria></SortCriteria></u:Browse></s:Body></s:Envelope>";

    response := SENDHTTPREQUEST("MediaServer/ContentDirectory/Control", "POST", body, header);
    content := response.Content;
    
    IF(numberOfPlaylists = -1)
        numberOfPlaylists := TODOUBLE(PARSETEXT(content, "<TotalMatches>", "</TotalMatches>"));
    END
    
    VAR returnedPlaylists := TODOUBLE(PARSETEXT(content, "<NumberReturned>", "</NumberReturned>"));
    readPlaylists := readPlaylists + returnedPlaylists;
    
    VAR playlistsXml := DECODE(PARSETEXT(content, "<Result>", "</Result>"), "xml");
    playlistUri := PARSEXML(playlistsXml, "//DIDL-Lite:container[dc:title='" + playlist_name + "']/DIDL-Lite:res");
    
    IF(!ISNULL(playlistUri) AND LENGTH(playlistUri) > 0)
        BREAK;
    END
LOOP WHILE readPlaylists < numberOfPlaylists
    
######################
IF(ISNULL(playlistUri) OR LENGTH(playlistUri) = 0)
    ADDERROR("Unable to find playlist with name '" + playlist_name + "'. Only Sonos playlists are supported.");
    RETURN(-3);
END

######################
# clear play queue
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#RemoveAllTracksFromQueue\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:RemoveAllTracksFromQueue xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:RemoveAllTracksFromQueue></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to RemoveAllTracksFromQueue (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-4);
END
######################

######################
# add playlist to queue
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:AddURIToQueue xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><EnqueuedURI>" + playlistUri + "</EnqueuedURI><EnqueuedURIMetaData></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>0</EnqueueAsNext></u:AddURIToQueue></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to AddURIToQueue (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-5);
END
######################

######################
# set play uri
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:SetAVTransportURI xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><CurrentURI>x-rincon-queue:" + playerUuid + "#0</CurrentURI><CurrentURIMetaData></CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to SetAVTransportURI (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-6);
END
######################

######################
# play
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Play\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to Play (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-7);
END
######################
```

Playlist 3 Pulsante Lettura e scrittura

action

Variabile: `playlist_name` — Nome esatto di una playlist Sonos (Saved Queue). Distingue maiuscole e minuscole.

Scrittura stato pulsante

```taphome
######################
# check playlist name is not empty
IF(ISNULL(playlist_name) OR LENGTH(playlist_name) = 0)
   ADDERROR("Please set playlist name in device variables");
   RETURN(-1);
END

######################
# get player uuid
VAR response := SENDHTTPREQUEST("xml/device_description.xml");
VAR content := response.Content;
VAR playerUuid := PARSETEXT(content, "<UDN>uuid:", "</UDN>");

IF(ISNULL(playerUuid))
    ADDERROR("Failed to get player UUID");
    RETURN(-2);
END
######################

######################
# fetch playlists
VAR playlistUri := NULL;
VAR numberOfPlaylists := -1;
VAR readPlaylists := 0;

DO
    VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:ContentDirectory:1#Browse\"";
    VAR body := "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\"><ObjectID>SQ:</ObjectID><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter></Filter><StartingIndex>" + readPlaylists + "</StartingIndex><RequestedCount>10</RequestedCount><SortCriteria></SortCriteria></u:Browse></s:Body></s:Envelope>";

    response := SENDHTTPREQUEST("MediaServer/ContentDirectory/Control", "POST", body, header);
    content := response.Content;
    
    IF(numberOfPlaylists = -1)
        numberOfPlaylists := TODOUBLE(PARSETEXT(content, "<TotalMatches>", "</TotalMatches>"));
    END
    
    VAR returnedPlaylists := TODOUBLE(PARSETEXT(content, "<NumberReturned>", "</NumberReturned>"));
    readPlaylists := readPlaylists + returnedPlaylists;
    
    VAR playlistsXml := DECODE(PARSETEXT(content, "<Result>", "</Result>"), "xml");
    playlistUri := PARSEXML(playlistsXml, "//DIDL-Lite:container[dc:title='" + playlist_name + "']/DIDL-Lite:res");
    
    IF(!ISNULL(playlistUri) AND LENGTH(playlistUri) > 0)
        BREAK;
    END
LOOP WHILE readPlaylists < numberOfPlaylists
    
######################
IF(ISNULL(playlistUri) OR LENGTH(playlistUri) = 0)
    ADDERROR("Unable to find playlist with name '" + playlist_name + "'. Only Sonos playlists are supported.");
    RETURN(-3);
END

######################
# clear play queue
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#RemoveAllTracksFromQueue\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:RemoveAllTracksFromQueue xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:RemoveAllTracksFromQueue></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to RemoveAllTracksFromQueue (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-4);
END
######################

######################
# add playlist to queue
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:AddURIToQueue xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><EnqueuedURI>" + playlistUri + "</EnqueuedURI><EnqueuedURIMetaData></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>0</EnqueueAsNext></u:AddURIToQueue></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to AddURIToQueue (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-5);
END
######################

######################
# set play uri
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:SetAVTransportURI xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><CurrentURI>x-rincon-queue:" + playerUuid + "#0</CurrentURI><CurrentURIMetaData></CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to SetAVTransportURI (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-6);
END
######################

######################
# play
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Play\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to Play (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-7);
END
######################
```

Playlist 4 Pulsante Lettura e scrittura

action

Variabile: `playlist_name` — Nome esatto di una playlist Sonos (Saved Queue). Distingue maiuscole e minuscole.

Scrittura stato pulsante

```taphome
######################
# check playlist name is not empty
IF(ISNULL(playlist_name) OR LENGTH(playlist_name) = 0)
   ADDERROR("Please set playlist name in device variables");
   RETURN(-1);
END

######################
# get player uuid
VAR response := SENDHTTPREQUEST("xml/device_description.xml");
VAR content := response.Content;
VAR playerUuid := PARSETEXT(content, "<UDN>uuid:", "</UDN>");

IF(ISNULL(playerUuid))
    ADDERROR("Failed to get player UUID");
    RETURN(-2);
END
######################

######################
# fetch playlists
VAR playlistUri := NULL;
VAR numberOfPlaylists := -1;
VAR readPlaylists := 0;

DO
    VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:ContentDirectory:1#Browse\"";
    VAR body := "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\"><ObjectID>SQ:</ObjectID><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter></Filter><StartingIndex>" + readPlaylists + "</StartingIndex><RequestedCount>10</RequestedCount><SortCriteria></SortCriteria></u:Browse></s:Body></s:Envelope>";

    response := SENDHTTPREQUEST("MediaServer/ContentDirectory/Control", "POST", body, header);
    content := response.Content;
    
    IF(numberOfPlaylists = -1)
        numberOfPlaylists := TODOUBLE(PARSETEXT(content, "<TotalMatches>", "</TotalMatches>"));
    END
    
    VAR returnedPlaylists := TODOUBLE(PARSETEXT(content, "<NumberReturned>", "</NumberReturned>"));
    readPlaylists := readPlaylists + returnedPlaylists;
    
    VAR playlistsXml := DECODE(PARSETEXT(content, "<Result>", "</Result>"), "xml");
    playlistUri := PARSEXML(playlistsXml, "//DIDL-Lite:container[dc:title='" + playlist_name + "']/DIDL-Lite:res");
    
    IF(!ISNULL(playlistUri) AND LENGTH(playlistUri) > 0)
        BREAK;
    END
LOOP WHILE readPlaylists < numberOfPlaylists
    
######################
IF(ISNULL(playlistUri) OR LENGTH(playlistUri) = 0)
    ADDERROR("Unable to find playlist with name '" + playlist_name + "'. Only Sonos playlists are supported.");
    RETURN(-3);
END

######################
# clear play queue
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#RemoveAllTracksFromQueue\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:RemoveAllTracksFromQueue xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:RemoveAllTracksFromQueue></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to RemoveAllTracksFromQueue (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-4);
END
######################

######################
# add playlist to queue
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:AddURIToQueue xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><EnqueuedURI>" + playlistUri + "</EnqueuedURI><EnqueuedURIMetaData></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>0</EnqueueAsNext></u:AddURIToQueue></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to AddURIToQueue (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-5);
END
######################

######################
# set play uri
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:SetAVTransportURI xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><CurrentURI>x-rincon-queue:" + playerUuid + "#0</CurrentURI><CurrentURIMetaData></CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to SetAVTransportURI (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-6);
END
######################

######################
# play
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Play\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to Play (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-7);
END
######################
```

Playlist 5 Pulsante Lettura e scrittura

action

Variabile: `playlist_name` — Nome esatto di una playlist Sonos (Saved Queue). Distingue maiuscole e minuscole.

Scrittura stato pulsante

```taphome
######################
# check playlist name is not empty
IF(ISNULL(playlist_name) OR LENGTH(playlist_name) = 0)
   ADDERROR("Please set playlist name in device variables");
   RETURN(-1);
END

######################
# get player uuid
VAR response := SENDHTTPREQUEST("xml/device_description.xml");
VAR content := response.Content;
VAR playerUuid := PARSETEXT(content, "<UDN>uuid:", "</UDN>");

IF(ISNULL(playerUuid))
    ADDERROR("Failed to get player UUID");
    RETURN(-2);
END
######################

######################
# fetch playlists
VAR playlistUri := NULL;
VAR numberOfPlaylists := -1;
VAR readPlaylists := 0;

DO
    VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:ContentDirectory:1#Browse\"";
    VAR body := "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\"><ObjectID>SQ:</ObjectID><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter></Filter><StartingIndex>" + readPlaylists + "</StartingIndex><RequestedCount>10</RequestedCount><SortCriteria></SortCriteria></u:Browse></s:Body></s:Envelope>";

    response := SENDHTTPREQUEST("MediaServer/ContentDirectory/Control", "POST", body, header);
    content := response.Content;
    
    IF(numberOfPlaylists = -1)
        numberOfPlaylists := TODOUBLE(PARSETEXT(content, "<TotalMatches>", "</TotalMatches>"));
    END
    
    VAR returnedPlaylists := TODOUBLE(PARSETEXT(content, "<NumberReturned>", "</NumberReturned>"));
    readPlaylists := readPlaylists + returnedPlaylists;
    
    VAR playlistsXml := DECODE(PARSETEXT(content, "<Result>", "</Result>"), "xml");
    playlistUri := PARSEXML(playlistsXml, "//DIDL-Lite:container[dc:title='" + playlist_name + "']/DIDL-Lite:res");
    
    IF(!ISNULL(playlistUri) AND LENGTH(playlistUri) > 0)
        BREAK;
    END
LOOP WHILE readPlaylists < numberOfPlaylists
    
######################
IF(ISNULL(playlistUri) OR LENGTH(playlistUri) = 0)
    ADDERROR("Unable to find playlist with name '" + playlist_name + "'. Only Sonos playlists are supported.");
    RETURN(-3);
END

######################
# clear play queue
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#RemoveAllTracksFromQueue\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:RemoveAllTracksFromQueue xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:RemoveAllTracksFromQueue></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to RemoveAllTracksFromQueue (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-4);
END
######################

######################
# add playlist to queue
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:AddURIToQueue xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><EnqueuedURI>" + playlistUri + "</EnqueuedURI><EnqueuedURIMetaData></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>0</EnqueueAsNext></u:AddURIToQueue></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to AddURIToQueue (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-5);
END
######################

######################
# set play uri
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:SetAVTransportURI xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><CurrentURI>x-rincon-queue:" + playerUuid + "#0</CurrentURI><CurrentURIMetaData></CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to SetAVTransportURI (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-6);
END
######################

######################
# play
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Play\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
    ADDERROR("Unable to Play (" + PARSEJSON(response, "Content", 1) + ")");
    RETURN(-7);
END
######################
```

Stazione radio 1 Pulsante Lettura e scrittura

action

Variabile: `radio_name` — Nome esatto di una stazione radio da Sonos Favorites. Distingue maiuscole e minuscole.

Scrittura stato pulsante

```taphome
######################
# check radio name is not empty
IF(ISNULL(radio_name) OR LENGTH(radio_name) = 0)
   ADDERROR("Please set radio name in device variables");
   RETURN(-1);
END

######################
# fetch favorites
VAR radioUri := NULL;
VAR numberOfFavorites := -1;
VAR readFavorites := 0;

DO
    VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:ContentDirectory:1#Browse\"";
    VAR body := "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\"><ObjectID>FV:2</ObjectID><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter></Filter><StartingIndex>" + readFavorites + "</StartingIndex><RequestedCount>10</RequestedCount><SortCriteria></SortCriteria></u:Browse></s:Body></s:Envelope>";

    VAR response := SENDHTTPREQUEST("MediaServer/ContentDirectory/Control", "POST", body, header);
    VAR content := response.Content;
   
    IF(numberOfFavorites = -1)
        numberOfFavorites := TODOUBLE(PARSETEXT(content, "<TotalMatches>", "</TotalMatches>"));
    END
    
    VAR returnedFavorites := TODOUBLE(PARSETEXT(content, "<NumberReturned>", "</NumberReturned>"));
    readFavorites := readFavorites + returnedFavorites;
    
    VAR favoritesXml := DECODE(PARSETEXT(content, "<Result>", "</Result>"), "xml");
    radioUri := PARSEXML(favoritesXml, "//DIDL-Lite:item[dc:title='" + radio_name + "']/DIDL-Lite:res[@protocolInfo='x-sonosapi-stream:*:*:*']");
    
    IF(!ISNULL(radioUri) AND LENGTH(radioUri) > 0)
        BREAK;
    END
LOOP WHILE readFavorites < numberOfFavorites

IF(ISNULL(radioUri) OR LENGTH(radioUri) = 0)
    ADDERROR("Unable to find radio with name '" + radio_name + "'. Make sure it's included in your Sonos favorite radio stations");
    RETURN(-3);
END

######################
# find radio metadata
VAR radioMetaData := PARSEXML(favoritesXml, "//DIDL-Lite:item[dc:title='" + radio_name + "'and DIDL-Lite:res[@protocolInfo='x-sonosapi-stream:*:*:*']]/r:resMD");

IF(ISNULL(radioMetaData) OR LENGTH(radioMetaData) = 0)
	ADDERROR("Unable to find radio metadata");
	RETURN(-4);
END

######################
# set radio uri
VAR metaDataEncoded := ENCODE(radioMetaData, "xml");
VAR uriEncoded := ENCODE(radioUri, "xml");

header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:SetAVTransportURI xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><CurrentURI>" + uriEncoded + "</CurrentURI><CurrentURIMetaData>" + metaDataEncoded + "</CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
	ADDERROR("Unable to SetAVTransportURI (" + PARSEJSON(response, "Content", 1) + ")");
	RETURN(-5);
END
######################

######################
# play
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Play\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
	ADDERROR("Unable to Play (" + PARSEJSON(response, "Content", 1) + ")");
	RETURN(-6);
END
######################
```

Stazione radio 2 Pulsante Lettura e scrittura

action

Variabile: `radio_name` — Nome esatto di una stazione radio da Sonos Favorites. Distingue maiuscole e minuscole.

Scrittura stato pulsante

```taphome
######################
# check radio name is not empty
IF(ISNULL(radio_name) OR LENGTH(radio_name) = 0)
   ADDERROR("Please set radio name in device variables");
   RETURN(-1);
END

######################
# fetch favorites
VAR radioUri := NULL;
VAR numberOfFavorites := -1;
VAR readFavorites := 0;

DO
    VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:ContentDirectory:1#Browse\"";
    VAR body := "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\"><ObjectID>FV:2</ObjectID><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter></Filter><StartingIndex>" + readFavorites + "</StartingIndex><RequestedCount>10</RequestedCount><SortCriteria></SortCriteria></u:Browse></s:Body></s:Envelope>";

    VAR response := SENDHTTPREQUEST("MediaServer/ContentDirectory/Control", "POST", body, header);
    VAR content := response.Content;
   
    IF(numberOfFavorites = -1)
        numberOfFavorites := TODOUBLE(PARSETEXT(content, "<TotalMatches>", "</TotalMatches>"));
    END
    
    VAR returnedFavorites := TODOUBLE(PARSETEXT(content, "<NumberReturned>", "</NumberReturned>"));
    readFavorites := readFavorites + returnedFavorites;
    
    VAR favoritesXml := DECODE(PARSETEXT(content, "<Result>", "</Result>"), "xml");
    radioUri := PARSEXML(favoritesXml, "//DIDL-Lite:item[dc:title='" + radio_name + "']/DIDL-Lite:res[@protocolInfo='x-sonosapi-stream:*:*:*']");
    
    IF(!ISNULL(radioUri) AND LENGTH(radioUri) > 0)
        BREAK;
    END
LOOP WHILE readFavorites < numberOfFavorites

IF(ISNULL(radioUri) OR LENGTH(radioUri) = 0)
    ADDERROR("Unable to find radio with name '" + radio_name + "'. Make sure it's included in your Sonos favorite radio stations");
    RETURN(-3);
END

######################
# find radio metadata
VAR radioMetaData := PARSEXML(favoritesXml, "//DIDL-Lite:item[dc:title='" + radio_name + "'and DIDL-Lite:res[@protocolInfo='x-sonosapi-stream:*:*:*']]/r:resMD");

IF(ISNULL(radioMetaData) OR LENGTH(radioMetaData) = 0)
	ADDERROR("Unable to find radio metadata");
	RETURN(-4);
END

######################
# set radio uri
VAR metaDataEncoded := ENCODE(radioMetaData, "xml");
VAR uriEncoded := ENCODE(radioUri, "xml");

header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:SetAVTransportURI xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><CurrentURI>" + uriEncoded + "</CurrentURI><CurrentURIMetaData>" + metaDataEncoded + "</CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
	ADDERROR("Unable to SetAVTransportURI (" + PARSEJSON(response, "Content", 1) + ")");
	RETURN(-5);
END
######################

######################
# play
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Play\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
	ADDERROR("Unable to Play (" + PARSEJSON(response, "Content", 1) + ")");
	RETURN(-6);
END
######################
```

Stazione radio 3 Pulsante Lettura e scrittura

action

Variabile: `radio_name` — Nome esatto di una stazione radio da Sonos Favorites. Distingue maiuscole e minuscole.

Scrittura stato pulsante

```taphome
######################
# check radio name is not empty
IF(ISNULL(radio_name) OR LENGTH(radio_name) = 0)
   ADDERROR("Please set radio name in device variables");
   RETURN(-1);
END

######################
# fetch favorites
VAR radioUri := NULL;
VAR numberOfFavorites := -1;
VAR readFavorites := 0;

DO
    VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:ContentDirectory:1#Browse\"";
    VAR body := "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\"><ObjectID>FV:2</ObjectID><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter></Filter><StartingIndex>" + readFavorites + "</StartingIndex><RequestedCount>10</RequestedCount><SortCriteria></SortCriteria></u:Browse></s:Body></s:Envelope>";

    VAR response := SENDHTTPREQUEST("MediaServer/ContentDirectory/Control", "POST", body, header);
    VAR content := response.Content;
   
    IF(numberOfFavorites = -1)
        numberOfFavorites := TODOUBLE(PARSETEXT(content, "<TotalMatches>", "</TotalMatches>"));
    END
    
    VAR returnedFavorites := TODOUBLE(PARSETEXT(content, "<NumberReturned>", "</NumberReturned>"));
    readFavorites := readFavorites + returnedFavorites;
    
    VAR favoritesXml := DECODE(PARSETEXT(content, "<Result>", "</Result>"), "xml");
    radioUri := PARSEXML(favoritesXml, "//DIDL-Lite:item[dc:title='" + radio_name + "']/DIDL-Lite:res[@protocolInfo='x-sonosapi-stream:*:*:*']");
    
    IF(!ISNULL(radioUri) AND LENGTH(radioUri) > 0)
        BREAK;
    END
LOOP WHILE readFavorites < numberOfFavorites

IF(ISNULL(radioUri) OR LENGTH(radioUri) = 0)
    ADDERROR("Unable to find radio with name '" + radio_name + "'. Make sure it's included in your Sonos favorite radio stations");
    RETURN(-3);
END

######################
# find radio metadata
VAR radioMetaData := PARSEXML(favoritesXml, "//DIDL-Lite:item[dc:title='" + radio_name + "'and DIDL-Lite:res[@protocolInfo='x-sonosapi-stream:*:*:*']]/r:resMD");

IF(ISNULL(radioMetaData) OR LENGTH(radioMetaData) = 0)
	ADDERROR("Unable to find radio metadata");
	RETURN(-4);
END

######################
# set radio uri
VAR metaDataEncoded := ENCODE(radioMetaData, "xml");
VAR uriEncoded := ENCODE(radioUri, "xml");

header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:SetAVTransportURI xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><CurrentURI>" + uriEncoded + "</CurrentURI><CurrentURIMetaData>" + metaDataEncoded + "</CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
	ADDERROR("Unable to SetAVTransportURI (" + PARSEJSON(response, "Content", 1) + ")");
	RETURN(-5);
END
######################

######################
# play
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Play\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
	ADDERROR("Unable to Play (" + PARSEJSON(response, "Content", 1) + ")");
	RETURN(-6);
END
######################
```

Stazione radio 4 Pulsante Lettura e scrittura

action

Variabile: `radio_name` — Nome esatto di una stazione radio da Sonos Favorites. Distingue maiuscole e minuscole.

Scrittura stato pulsante

```taphome
######################
# check radio name is not empty
IF(ISNULL(radio_name) OR LENGTH(radio_name) = 0)
   ADDERROR("Please set radio name in device variables");
   RETURN(-1);
END

######################
# fetch favorites
VAR radioUri := NULL;
VAR numberOfFavorites := -1;
VAR readFavorites := 0;

DO
    VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:ContentDirectory:1#Browse\"";
    VAR body := "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\"><ObjectID>FV:2</ObjectID><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter></Filter><StartingIndex>" + readFavorites + "</StartingIndex><RequestedCount>10</RequestedCount><SortCriteria></SortCriteria></u:Browse></s:Body></s:Envelope>";

    VAR response := SENDHTTPREQUEST("MediaServer/ContentDirectory/Control", "POST", body, header);
    VAR content := response.Content;
   
    IF(numberOfFavorites = -1)
        numberOfFavorites := TODOUBLE(PARSETEXT(content, "<TotalMatches>", "</TotalMatches>"));
    END
    
    VAR returnedFavorites := TODOUBLE(PARSETEXT(content, "<NumberReturned>", "</NumberReturned>"));
    readFavorites := readFavorites + returnedFavorites;
    
    VAR favoritesXml := DECODE(PARSETEXT(content, "<Result>", "</Result>"), "xml");
    radioUri := PARSEXML(favoritesXml, "//DIDL-Lite:item[dc:title='" + radio_name + "']/DIDL-Lite:res[@protocolInfo='x-sonosapi-stream:*:*:*']");
    
    IF(!ISNULL(radioUri) AND LENGTH(radioUri) > 0)
        BREAK;
    END
LOOP WHILE readFavorites < numberOfFavorites

IF(ISNULL(radioUri) OR LENGTH(radioUri) = 0)
    ADDERROR("Unable to find radio with name '" + radio_name + "'. Make sure it's included in your Sonos favorite radio stations");
    RETURN(-3);
END

######################
# find radio metadata
VAR radioMetaData := PARSEXML(favoritesXml, "//DIDL-Lite:item[dc:title='" + radio_name + "'and DIDL-Lite:res[@protocolInfo='x-sonosapi-stream:*:*:*']]/r:resMD");

IF(ISNULL(radioMetaData) OR LENGTH(radioMetaData) = 0)
	ADDERROR("Unable to find radio metadata");
	RETURN(-4);
END

######################
# set radio uri
VAR metaDataEncoded := ENCODE(radioMetaData, "xml");
VAR uriEncoded := ENCODE(radioUri, "xml");

header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:SetAVTransportURI xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><CurrentURI>" + uriEncoded + "</CurrentURI><CurrentURIMetaData>" + metaDataEncoded + "</CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
	ADDERROR("Unable to SetAVTransportURI (" + PARSEJSON(response, "Content", 1) + ")");
	RETURN(-5);
END
######################

######################
# play
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Play\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
	ADDERROR("Unable to Play (" + PARSEJSON(response, "Content", 1) + ")");
	RETURN(-6);
END
######################
```

Stazione radio 5 Pulsante Lettura e scrittura

action

Variabile: `radio_name` — Nome esatto di una stazione radio da Sonos Favorites. Distingue maiuscole e minuscole.

Scrittura stato pulsante

```taphome
######################
# check radio name is not empty
IF(ISNULL(radio_name) OR LENGTH(radio_name) = 0)
   ADDERROR("Please set radio name in device variables");
   RETURN(-1);
END

######################
# fetch favorites
VAR radioUri := NULL;
VAR numberOfFavorites := -1;
VAR readFavorites := 0;

DO
    VAR header := "SOAPACTION: \"urn:schemas-upnp-org:service:ContentDirectory:1#Browse\"";
    VAR body := "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\"><ObjectID>FV:2</ObjectID><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter></Filter><StartingIndex>" + readFavorites + "</StartingIndex><RequestedCount>10</RequestedCount><SortCriteria></SortCriteria></u:Browse></s:Body></s:Envelope>";

    VAR response := SENDHTTPREQUEST("MediaServer/ContentDirectory/Control", "POST", body, header);
    VAR content := response.Content;
   
    IF(numberOfFavorites = -1)
        numberOfFavorites := TODOUBLE(PARSETEXT(content, "<TotalMatches>", "</TotalMatches>"));
    END
    
    VAR returnedFavorites := TODOUBLE(PARSETEXT(content, "<NumberReturned>", "</NumberReturned>"));
    readFavorites := readFavorites + returnedFavorites;
    
    VAR favoritesXml := DECODE(PARSETEXT(content, "<Result>", "</Result>"), "xml");
    radioUri := PARSEXML(favoritesXml, "//DIDL-Lite:item[dc:title='" + radio_name + "']/DIDL-Lite:res[@protocolInfo='x-sonosapi-stream:*:*:*']");
    
    IF(!ISNULL(radioUri) AND LENGTH(radioUri) > 0)
        BREAK;
    END
LOOP WHILE readFavorites < numberOfFavorites

IF(ISNULL(radioUri) OR LENGTH(radioUri) = 0)
    ADDERROR("Unable to find radio with name '" + radio_name + "'. Make sure it's included in your Sonos favorite radio stations");
    RETURN(-3);
END

######################
# find radio metadata
VAR radioMetaData := PARSEXML(favoritesXml, "//DIDL-Lite:item[dc:title='" + radio_name + "'and DIDL-Lite:res[@protocolInfo='x-sonosapi-stream:*:*:*']]/r:resMD");

IF(ISNULL(radioMetaData) OR LENGTH(radioMetaData) = 0)
	ADDERROR("Unable to find radio metadata");
	RETURN(-4);
END

######################
# set radio uri
VAR metaDataEncoded := ENCODE(radioMetaData, "xml");
VAR uriEncoded := ENCODE(radioUri, "xml");

header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:SetAVTransportURI xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><CurrentURI>" + uriEncoded + "</CurrentURI><CurrentURIMetaData>" + metaDataEncoded + "</CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
	ADDERROR("Unable to SetAVTransportURI (" + PARSEJSON(response, "Content", 1) + ")");
	RETURN(-5);
END
######################

######################
# play
header := "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#Play\"";
body := "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>";

response := SENDHTTPREQUEST("MediaRenderer/AVTransport/Control", "POST", body, header);
IF(!response.IsSuccess)
	ADDERROR("Unable to Play (" + PARSEJSON(response, "Content", 1) + ")");
	RETURN(-6);
END
######################
```

**Connessione:** Packet Parser → HTTP • Hostname: `Sonos-{MAC}.local`

Possibili miglioramenti (14)

- Bass control — Adjustable bass level -10 to 10
- Treble control — Adjustable treble level -10 to 10
- Loudness compensation — Boolean loudness on/off
- Night mode — Boolean night mode (reduced dynamics), available on soundbar models
- Crossfade — Boolean crossfade on/off between tracks
- Seek (time/track) — Seek by TRACK\_NR, REL\_TIME, or TIME\_DELTA
- Queue management — Full queue CRUD — add, remove, reorder tracks
- Group management — Multi-room group join/leave/delegate coordinator
- Alarm management — Create, edit, delete alarms on the speaker
- Battery status — Battery data available on portable models only (Move, Roam)
- Relative volume — Increment/decrement volume by delta value
- Sleep timer remaining — Read remaining sleep timer duration (hh:mm:ss)
- Surround/Sub EQ — Subwoofer gain, surround level, height channel — available on multi-speaker setups
- LED control — Status LED on/off

## Parametri di importazione

Inserisci questi valori quando importi l'XML.

| Richiesto nell'app | Predefinito   |
|--------------------|---------------|
| Indirizzo IP       | `192.168.0.1` |

## Fonti

- Sonos AVTransport API Reference (svrooij.io)
  
  [sonos.svrooij.io](https://sonos.svrooij.io/services/av-transport) 2026-03-27
- Sonos RenderingControl API Reference (svrooij.io)
  
  [sonos.svrooij.io](https://sonos.svrooij.io/services/rendering-control) 2026-03-27
- Sonos Communication Overview (svrooij.io)
  
  [sonos.svrooij.io](https://sonos.svrooij.io/sonos-communication) 2026-03-27
- Home Assistant Sonos Integration
  
  [www.home-assistant.io](https://www.home-assistant.io/integrations/sonos/) 2026-03-27

## Documentazione correlata

- [Integrazione Packet Parser](https://taphome.com/it/compatibility/packet-parser-guide/)
- [Packet Parser (HTTP, TCP, UDP, FTP, MQTT)](https://taphome.com/it/docs/integration/packet-parser/)
- [Funzioni Packet parser](https://taphome.com/it/docs/script/packet-parser/)
- [Funzioni di parsing](https://taphome.com/it/docs/script/parsing-functions/)

