# \[NODE-RED\] Sonos speakers

**URL:** <https://community.gladysassistant.com/t/node-red-enceintes-sonos/7792>\
**Category:** Tutoriels\
**Tags:** tutoriel, sonos\
**Created:** [December 25, 2022, 2:39pm UTC](https://community.gladysassistant.com/t/node-red-enceintes-sonos/7792 "2022-12-25T14:39:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tlse-vins](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/tlse-vins/32/6054_2.png) [@Tlse-vins](https://community.gladysassistant.com/u/Tlse-vins)\
**Post date:** [December 25, 2022, 2:39pm UTC](https://community.gladysassistant.com/t/node-red-enceintes-sonos/7792/1 "2022-12-25T14:39:49Z")

</div>

With the help of @spenceur, I’ll explain how to make your Sonos speakers speak via node-red and a scene.

I won’t explain how to set up NODE-RED, @pierre-gilles has already made a tutorial video for that. [https://www.youtube.com/watch?v=bpmHzR8\_S5g](https://www.youtube.com/watch?v=bpmHzR8_S5g).  
However, you’ll need to call an external API in Node-RED called «&nbsp;node-red–contrib-tts-ultimate&nbsp;».  
To do this @pierre-gilles explains it at [38:55](https://www.youtube.com/watch?v=bpmHzR8_S5g&t=2335s).

**Here is the Node-RED flow:**

 ![Screenshot of Node-RED flow](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/5/5b3d8b45d1c386f0dd404a6890ed0ebcd32add65.png)

**First function: http in**  
Nothing complicated

 ![Screenshot of http in function](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/a/added469aadcb42c9184078c5323b16ae5114603.png)

**Second function: Global settings**

```auto
 // Global Settings
 global.set("defaultVolume", 30);
 global.set("home", {
     salon: '192.168.1.58'
    chambre: 'ip-chambre'
 })
 return msg;

```

**Third function: check auth**

```auto
 msg.statusCode = 401;
 if (
     typeof msg.payload.room != 'undefined'
     && msg.payload.user === 'clef uuid' à renseigner
 ) {
     msg.statusCode = 200;
     msg.room = msg.payload.room || 'all';
     msg.volume = msg.payload.volume || global.get("defaultVolume");
     msg.payload = msg.payload.msg;
     msg.test = global.get("home")[msg.room];
     msg.setConfig = {};
     if (msg.room === 'all') {
         msg.setConfig = {
             setMainPlayerIP: global.get("home")['salon'],
             setPlayerGroupArray: [
                 global.get("home")['salon']
             ],
         }
     } else {
         msg.setConfig.setMainPlayerIP = global.get("home")[msg.room];
     }
 }
 return msg;

```

You will need to generate a UUID key so that only you can broadcast to your speakers via a key generator: [uuidgenerator.net](https://www.uuidgenerator.net/).

**Fourth function: TTS-Ultimate**

You can choose the parameters you want in this function.  
In «&nbsp;main Sonos Player&nbsp;», select the speaker group.

 ![TTS-Ultimate function screenshot](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/d/d7b8bf77aa66b59d2bb58e7901d27a696ae3e2a9.png)

**Fifth function: http response**

There’s nothing to put in it.

**Sixth function: debug**

 ![debug function screenshot](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/7/7df04b34e84e45f0b85c11d3b724715cc8d28576.png)

Remember to connect everything properly and deploy your flow.  
If everything is fine, below the TTS-Ultimate function you should see Sonos is connected.

Now we’re going to create a scene in Gladys.

Choose a trigger depending on what you want to do.  
Then add an action «&nbsp;Make an HTTP request.&nbsp;»

**In this request:**

- Method: POST
- URL: http://ip\_de\_votre\_instance:1880/tts
- Body:

```auto
{
"user":"clef uuid",
"msg":"il faut sortir la poubelle",
"room":"salon",
"volume": 15

}

```

Now it’s your turn to play with your scenes and broadcast your messages.

As soon as I understand how to add an audio file so it can be played, I’ll add it to the tutorial.  
For example an alarm sound during an intrusion.  
If you know how to do it, I’m open to any info — I’m far from an expert in node-red.  
Thanks to @spenceur for his help.
