Smart routing of sonos_say script


#1

I had a yaml automation that would announce via sonos_say when my Ring doorbell was rung, with the condition that it would only announce if the Pool Sonos was playing (indicating I might be in the backyard). I want to have a more sophisticated version of that using Node-red. I made a basic flow triggered by the ring’s binary sensor, which then fans out to condition state nodes for each media player (halt if paused). It then calls the sonos_say service for each media player with the following example json:
{ "sonos_entity": "media_player.pool", "volume": 0.7, "message": "Someone's at the door", "delay": "00:00:02" }
And looks like this:
image
Oddly, when I run this, only one Sonos will make the announcement if more than one is playing (which, as far as I can tell, is based on the order I added the condition nodes).
Can anyone show me a more elegant execution of this? I’m thinking it’d do something to create a sonos snapshot, temporarily join all playing sonos and play the announcement, then restore the snapshot.


#2

Did you ever figure this out? I can’t even figure out how to use TTS with my Sonos via Node-red.


#3

Me neither, however I found this: https://www.home-assistant.io/cookbook/sonos_say/


#4

I’m using a Node-Red node for Sonos which works really well. I use it for all kind of announcements.


#5

I use node-red all the time and downloaded the Sonos nodes, but can’t get those to work either. I wonder what I’m doing wrong??


#6

yes, It was a bit tricky to setup … I will share my flow later


#7

That would be great! Thanks


#8

All my Sonos messages are done with the Polly-TTS Node

I have configured 3 global variables which either get set by HA or from within Node-Red flows (see Inject node in this sample)

  • global.sonos_message = containing the message string
  • global.Sonos_msg_volume = the volume of the message
  • global.Sonos_msg_room = Room-Name of the Sonos device to say-out the message

In this sample I have i have 4 events

  • General Message , (controlled via the Global Variable)
  • Doorbell , which is called from the motionsensor at front-door
  • Abbey_is_outside, which is called when the backdoor is closed and the motion sensor in front of the backdoor is triggered
  • Abbey_wants_out, which is called when the backdoor is closed and the motion sensor inside the backdoor is triggered

The good thing is that Polly-TTS is doing a local cache, so the last 3 events are triggered and said-out-load, when there is no internet connection

[{"id":"9cd719e1.24c3b8","type":"inject","z":"ced8e004.0bd76","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":145,"y":350,"wires":[["44f6cbc7.2fefd4"]]},{"id":"44f6cbc7.2fefd4","type":"change","z":"ced8e004.0bd76","name":"Sonos MSG","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"sonos_message","pt":"global","to":"This is a Test","tot":"str"},{"t":"set","p":"Sonos_msg_volume","pt":"msg","to":"0.5","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":205,"y":100,"wires":[["96f5450a.8e2308"]]},{"id":"96f5450a.8e2308","type":"change","z":"ced8e004.0bd76","name":"Sonos MSG","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"sonos_message","tot":"global"},{"t":"set","p":"volume","pt":"msg","to":"Sonos_msg_volume","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":70,"wires":[["cf50cc2d.0b55"]]},{"id":"cf50cc2d.0b55","type":"switch","z":"ced8e004.0bd76","name":"Sonos?","property":"Sonos_msg_room","propertyType":"global","rules":[{"t":"eq","v":"Bedroom","vt":"str"},{"t":"eq","v":"Kitchen","vt":"str"},{"t":"eq","v":"Living","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":540,"y":70,"wires":[["f888efa1.91e9b","dc5d67b9.51e428"],["b4f46022.ec31f","74083f65.078de"],[]]},{"id":"722e0882.1a3968","type":"link in","z":"ced8e004.0bd76","name":">> TTS Polly","links":["3401c13.2f8b93e"],"x":200,"y":70,"wires":[["96f5450a.8e2308"]]},{"id":"f888efa1.91e9b","type":"sonospollytts","z":"ced8e004.0bd76","name":"","voice":"0","ssml":false,"dir":"/tmp","sonosipaddress":"192.168.1.223","sonosvolume":"5","sonoshailing":"0","noderedipaddress":"192.168.1.200","noderedport":"1880","config":"e1b5b40b.260d88","x":760,"y":60,"wires":[]},{"id":"dc5d67b9.51e428","type":"debug","z":"ced8e004.0bd76","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":775,"y":170,"wires":[]},{"id":"b4f46022.ec31f","type":"sonospollytts","z":"ced8e004.0bd76","name":"","voice":"0","ssml":false,"dir":"/tmp","sonosipaddress":"192.168.1.220","sonosvolume":"5","sonoshailing":"0","noderedipaddress":"192.168.1.200","noderedport":"1880","config":"e1b5b40b.260d88","x":760,"y":110,"wires":[]},{"id":"74083f65.078de","type":"debug","z":"ced8e004.0bd76","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":795,"y":200,"wires":[]},{"id":"192584f0.f53b3b","type":"change","z":"ced8e004.0bd76","name":"Doorbell","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"http://192.168.1.199:8123/local/doorbell.mp3","tot":"str"},{"t":"set","p":"volume","pt":"msg","to":"50","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":140,"wires":[["cf50cc2d.0b55"]]},{"id":"73c7c571.34aa1c","type":"change","z":"ced8e004.0bd76","name":"Abbey_is_outside","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"http://192.168.1.199:8123/local/Abbey_is_outside.mp3","tot":"str"},{"t":"set","p":"volume","pt":"msg","to":"Sonos_msg_volume","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":180,"wires":[["cf50cc2d.0b55"]]},{"id":"caab3279.d8b6d","type":"change","z":"ced8e004.0bd76","name":"Abbey_wants_out","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"http://192.168.1.199:8123/local/Abbey_wants_out.mp3","tot":"str"},{"t":"set","p":"volume","pt":"msg","to":"Sonos_msg_volume","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":220,"wires":[["cf50cc2d.0b55"]]},{"id":"3bc2de2e.d4b2d2","type":"link in","z":"ced8e004.0bd76","name":">> Doorbell","links":["c2223c20.eab57"],"x":200,"y":140,"wires":[["192584f0.f53b3b"]]},{"id":"7ef49e1c.013a9","type":"link in","z":"ced8e004.0bd76","name":">> Abbey_is_outside","links":["6c8c1414.55b71c"],"x":200,"y":180,"wires":[["73c7c571.34aa1c"]]},{"id":"1e700ea2.832a71","type":"link in","z":"ced8e004.0bd76","name":">> Abbey_wants_out","links":["3b7b7b96.58e6c4"],"x":200,"y":220,"wires":[["caab3279.d8b6d"]]},{"id":"e1b5b40b.260d88","type":"sonospollytts-config","z":0,"name":"AWS"}]

I hope it helps


#9

Having a bit of trouble getting my head around it, since it uses locally stored mp3 files. Also, I get “pausing error” on my sonospollytts node whenever I try to do anything with it. Any idea what might be causing that?


#10

Yes, the MP3 files are stored locally but this is the same approach with most TTS systems as the announcment can be very lonng. The good thing is that repeated announcements will be played from cache and do not need internet connect.

I do not have a pausing error with my system. Is the pausing for a new announcement or for cached files?

  1. Delay with cached files - do you have audio compression on your sonos? … I had to disable mine due to delays and pause with other features
  2. Delay with new announcements - can be the network or internet connect