Page 4 of 5
Re: Easy Sonos
Posted: Tuesday 19 January 2016 13:23
by HansLe
YEEEEEEESSSSS! I'm able to use TTS on a RPI. As you can read Thorjb had some problems. I had the same. This problem exist when you don't use a file share but you use your RPI as place to read and find the MP3 files. I hope G3rard will change the following recommendations in the source files. If not you can do it by yourself after downloading these file
In file sonos.php change line 438
Code: Select all
$this->_PHPSonos->SetAVTransportURI('x-file-cifs:' . $this->_config['messagePath'] . $messageId . '.mp3');
to
Code: Select all
$this->_PHPSonos->SetAVTransportURI($this->_config['messagePath'] . $messageId . '.mp3');
In file config.php you can find the following lines:
Code: Select all
'messagePath' => '//<yourpath>/sonos/spraak/',
'messageStorePath' => '//<yourpath>/sonos/spraak/',
If you use a RPI, change to:
Code: Select all
'messagePath' => 'http://xxx.xx.x.xx/sonos/spraak/', // for f.e. a RPI
'messageStorePath' => 'http://xxx.xx.x.xx/sonos/spraak/',
xxx.xx.x.xx is the IP adres of you RPI server (Domoticz).
On your RPI excute the command: sudo chmod +777 /var/www/sonos/spraak

- sonos-spraak.JPG (56.69 KiB) Viewed 9873 times
If you use a network share change to
Code: Select all
'messagePath' => 'x-file-cifs://<yourpath>/spraak/', // for network share
'messageStorePath' => 'x-file-cifs://<yourpath>/spraak/',
Now is EasySonos Easy

Re: Easy Sonos
Posted: Tuesday 19 January 2016 18:01
by Philosifer
I'm struggling to get PHPSonos to work so I can use HansLe alarm script idea.
Running on debian. I've installed apache, php5-curl and php5-cli.
I can make the Sonos play with EasySonos like this
Code: Select all
<?php
$IP_sonos_1 = "192.168.23.180";
require("sonos.class.php");
$sonos_1 = new SonosPHPController($IP_sonos_1);
$sonos_1 = $sonos_1->Play();
?>
but PHPSonos won't do anything.
Code: Select all
<?php
require ("PHPSonos.inc.php");
$ip = "192.168.23.180";
$sonos = new PHPSonos($ip); // no check on valid IP address!
$sonos->Play();
?>
Eventually comes back with
PHP Fatal error: Uncaught exception 'Exception' with message 'Error sending command: HTTP/1.1 408 Request Timeout
Content-type: text/html
Server: Linux UPnP/1.0 Sonos/31.3-22220 (ZPS3)
Connection: close
Error 408Error 408Request Timeout' in /home/phil/domoticz/scripts/php/PHPSonos.inc.php:1975
Stack trace:
#0 /home/phil/domoticz/scripts/php/PHPSonos.inc.php(801): PHPSonos->sendPacket('POST /MediaRend...')
#1 /home/phil/domoticz/scripts/php/PHPsonos.test.php(12): PHPSonos->Play()
#2 {main}
thrown in /home/phil/domoticz/scripts/php/PHPSonos.inc.php on line 1975
Anyone any suggestions?
Phil
Re: Easy Sonos
Posted: Tuesday 19 January 2016 23:43
by HansLe
Have you downloaded all these files:
https://github.com/gerard33/sonos .... and copied them in the same directory as your script?
Re: Easy Sonos
Posted: Tuesday 19 January 2016 23:56
by Philosifer
I hadn't got the 3 wrapper scripts but I've just tried them and it didn't make any different.
Tomorrow I'll see if I can put in some debug lines to find out what its trying to send to the Sonos. I suspect there's another component I need to install that's already bundled in for those of you using RPi.
Re: Easy Sonos
Posted: Wednesday 20 January 2016 20:51
by HansLe
G3rard wrote:StanHD wrote:
My Domoticz is running on a Windows 7 NUC PC. So do I need to add a web server there? How do I do that?
Apologies for the basic questions

The PHP files don't have to be on the same server as your Domoticz is running on. Do you have a Raspberry pi or NAS you can use as web server?
Otherwise you can check
http://www.easyphp.org/ for installing on your NUC PC.
See
https://www.apachefriends.org/index.html. XAMPP is an easy to use installation of an Apache server and PHP.
Re: Easy Sonos
Posted: Thursday 21 January 2016 19:49
by Philosifer
Philosifer wrote:I hadn't got the 3 wrapper scripts but I've just tried them and it didn't make any different.
Tomorrow I'll see if I can put in some debug lines to find out what its trying to send to the Sonos. I suspect there's another component I need to install that's already bundled in for those of you using RPi.
I finally worked out what was wrong with my setup. Posting the explanation for those who may follow
The problem was with end of line characters in my PHPSonos.inc.php I redownloaded the file and it all sprang to life.
using VI they looked the same but ":set list" revealed the problem
Code: Select all
^Ipublic function Play()$
^I{$
$content='POST /MediaRenderer/AVTransport/Control HTTP/1.1$
CONNECTION: close$
HOST: '.$this->address.':1400$
CONTENT-LENGTH: 266$
CONTENT-TYPE: text/xml; charset="utf-8"$
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play"$
$
Whereas the working file
Code: Select all
public function Play()^M
{^M
^M
$content='POST /MediaRenderer/AVTransport/Control HTTP/1.1^M
CONNECTION: close^M
HOST: '.$this->address.':1400^M
CONTENT-LENGTH: 266^M
CONTENT-TYPE: text/xml; charset="utf-8"^M
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play"^M
^M
I think the PHP worked ok but the SOAP calls didn't like the difference.
I now have a working Sonos doorbell thanks HansLe

Re: Easy Sonos
Posted: Thursday 21 January 2016 22:01
by HansLe
Philosifer wrote:Philosifer wrote:I hadn't got the 3 wrapper scripts but I've just tried them and it didn't make any different.
Tomorrow I'll see if I can put in some debug lines to find out what its trying to send to the Sonos. I suspect there's another component I need to install that's already bundled in for those of you using RPi.
I finally worked out what was wrong with my setup. Posting the explanation for those who may follow
The problem was with end of line characters in my PHPSonos.inc.php I redownloaded the file and it all sprang to life.
using VI they looked the same but ":set list" revealed the problem
Code: Select all
^Ipublic function Play()$
^I{$
$content='POST /MediaRenderer/AVTransport/Control HTTP/1.1$
CONNECTION: close$
HOST: '.$this->address.':1400$
CONTENT-LENGTH: 266$
CONTENT-TYPE: text/xml; charset="utf-8"$
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play"$
$
Whereas the working file
Code: Select all
public function Play()^M
{^M
^M
$content='POST /MediaRenderer/AVTransport/Control HTTP/1.1^M
CONNECTION: close^M
HOST: '.$this->address.':1400^M
CONTENT-LENGTH: 266^M
CONTENT-TYPE: text/xml; charset="utf-8"^M
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play"^M
^M
I think the PHP worked ok but the SOAP calls didn't like the difference.
I now have a working Sonos doorbell thanks HansLe

Great you got it working! Thanks for the credits but other did far more to get this working as I did. I solved just a small problem when using a PI as webserver. Besides the alarm sound I download just as you a doorbell sound

Re: Easy Sonos
Posted: Friday 22 January 2016 0:47
by G3rard
HansLe wrote:YEEEEEEESSSSS! I'm able to use TTS on a RPI. As you can read Thorjb had some problems. I had the same. This problem exist when you don't use a file share but you use your RPI as place to read and find the MP3 files. I hope G3rard will change the following recommendations in the source files. If not you can do it by yourself after downloading these file
I tested it on my NAS and it's working fine so I merged your pull request.
Thanks for the update.
Re: Easy Sonos
Posted: Friday 22 January 2016 19:01
by nizaga
hi,
i am running Easy Sonos on my RPI2. Everything works fine but the PlayTTS.
What do i have to specify in the call PlayTTS(string message,string station,int volume,string lang) as station?? I have tried my "<myRIP_IP>/sonos" but it does not work.... i am sure i am making the wrong call but i can't find it....
Further, i get the following when i run PlayTSS
PHP Notice: Undefined offset: 1 in /home/pi/scripts/sonos.class.php on line 54
PHP Notice: Undefined offset: 1 in /home/pi/scripts/sonos.class.php on line 54
PHP Notice: Undefined offset: 1 in /home/pi/scripts/sonos.class.php on line 54
Is this normal?
Thanks very much!!!
Nacho
BTW, i also downloaded the html sonos.class.php ... jajaja....
Re: Easy Sonos
Posted: Friday 22 January 2016 19:08
by nizaga
ok, i found out reading the php code if have to enter the php code i have to enter "param string radio name display on sonos controller"..
I still can't make it to work but i realized the first time i test it (using a new message text) i get:
PHP Warning: file_get_contents(
http://translate.google.com/translate_tts?q=hola1&tl=fr): failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable
in /home/pi/scripts/sonos.class.php on line 412
Then, the mp3 is downloaded in the audio folder...
What is wrong???
Thanks!
Re: Easy Sonos
Posted: Friday 22 January 2016 22:42
by G3rard
Google TTS is not working anymore when used from a script (at least not in an easy way).
You can try
https://github.com/gerard33/sonos.
It is a bit different then the scripts in the topic start, so please check the readme.
In these files I changed the Google TTS to voicerss.org TTS and that is working fine.
Re: Easy Sonos
Posted: Saturday 23 January 2016 14:06
by HansLe
nizaga wrote:ok, i found out reading the php code if have to enter the php code i have to enter "param string radio name display on sonos controller"..
I still can't make it to work but i realized the first time i test it (using a new message text) i get:
PHP Warning: file_get_contents(
http://translate.google.com/translate_tts?q=hola1&tl=fr): failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable
in /home/pi/scripts/sonos.class.php on line 412
Then, the mp3 is downloaded in the audio folder...
What is wrong???
Thanks!
Nizaga, please start with an easy test.
Download the files G3rard mentioned in the previous post and then start with the simple start en stop scripts I mentioned (
viewtopic.php?f=38&t=6088&start=40#p70561).
Re: Easy Sonos
Posted: Wednesday 17 February 2016 23:18
by techoguy
Hi All,
I'm new to the forums but have been messing with Home Automation for awhile now. Currently I use EventGhost for a lot of my automation but have been intereseted in checking out other options like Domoticz.
I currently have deap integration with SONOS from a plugin that I created and use every day. I'm curious if anyone can tell me if the script everyone is using here only works with one SONOS device or works with a bunch. Meaning does it handle grouping and ungrouping players?
Re: Easy Sonos
Posted: Thursday 18 February 2016 9:13
by kalinkamaen
Hello Techoguy!!
I am happy to see you on the Domoticz forum. You made a great job with the Sonos plugin on Eventghost.
I do not no much about this or the other Sonos plugins, because I have never tried it.
But as far as I can tell, Domoticz need a guy like you to implement Sonos plugin for us all. This should have been done
a long time ago.
Re: Easy Sonos
Posted: Friday 19 February 2016 16:19
by wmn79
techoguy wrote:Hi All,
I'm new to the forums but have been messing with Home Automation for awhile now. Currently I use EventGhost for a lot of my automation but have been intereseted in checking out other options like Domoticz.
I currently have deap integration with SONOS from a plugin that I created and use every day. I'm curious if anyone can tell me if the script everyone is using here only works with one SONOS device or works with a bunch. Meaning does it handle grouping and ungrouping players?
I think the most used here is the wrapper of thomas_tr of the on that is forked from it by G3rard. Both are using the phpsonos class that can be found here:
https://www.symcon.de/forum/threads/149 ... post133623
I am not sure if it can group and ungroup speakers. I know the Soco plugin does have a party mode and a possibility to ungroup speakers from the group. The links to the different available methods that are used for Sonos in Domoticz are on the wiki page:
https://www.domoticz.com/wiki/Sonos hope it helps.
Re: Easy Sonos
Posted: Friday 05 August 2016 15:26
by Tcar79
Hi All,
I'm a one month greenhorn on Domoticz, but really liking and getting the hang of it! I started with connecting my current devices (temp, hue, sonos) to create a Frontpage and thx to G3rard and a lot of others I came really far. The sonos was the most difficult on my raspberry, but I got it working! Yihaa!
I integrated my sonos via the wrapper of thomas_tr that is forked by G3rard. This works in Domoticz and in the frontpage which is very nice! I only have a problem if I use my tv/television on the playbar.
Is there a way/phpscript to switch between audio(radio or spotify) and tv? Or from TV to Audio? I searched a lot, but cannot find anything for the php method. I would like to create a virtual switch where I can toggle between tv and radio.
I found the possibility using the soco plugin, but since I already use the php method I hoped anybody would know.
OT: searching for tv is drama in a forum (2 short), so a television for other searchers.
Re: Easy Sonos
Posted: Saturday 06 August 2016 15:11
by G3rard
Re: Easy Sonos
Posted: Saturday 06 August 2016 18:51
by Tcar79
Thx. Not directly the wright direction, but it got me going with the URI’s. I went back to the basics of Easy sonos with the sonos.class.php and managed to make a switch that (when on) switches to the tv. I do get an error if executed through bash, but it works from domoticz. Cool!
Code: Select all
#! /usr/bin/php
<?php
$IP_sonos_1 = "192.168.178.13";
require("sonos.class.php");
$sonos_1 = new SonosPHPController($IP_sonos_1);
$sonos_1->RemoveAllTracksFromQueue(); //Playlist löschen / delete pl
$sonos_1->AddURIToQueue("x-sonos-htastream:RINCON_B8E937734D1501400:spdif"); //Datei hinzufügen, Fill with URI from tv
//Playlist auswählen (Nötig, wenn Radio vorher ausgewählt war) / select pl - this is needed after playin radio
$sonos_1->SetQueue("x-sonos-htastream:RINCON_B8E937734D1501400:spdif"); //Fill with URI from tv
$sonos_1->Play();
?>
After that I got lots of problems because sonos is completely taken over by the television.
• I cannot switch to radio, The same script with a radio URI doesn’t work.
• I cannot stop/pause the tv,
• Volume up / down works
• Getting the status is a thing I haven’t even begun yet (frontpage gives “|ONBEKEND” when tv is on)
Any idea's?
I don't have much php experiance, so I'm learning along the way. I see some code in PHPSonos.inc.php about the setRadio but I haven’t deciphered that yet.
Re: Easy Sonos
Posted: Saturday 06 August 2016 22:50
by G3rard
Yeah I meant the use of the URI's from that post
Maybe you can have a look at
https://github.com/gerard33/sonos/blob/ ... s.php#L277. I added that code to switch between radio stations defined in config.php. Maybe you can use that to go back to a radio station?
As I don't have a playbar I can't reproduce this so you have to do some trial and error

Re: Easy Sonos
Posted: Saturday 08 October 2016 20:51
by josimd
Hi, hope that anyone can help me with the following issue..

I have copied the script (3 files) from the Easy sonos wiki... I'm running Domoticz on a Synology NAS
sonos.pause.php:
<?php
class SonosPHPController
$IP_sonos_1 = “192.168.0.66”;
require(“sonos.class.php”);
$sonos_1 = new SonosPHPController($IP_sonos_1);
$sonos_1 = $sonos_1->Play();
?>
after chmod u+x I want to start te script but get the error....
php sonos.pause.php
error:
PHP Parse error: syntax error, unexpected '\' (T_NS_SEPARATOR) in /volume1/@appstore/cron/sonos.pause.php on line 17
Parse error: syntax error, unexpected '\' (T_NS_SEPARATOR) in /volume1/@appstore/cron/sonos.pause.php on line 17