Easy Sonos

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

HansLe
Posts: 25
Joined: Wednesday 13 January 2016 21:12
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.3530
Location: Netherlands
Contact:

Re: Easy Sonos

Post 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
sonos-spraak.JPG (56.69 KiB) Viewed 9681 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 :D
Raspberry Pi B+ | Domoticz v3.4834 | RFXtrx433E | Action sockets and remote control (a cheap solution to start with)
Sonos device: control via Action remote control and EasySonos (via Domoticz scripts)
2 x Chresta TX320, Kaku sensoren, D-link camera
Philosifer
Posts: 17
Joined: Thursday 07 January 2016 18:38
Target OS: Linux
Domoticz version: 2.4223
Location: United Kingdom
Contact:

Re: Easy Sonos

Post 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
HansLe
Posts: 25
Joined: Wednesday 13 January 2016 21:12
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.3530
Location: Netherlands
Contact:

Re: Easy Sonos

Post by HansLe »

Have you downloaded all these files: https://github.com/gerard33/sonos .... and copied them in the same directory as your script?
Raspberry Pi B+ | Domoticz v3.4834 | RFXtrx433E | Action sockets and remote control (a cheap solution to start with)
Sonos device: control via Action remote control and EasySonos (via Domoticz scripts)
2 x Chresta TX320, Kaku sensoren, D-link camera
Philosifer
Posts: 17
Joined: Thursday 07 January 2016 18:38
Target OS: Linux
Domoticz version: 2.4223
Location: United Kingdom
Contact:

Re: Easy Sonos

Post 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.
HansLe
Posts: 25
Joined: Wednesday 13 January 2016 21:12
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.3530
Location: Netherlands
Contact:

Re: Easy Sonos

Post 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 :oops:
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.
Raspberry Pi B+ | Domoticz v3.4834 | RFXtrx433E | Action sockets and remote control (a cheap solution to start with)
Sonos device: control via Action remote control and EasySonos (via Domoticz scripts)
2 x Chresta TX320, Kaku sensoren, D-link camera
Philosifer
Posts: 17
Joined: Thursday 07 January 2016 18:38
Target OS: Linux
Domoticz version: 2.4223
Location: United Kingdom
Contact:

Re: Easy Sonos

Post 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 :D
HansLe
Posts: 25
Joined: Wednesday 13 January 2016 21:12
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.3530
Location: Netherlands
Contact:

Re: Easy Sonos

Post 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 :D
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 :D
Raspberry Pi B+ | Domoticz v3.4834 | RFXtrx433E | Action sockets and remote control (a cheap solution to start with)
Sonos device: control via Action remote control and EasySonos (via Domoticz scripts)
2 x Chresta TX320, Kaku sensoren, D-link camera
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: Easy Sonos

Post 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.
Not using Domoticz anymore
nizaga
Posts: 69
Joined: Monday 30 November 2015 11:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Easy Sonos

Post 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....
nizaga
Posts: 69
Joined: Monday 30 November 2015 11:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Easy Sonos

Post 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!
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: Easy Sonos

Post 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.
Not using Domoticz anymore
HansLe
Posts: 25
Joined: Wednesday 13 January 2016 21:12
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.3530
Location: Netherlands
Contact:

Re: Easy Sonos

Post 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).
Raspberry Pi B+ | Domoticz v3.4834 | RFXtrx433E | Action sockets and remote control (a cheap solution to start with)
Sonos device: control via Action remote control and EasySonos (via Domoticz scripts)
2 x Chresta TX320, Kaku sensoren, D-link camera
techoguy
Posts: 1
Joined: Wednesday 17 February 2016 23:14
Target OS: Windows
Domoticz version:
Contact:

Re: Easy Sonos

Post 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?
kalinkamaen
Posts: 52
Joined: Sunday 04 January 2015 15:57
Target OS: Windows
Domoticz version: 2022.2
Location: Norway
Contact:

Re: Easy Sonos

Post 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.
Windows 10, Domoticz 14784
wmn79
Posts: 27
Joined: Monday 13 April 2015 23:19
Target OS: NAS (Synology & others)
Domoticz version: 3.5033
Location: Amsterdam, The Netherlands
Contact:

Re: Easy Sonos

Post 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.
Tcar79
Posts: 11
Joined: Thursday 21 July 2016 10:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Easy Sonos

Post 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.
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: Easy Sonos

Post by G3rard »

Maybe this topic can help you to switch to TV http://forum.micasaverde.com/index.php? ... #msg241518?
Not using Domoticz anymore
Tcar79
Posts: 11
Joined: Thursday 21 July 2016 10:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Easy Sonos

Post by Tcar79 »

G3rard wrote:Maybe this topic can help you to switch to TV http://forum.micasaverde.com/index.php? ... #msg241518?
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.
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: Easy Sonos

Post by G3rard »

Yeah I meant the use of the URI's from that post :mrgreen:

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 ;)
Not using Domoticz anymore
josimd
Posts: 59
Joined: Saturday 09 January 2016 19:47
Target OS: -
Domoticz version:
Contact:

Re: Easy Sonos

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest