[APP][Pro] Sonos (LocalAPI)

Could have done that.. At least I didn’t uninstall the original app. :zany_face:

Hopefully, you’ll have copied your flows beforehand. Otherwise, you’ll have to edit ALL the flows again anyway.

Big flow, only edited the Sonos part. Thank God!

Just FYI:

  • Before making key changes to a flow, you can make a restorable download of your flow. Check: Web App ALT + Context Menu: Export/Import Flows;
  • Another suggestion is to create a PDF print of your flow (e.g. via Chrome’s print to PDF option). That way you always have a visual copy of the flow, should you have to re-create it;
  • Also there is the Flow Version History app that automatically saves restorable copies of your flow after each change. It also acts as a recycle bin, allowing you to restore deleted flows.

So here’s how to use it: You paste the code i will give you in a “run code with argument and return text-string” card.

image

Now you put the argument as Text;Language.

The language will be the language code as for example: en for english, en-US if you specifically want US english.

Now lastly just put the play URL at volume and put the URL as the Result of your HomeyScript.

Code:

// Single argument format: "text;language"

if (!args[0]) throw new Error('Usage: args[0]="text;language"');

// Split the argument by separator ";"
const parts = args[0].split(';');
if (parts.length !== 2) throw new Error('Argument must be "text;language"');

const text = parts[0].trim();
const lang = parts[1].trim();

// URL-encode the text
const encodeText = encodeURIComponent(text);

// Build Google Translate TTS URL
const ttsUrl = `https://translate.google.com/translate_tts?ie=UTF-8&q=${encodeText}&tl=${lang}&client=tw-ob`;

// Log for debugging
console.log(`TTS URL: ${ttsUrl}`);

// Return the URL to use in Sonos
return ttsUrl;

You can also type sentences.

image

Great, will definitely try that. Thx, @John_William_Brekke.
Is it also possible to use a text variable (logic) this way?

I have a variable -part of the day- that is set as “morning”, “afternoon”, “evening” and “night”.
I use it in the Athom Sonos app to let it say “good -part of the day-”, that makes “good morning”, “good afternoon”, etc…

Yes, you can also use variables! All it does is actually take your text, which can include all types of variables. And makes it into a google translate .mp3 file which Sonos plays through the URL.

I use a Tag from a webhook where my phone sends input to say whatever i want through the Sonos speakers.

As you can see here it says Result;Result. Because both Text and Language gets sent from my phone. (Only iPhone as IOS Shortcuts is used for this, i don’t know if Android has similar apps to IOS Shortcuts)

I found JSON helping a lot and making the advanced flow much more advanced while being smaller than my other advanced flow which was way too big. Both advanced flows doing the same except the smallest one where i use JSON has more advanced features, so therefore i deleted my big advanced flow to only use the smaller one with JSON.

I’ve just released version 2.5.0 to test.

This version adds a built-in Azure Text-to-Speech option. Until now, using Azure TTS required creating your own Azure account, setting up a Speech resource, and entering your own API key in the app. (That option will remain available)

The new built-in option is meant to make TTS much easier to use: select the built-in Azure provider in the app settings, choose a voice, and use the existing TTS flow card.

To keep this manageable, the built-in service uses caching and usage limits. So repeated messages should not always need a new Azure request, and the service is protected against excessive use.

For now this is available in the test version first. It will probably take some trial and error to find the right balance between normal day-to-day usage, fair use for everyone, and keeping the Azure costs under control. Feedback is very welcome, especially about reliability, and whether the current limits feel reasonable in normal use.

Thanks, you’re the best!
Works like a charm!

Only thing I can think of is that when you go back into the app settings after selecting and saving another voice, the first voice (from that language) seems to be selected again (in my case with nl-nl, voice Fenna).

Nothing important of course. Have donated you a few beers to help you maintaining… :+1:t2::smiley:

Hi everyone,

i just tried grouping my speakers with an advanced flow but unfortunately no other speakers appear to connect with. It works with the official Sonos app, but I’d really love to use this app. Does anyone has an idea or is it a bug? I already deleted the app, restarted my Homey 2019 and reinstalled the app.

Could you check if the other speakers are also added in Homey through Sonos (LocalAPI), and not only through the official Sonos app? The card can only group with speakers that are known to this app.

Could you also try the flowcard in the app on your phone? Could be browser caching or something.

I definitly had all speakers connected through the Sonos (LocalAPI) App. Just tried it on the phone in a standard flow: unfortunetaly the same result. No devices appear.

Sonos S1 System?

I only have Sonos S1 devices, and the group option doesn’t work with this Sonos (LocalAPI) because it only takes Sonos S2 devices into account. The official Sonos app from athom works with Sonos S1 devices. But I think a mixed S1 + S2 System will also not work.

Only my sub is a gen 1 and therefor a S1 device. Apart from that I have an Arc and 3x Sonos One gen 2 (two of them as standalone speakers). So I’d assume that at least the two standalone Sonos One gen 2 speakers should appear.

It’s not just a question of generation, but of which mode the devices are set to. Your Sonos One supports both S1 and S2 modes.

Question: Which Sonos app are you using on your phone?