SONOS, 'say' what?

Is it possible to take advantage of the Say and Play commands programmatically on a SONOS device across the network - for alarms, greetings, alerts etc and just in response to various OpenHAB events? OR do you have to play an MP3 on the OpenHAB server and output whatever with a wired audio connection from the OpenHAB server (a RPi in my case) to a SONOS device like a Play:5 with audio in?

Hey,
I more or less asked the same question in the googlegroup. Seems like the 1st option is not possible right now, but also do see valuable use cases. Your second option might work as long as the rPi recognizes your PLAY:5 as regular output device.
Since I only own a PLAY:1 which does not have LineIn, I’m stuck with my alarming ideas.
Any input from others is appreciated.
Thanks

You can give a Sonos device a path to an mp3 and it will play.

You need a playuri item: String SonosLivingroom_PlayUri {sonos="[living:playuri]"}
Then in a rule you can do this:
sendCommand(“SonosLivingroom_PlayUri” , “//path/to/file.mp3”)

Hey Leon,
thanks for sharing that info. At least this gets me going with some static MP3’s. Do you know if $PATH_TO_FILE can be also a real URI? Then we could use the Google translate service to pull an MP3 file like this:

http://translate.google.com/translate_tts?tl=de&q="Openhab is so cool"

Thanks

That used to work:
sendCommand(“SonosLivingroom_PlayUri” , “x-rincon-mp3radio://translate.google.com/translate_tts?tl=en&q=Hello+i+am+home&client=OpenHAB”)
Allthough it took quite some time before it started playing.

But Google added a Capcha to the service :frowning:
On the OpenHAB Google groups forum there was a thread about this, and alternatives.

[edit]The mentioned thread has the solution, just add &client=OpenHAB to the query[/edit]

You can also use the service manually and save the mp3’s, and use those.

2 Likes

Thanks for your hint. I’ve tried with the following simple rule:

rule "Sonos play uri"
when
	Item wz_sonos_play_uri_switch changed to ON
then
	val speech = "Hello. This is a test"
	val url = "http://translate.google.com/translate_tts?tl=de&q=\"" + speech + "\"&client=OpenHAB"
	logInfo("Sonos Say URI","Link: " + url)
	sendCommand(wz_sonos_play_uri, url)
end

I can hear my Sonos going active since it does some really gentle noise, but it doesnt say anything.
events.log & openhab.log do receive the update and I can copy&paste the URL to a browser and listen to the voice.
In fact, URL & rule are ok. Only sonos does not spit it.
openhab.log:

2015-08-27 20:09:44.571 [INFO ] [hab.model.script.Sonos Say URI] - Link: http://translate.google.com/translate_tts?tl=de&q="Hello. This is a test"&client=OpenHAB

Any ideas?
Thanks

I’ve run in to a similar issue, but referencing local MP3 files - I can hear my SONOS go quietly fuzzy when the rule fires, but no MP3 is played. It was late the other night when I tried, so I gave up and haven’t returned to it yet. Keen to hear people’s thoughts on Sebastian’s issue as it will probably help me too.

The trick seems to be to use x-rincon-mp3radio:// instead of http:// in your url. Did you try this?

4 Likes

Hey Kai,
thanks for your feedback. I can confirm that this works nicely with my PLAY:1.
Great!

Just did. And it works great! Cheers.

What cool ways have people been putting this to use, aside from the expected doorbell and alarm siren applications…

Also…keen to explore how to make the ‘say’ command work with the sonos system for item status and other notifications.

I just tried this in the hope of using the Sonos system is feedback for when I verbally asked for the state of various items. During testing I got it to play the first time, but subsequent attempts at making it say something fails. When opening the Sonos app to try to play the last track again (which was the thing I sent from Openhab) it says that playback failed.

This is with OH2, and the log looks like this:

 Received HTTP POST request at 'items/sayKitchen' with value 'This is a test'.
2015-11-26 13:56:13 [INFO ] [arthome.event.ItemCommandEvent:43   ] - Item 'sayKitchen' received command This     is a test
2015-11-26 13:56:13 [DEBUG] [.m.r.r.i.engine.RuleEngineImpl:295  ] - Executing rule 'Sonos play uri'
2015-11-26 13:56:14 [INFO ] [smarthome.event.ItemStateEvent:43   ] - sayKitchen updated to This is a test
2015-11-26 13:56:14 [INFO ] [e.s.model.script.Sonos Say URI:48   ] - Link: x-rincon-    mp3radio://translate.google.com/translate_tts?tl=de&q="This is a test"&client=OpenHAB
2015-11-26 13:56:14 [DEBUG] [.c.thing.internal.ThingManager:293  ] - Delegating command 'x-rincon-    mp3radio://translate.google.com/translate_tts?tl=de&q="This is a test"&client=OpenHAB' for item     'FF_hallwaySonosURI' to handler for channel 'sonos:zoneplayer:RINCON_5CAAFD2BB4FE01400:playuri'
2015-11-26 13:56:14 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action 'Stop' of service     'AVTransport' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:14 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action     'RemoveAllTracksFromQueue' of service 'AVTransport' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:14 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action 'AddURIToQueue' of service     'AVTransport' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:14 [DEBUG] [.m.r.r.i.engine.RuleEngineImpl:267  ] - Executing startup rule 'Startup'
2015-11-26 13:56:14 [DEBUG] [.m.r.r.i.engine.RuleEngineImpl:278  ] - Execution of startup rule 'Startup' has been     postponed as items are still missing.
2015-11-26 13:56:14 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action 'SetAVTransportURI' of     service 'AVTransport' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:14 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action 'SetMute' of service     'RenderingControl' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:14 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action 'Play' of service     'AVTransport' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:14 [INFO ] [arthome.event.ItemCommandEvent:43   ] - Item 'FF_hallwaySonosURI' received     command x-rincon-mp3radio://translate.google.com/translate_tts?tl=de&q="This is a test"&client=OpenHAB
2015-11-26 13:56:14 [DEBUG] [.c.thing.internal.ThingManager:336  ] - Delegating update 'x-rincon-    mp3radio://translate.google.com/translate_tts?tl=de&q="This is a test"&client=OpenHAB' for item     'FF_hallwaySonosURI' to handler for channel 'sonos:zoneplayer:RINCON_5CAAFD2BB4FE01400:playuri'
2015-11-26 13:56:14 [INFO ] [smarthome.event.ItemStateEvent:43   ] - FF_hallwaySonosURI updated to x-rincon-    mp3radio://translate.google.com/translate_tts?tl=de&q="This is a test"&client=OpenHAB
2015-11-26 13:56:15 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currentartist updated to
2015-11-26 13:56:15 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currenttitle updated to translate_tts?tl=de&q="This is a     test"&client=OpenHAB
2015-11-26 13:56:15 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currentalbum updated to
2015-11-26 13:56:15 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action 'GetMediaInfo' of service     'AVTransport' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:15 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currenttitle updated to translate_tts?tl=de&q="This is a     test"&client=OpenHAB
2015-11-26 13:56:15 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currentartist updated to
2015-11-26 13:56:15 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action 'GetMediaInfo' of service     'AVTransport' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:15 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currenttitle updated to translate_tts?tl=de&q="This is a     test"&client=OpenHAB
2015-11-26 13:56:15 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currentalbum updated to
2015-11-26 13:56:15 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currenttitle updated to translate_tts?tl=de&q="This is a     test"&client=OpenHAB
2015-11-26 13:56:16 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action 'GetMediaInfo' of service     'AVTransport' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:16 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currentartist updated to
2015-11-26 13:56:16 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currenttitle updated to translate_tts?tl=de&q="This is a     test"&client=OpenHAB
2015-11-26 13:56:16 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currentalbum updated to
2015-11-26 13:56:16 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currenttitle updated to translate_tts?tl=de&q="This is a     test"&client=OpenHAB
2015-11-26 13:56:26 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currentartist updated to
2015-11-26 13:56:26 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currenttitle updated to translate_tts?tl=de&q="This is a     test"&client=OpenHAB
2015-11-26 13:56:26 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currentalbum updated to
2015-11-26 13:56:26 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action 'GetMediaInfo' of service     'AVTransport' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:26 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currenttitle updated to translate_tts?tl=de&q="This is a     test"&client=OpenHAB
2015-11-26 13:56:26 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_control updated to PAUSE
2015-11-26 13:56:26 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currentartist updated to
2015-11-26 13:56:26 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currenttitle updated to translate_tts?tl=de&q="This is a     test"&client=OpenHAB
2015-11-26 13:56:26 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currentalbum updated to
2015-11-26 13:56:26 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action 'GetMediaInfo' of service     'AVTransport' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:26 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action 'GetZoneInfo' of service     'DeviceProperties' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:26 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currenttitle updated to translate_tts?tl=de&q="This is a     test"&client=OpenHAB
2015-11-26 13:56:26 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action 'GetZoneAttributes' of     service 'DeviceProperties' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:26 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action 'GetRunningAlarmProperties'     of service 'AVTransport' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:26 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action 'GetLEDState' of service 'DeviceProperties' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:26 [DEBUG] [e.s.i.t.upnp.UpnpIOServiceImpl:270  ] - Invoking Action 'GetMediaInfo' of service     'AVTransport' for participant 'RINCON_5CAAFD2BB4FE01400'
2015-11-26 13:56:26 [INFO ] [smarthome.event.ItemStateEvent:43   ] -     sonos_zoneplayer_RINCON_5CAAFD2BB4FE01400_currenttitle updated to translate_tts?tl=de&q="This is a     test"&client=OpenHAB

same problem here, first play worked. after that not anymore. :confused:

It also appears that you have to send it to the group controller if you have your Sonos speakers grouped.

For what it’s worth, my latest tutorial was just published on this. It provides a very reliable method, more than the native OpenHAB binding. Basically involves a couple of Node packages, and then gives you a generic HTTP API to announce messages. I’ve now integrated these into various OpenHAB rules like so:

var String text = "Access granted. Welcome James." sendHttpGetRequest("http://localhost:5005/office/say/"+text.encode("UTF-8")+"/en-gb")

The HTTP API used also provides simple methods for playing/stopping playlists etc.

1 Like

It would be worth quite a lot if you could point me to where that tutorial is :slight_smile:

Thanks.

Heh, that’s odd, I could’ve sworn I put the link in my original message. I’ll edit it in now if I still can, but here you go: http://www.makeuseof.com/tag/send-voice-notifications-sonos-speakers/

Thanks a bunch. I now have the speakers blaring out throughout the house that it is bedtime (in Norwegian so the kids can understand) :-).

I was able to make my Sonos speek, however it looks like its either the Sonos binding from OH2 or your way using HTTP-Get. Is that correct?
It also looks like one shouldn’t use special characters for naming the players ( in my case “Küche” didn’t work)