SONOS TTS Script

I have had the SONOS TTS installed and working via HASS.IO it was working fine until a month or so ago. To resolve I have tried to reinstall but now it doesn’t run, I get the following in the logs:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
ifelse: fatal: unable to exec ./run.sh: Exec format error
[cmd] ./run.sh exited 126
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.

Any ideas what’s going on?

Thanks Gary

@kevinvincent thanks a lot for your add on!
Unfortunetly I’m stuck with the “Perform auth flow” step… When I try to reach https://my.hassio.ip:8349/auth I always get an ERR_CONNECTION_REFUSED and I’m not able to login. I tried all the possible IPs/URLs that I use to access HA, but none of them worked (yes, I do use https).

This is the addon log (it reports the same error of @connoleg above) :

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
ifelse: fatal: unable to exec ./run.sh: Exec format error
[cmd] ./run.sh exited 126
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.

Any ideas?
Thanks!

@asp @connoleg I haven’t updated my HA in awhile so might be something weird with the latest Hass.io. I’ve updated the addon with my hunch of what it can be. Can you try reinstalling?

1 Like

Bingo! It’s working now :slight_smile: Thanks a lot for the super quick reply!

One request, would it be possibile in the future to use the Google Cloud TTS? It’s much more smooth and realistic compared to the Google Translate TTS (try it!)

Not see the Google Cloud TTS before, it’s so much better! Need to start using it in place of my current TTS setup!

Working here too!
Thank you very much for fixing. I’ve missed her voice telling me how long the journey to work is first thing.

Kind regards.
Gary

For those interested in using RESTful command for Sonos TTS Addon, here an example:

rest_command:
  sonos_rest:
    url: http://hassio.local:8349/api/speakText?playerId={{ sonos_id }}&text={{ sonos_text }}&volume={{ sonos_volume }}
    method: GET
    verify_ssl: false

and action for automation:

  action:
    - service: rest_command.sonos_rest
      data:
        sonos_id: "id_of_your_sonos_device"
        sonos_text: "Text example"
        sonos_volume: "20"

@kevinvincent, maybe we can add this to the documentation?

1 Like

Is this still working? Because whether using withing the automation nor doing it manual, snapshotting and restoring after a tts command is not working for me. at least with spotify playing music before. any ideas?

manual steps i did:

  1. listening to spotify music
  2. snapshotting it
  3. playing some tts commands - is working
  4. restoring it - nothing happens

I’m using the addon with RESTful commands (as mentioned above) and it’s still working, even if, since few updates, messages now get cutoff.

seems not to be working with spotify connect, everything else is working (started directly within the sonos app)

Hi @kevinvincent,
Just to say thank you for your SONOS addon, exactly what I was looking for, and working great!
For those interested, I thought that the best way to use it was as a notify service (and therefore add it in notify groups or alerts), so here is my config for those interested:

notify:
  - name: sonos
    platform: rest
    resource: 'http://<your.local.ip>:8349/api/speakText'
    method: GET
    message_param_name: text
    data:
      volume: '{{ data.volume }}'
      playerId: >
        {% set my_player = {"Cuisine":"RINCON_xxxxxxxxxxxxxxxxxxxxxx", "Salon":"RINCON_xxxxxxxxxxxxxxxxxxxxxx", "Salle à manger":"RINCON_xxxxxxxxxxxxxxxxxxxxxx"} -%}
        {{ my_player[target[0]] }}

To build the dict for the playerId, you have to take the values from the results here:
http://<your.local.ip>:8349/api/allClipCapableDevices

Then you can call it the same way you would use for another notify service:

service: notify.sonos
data:
  message: ceci est un test
  target: Salon
  data:
    volume: 30

It would be great if you could have a look at the possibility to broadcast to several or all SONOS speakers in sync (I think there were some discussions on this in your Github). Anyway, thanks again for this addon!

1 Like

Hi all and thank you @kevinvincent for this the addon! I’m an absolute beginner and had a lot of trouble, but eventually I got it working.

I really would LOVE to use Cloud TTS (via Nabu Casa) with this addon, is there any way at all of doing so? Any help with this would be greatly appreciated. I would prefer to use this addon with my Sonos to other solutions, but I just can’t go on without Cloud TTS :open_mouth:

I’m very new to HA, and I wanted something to announce when my doorbell is pressed.

This script makes sense to me, but where do I need to place it in HA to make it come alive? Ideally I want an automation of trigger being doorbell press, action being this sonos tts script but I have no idea where it should go.

TIA

This is all I do…

automation:

- alias: sound_doorbell
  trigger:
    - platform: event
      event_type: deconz_event
      event_data:
        id: doorbell
        event: 1002
  
  condition:
    condition: state
    entity_id: group.us
    state: home
  action:
    service: tts.google_translate_say
    data:
      entity_id: media_player.all
      message: there's someone at the door  

My door bell is just a Xiaomi push button (Aqara Smart Wireless Switch Smart Remote One Key Control Aqara Intelligent Application Home Security APP Control For Mijia APP|Smart Remote Control| - AliExpress) which I link to my HA with a Conbee zigbee usb device. Obviously the trigger could one of a huge range of alternatives from motion sensors to a switch.

Thats awesome thanks for the advice, I actually got it working straight after I posted then forgot to delete the post. I have a Google Nest doorbell and the announcement how plays on my Sonos Playbar.

alias: Doorbell Sonos
description: ''
trigger:
  - platform: device
    device_id: xxx
    domain: nest
    type: doorbell_chime
condition: []
action:
  - service: sonos.snapshot
    data:
      entity_id: media_player.livingroom_sonos
  - service: media_player.volume_set
    target:
      device_id: xxx111
    data:
      volume_level: 0.4
  - service: tts.google_say
    data:
      entity_id: media_player.livingroom_sonos
      message: Someone is waiting at the front door
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - service: sonos.restore
    data:
      entity_id: media_player.livingroom_sonos
mode: single

I recently found the Sonos audioClip API call and decided to make a custom component to take advantage of it. And then I found this thread and saw that @kevinvincent already did that almost exactly two years ago!

Anyway, I’ve posted a separate thread earlier today with a link to the new project: https://community.home-assistant.io/t/sonos-cloud-api-better-alerts-tts/. It’s a different approach which uses a custom component instead of an add-on. It does the OAuth-y authentication within HA and exposes media_player entities to use directly in scripts and automations. Hopefully it’s useful to somoene else. And perhaps @kevinvincent can give some suggestions on how to improve it. :wink:

Hmmm… Interesting to see how you did it. I’ve chosen a different approach. I wait for state to change to playing and again until state is paused. Works fine…

    - wait_template: "{{ is_state(sonos_entity, 'playing') }}"
      timeout: '00:00:05'
      continue_on_timeout: true
    - wait_template: "{{ is_state(sonos_entity, 'paused') }}"
      timeout: '00:05:00'
      continue_on_timeout: true

Does anyone know if the add-on by @kevinvincent is still being maintained/functional?

I see the linked repo has issues and PR’s that haven’t been addressed going back to December.

If you’re willing to try something new, I made a custom component that doesn’t require installation or maintenance of an add-on: Sonos Cloud API - Better alerts & TTS.

2 Likes

I’m already testing it out literally right now. :laughing:

I’ll see you in your other thread… :slightly_smiling_face:

1 Like