Sonos Cloud API - Better alerts & TTS

Currently that’s true, there’s no indication when an announcement has finished playing. Perhaps I can find a way, but no promises.

2 Likes

Thanks, It’d be great if you could.
I know this question came up a lot in several threads a few years ago and the only solutions were as I said to using the player state or the duration attribute.

I suspect quite a few people will want this even if it just to stop ‘announcement clash’.

Having use this now for a few days I really do urge you to consider a way to know when an announcement is playing and has ended.

I think it is actually very important.

One (perfect?) solution I can think of would be to add attributes to the media_player such as

- announcement: [true, false]
- announcement duration: x seconds

I don’t have a very deep knowledge of developing for HA so i admit that I have no idea if that is feasible?


I also have another issue (I think).

When using tts.cloud_say am I right in thinking that if the announcement is sent to several players (Sonos) they will not play in synch?

I know this was a limitation of the original integration and was the main reason I only made limited use of it. (As well as wanting my announcements to stay local and not pass through the Sonos organisation).

I may be doing something wrong but I am getting small but significant and annoying delays between each player which makes it sound like an echo if you are in earshot of more than one player.

Ok… another update…

I have now found out that there is very generous free tier for the Google Cloud TTS service (the same one used by Nabu Casa).

As you can imagine from a Google implementation it offers a vast array of customising of the TTS output.

Including:

  • Inserting pauses
  • Inserting audio files in sequence in the TTS (Perfect for small a small ‘ding-dong’ preceding the announcement.

These extras do require the text to be sent in SSML format but that is not a very onerous task. Normal text is sent as, erm, normal text.

The only downside is that you need to jump through a few hoops to set it up initially and provide billing information to Google in case you go over the free allowance (unlikely in my opinion for HA announcements and it seems that at that point you need to opt-in to billing anyway).

I used this website as a source of reference and it a was all fairly painless.

I haven’t yet done much testing but… fingers crossed!

Anyway, this probably means my only outstanding problem is ‘announcement clash’ and now that I can build pauses into a single annou9ncement it is much less of an issue (for me at least. I still think this will be an annoyance to others).

Anyway, this still means there are outstanding problems,

  • ‘announcement clash’ but now that I can build pauses into a single announcement it is much less of an issue (for me at least. I still think this will be an annoyance to others).
  • and of course not being able to group media players

PS. Yes I do see the irony in using Google Cloud after saying this: :wink:


EDIT: So far not bad, except I can’t get it to play an embedded local sound file. Probably some kind of security restriction somewhere. Shame as that would have been brilliant.

As far as embedding a local sound file, you should try using the custom integration Chime TTS which allows you to add a sound file at the start and/or the end of the TTS message. The integration locally combines them into a single file so there’s no lag during playback

I’m trying to use this with Node Red to send announcements when my doorbells are pressed. I can make it work using Developer Tools, to call the service, but I can’t seem to figure out the syntax in Node Red for the JSON. Here is what I’m using in Dev Tools. Any ideas?

service: media_player.play_media
data:
  entity_id: media_player.deck_sonos_move
  media_content_id: >-
    media-source://tts/cloud?message=The front door bell has been pressed.
  media_content_type: music
  extra:
    volume: 50

Now that many of the features are now included in core HASS, it looks like lots of people are converting automations to use the original media player entities.

Just wondering if volume is something I can control with core integrations now?

Yes. See the examples in the documentation: Sonos - Home Assistant.

Thanks for the info, but no matter what I try I can’t get it to work.

More specifically, I’m trying to automatically adjust volume of a TTS mesage sent to Sonos. My partner often turns volume of speakers down to zero instead of unpairing them from the group and so this weather notification is often played silently.

Whenever I try to add ‘volume’ or ‘extra: volume:’ anywhere in this data_template section I get an ‘extra keys not allowed @ data[‘extra’]. Got None’ error.

service: tts.speak
data_template:
  cache: false
  media_player_entity_id: media_player.sonos_roam
  message: >-
    The weather for today is a maximum of {{
    states('sensor.karabar_test_temp_max_0') }} degrees, {{
    states('sensor.karabar_test_extended_text_0') }}
  language: en
target:
  entity_id: tts.google_en_com

You can’t use that directly inside plain TTS calls. Look at the second example for how to use volume with TTS messages.

Hello,

I try to play a mp3 sound from my sonos. I hear the normal music is going to background (lower volume) but the mp3 will not be played.
I put the mp3 in /www/media/ and use the following service:

service: media_player.play_media
data:
  media_content_id: //www/media/spooky_halloween_with_thunder.mp3
  media_content_type: music
target:
  entity_id: media_player.kantoor_cloud

there is no error in dthe log about a unknown sourde directory.
Why will the mp3 not play?

Hi, i’m using the announce: true feature which works well.
However I have a setup with a pair of 2 era100’s and a sonos arc paired with 2 era300. The announce feature only works for 1 speaker in a stereo pair and only for the arc (not the era300). I’ve read somewhere that you can use play_on_bonded: true under extra to activate the paired speakers. However it doesn’t seem to work for me when using announce: true . Any idea how that can be solved?

This was a feature in the custom integration, but not (yet) available in the native integration. The behavior would sometimes lead to out-of-sync alerts in the same room so I was looking for better ways to use the Sonos API to avoid this. I haven’t found a way, so perhaps adding the feature as an opt-in option would be better than nothing.

1 Like

Thanks for the explanation and all your work! Would be great to have it indeed as an opt-in option :grin:

I’ve had this custom integration hanging around my system for a while now but I’m wondering why.

is there anything in this custom integration that is useful that isn’t available now in the built-in integration?