Page 1 of 1

sonos soco plugin?

Posted: Sunday 08 February 2015 14:21
by ivom74
I saw the songs native plugin discussion. This is something else then the https://github.com/SoCo/SoCo project?

Anyone got this running on the pi together with Domotica? Must be simple to stop and start a play list then by running a script?

Re: sonos soco plugin?

Posted: Sunday 08 February 2015 15:25
by ivom74
Couldn't wait for a reply:-). I installed it and can now control the sonos.
I can now using the zwave remote to stop playing and start playing in party mode with a default volume setting(all the groups).
I can't find out the command to select a Sonos playlist by default.

Ofcourse I prefer a addin so that Sonos hardware is added and can be controlled in Domotica it self and can select a playlist but in the meanwhile just installing soco is a simple solution.

Re: sonos soco plugin?

Posted: Tuesday 24 February 2015 20:33
by dieterdde
Hey,

I'm new to Domoticz (and home automation), just got going with the rfxcomrtx 433E module to control my Somfy RTS blinds, and Applamp led strip/light bulb. Pretty neat.

How did you manage to install that Soco plugin into Domoticz, would it be possible to give me some tips?

I have a couple of Sonos speakers and I'm intrigued how to incorporate Sonos into Domoticz.

I'm running Domoticz currently from my central media server, a Windows 7 PC. In time, i plan to dedicate the Domoticz system on a Raspberry PI, but for now the central Windows 7 box is fine for testing.

Cheers

Re: sonos soco plugin?

Posted: Tuesday 24 February 2015 20:58
by ivom74
dieterdde wrote:Hey,

I'm new to Domoticz (and home automation), just got going with the rfxcomrtx 433E module to control my Somfy RTS blinds, and Applamp led strip/light bulb. Pretty neat.

How did you manage to install that Soco plugin into Domoticz, would it be possible to give me some tips?

I have a couple of Sonos speakers and I'm intrigued how to incorporate Sonos into Domoticz.

I'm running Domoticz currently from my central media server, a Windows 7 PC. In time, i plan to dedicate the Domoticz system on a Raspberry PI, but for now the central Windows 7 box is fine for testing.

Cheers
I use the soco project. You can then on raspberry in the shell give some simple commands. If it works in the shell you can make a script which is started by a virtual dummy switch in domoticz. I don't kniw of soco project works on windows.

Re: sonos soco plugin?

Posted: Wednesday 04 March 2015 21:46
by hascins
Hey I did install SoCo, too.

Can you give me the command to just stop or play something...i dont understand the documentation.

i can control the volume and mute etc of one speaker...but i cant turn off all speakers or play next song or something....i have to admit that i started playing arround with python for 3 days now :/

would be great to get some examples :)

Re: sonos soco plugin?

Posted: Thursday 05 March 2015 16:28
by ivom74
hascins wrote:Hey I did install SoCo, too.

Can you give me the command to just stop or play something...i dont understand the documentation.

i can control the volume and mute etc of one speaker...but i cant turn off all speakers or play next song or something....i have to admit that i started playing arround with python for 3 days now :/

would be great to get some examples :)
Play example :-)
#!/usr/bin/env python
from soco import SoCo

if __name__ == '__main__':
sonos = SoCo('192.168.1.105') # Pass in the IP of your Sonos speaker
sonos.partymode()
sonos.volume = 10
sonos.play()

Re: sonos soco plugin?

Posted: Friday 06 March 2015 21:28
by hascins
hey thx ivom74...that worked :D

but it just works for one speaker...of course...how do you add a second speaker or a zone?

i tried something like that, but it didnt work:

zones=list(soco.discover())

for speaker in zones:
sonos=SoCo(speaker.ip_adress)
sonos=parymode()
sonos.volume=10
sonos.play()

Re: sonos soco plugin?

Posted: Friday 06 March 2015 22:14
by ivom74
hascins wrote:hey thx ivom74...that worked :D

but it just works for one speaker...of course...how do you add a second speaker or a zone?

i tried something like that, but it didnt work:

zones=list(soco.discover())

for speaker in zones:
sonos=SoCo(speaker.ip_adress)
sonos=parymode()
sonos.volume=10
sonos.play()
I thought the partymode() command will activate all the speakers.

Re: sonos soco plugin?

Posted: Thursday 18 June 2015 19:49
by ivom74
I have a problem to turn on the playlist if the sonosbar is in TV mode.

How can switch the sonos to play the music queue if it is in TV mode?

Can't find any commands for it. I can switch to TV or LINE-IN mode but playlist/queue mode is not possible?

Re: sonos soco plugin?

Posted: Friday 19 June 2015 10:49
by ivom74
ivom74 wrote:I have a problem to turn on the playlist if the sonosbar is in TV mode.

How can switch the sonos to play the music queue if it is in TV mode?

Can't find any commands for it. I can switch to TV or LINE-IN mode but playlist/queue mode is not possible?

Solved it:

Code: Select all

#!/usr/bin/env python
import random
from soco import SoCo
sonos = SoCo('192.168.1.103')
sonos.partymode()
sonos.volume = 10
sonos.play_from_queue(random.randint(1,100))

Re: sonos soco plugin?

Posted: Friday 03 July 2015 14:42
by thorbj
Hi, I just discovered this thread about SoCo, and I've installed on my Pi.
But how do this work? I understand there is no plugin-module to Domoticz, so I can't get a graphical controller there.

Can I get it to start playing a spotify playlist as soon as a smartphone is detected, unless it is not already playing, or the TV is on?
Or can I get it to randomly start playing something during the day/evening when I am on, say, vacation, as a break-in prevention?

I belive there are many possibilities, I just need a little help getting startet.

Has anyone done something similar?

Thanks!

Re: sonos soco plugin?

Posted: Friday 03 July 2015 18:52
by G3rard
You can add a virtual switch for your Sonos and in the On and Off command you can call the script to start en stop the Sonos.

There are some others solutions as well, see this topic including some examples http://www.domoticz.com/forum/viewtopic.php?f=38&t=6088.
That are PHP files, but it will work kinda the same way.

I have used that solution, but for my frontpage I have implemented another solution because that one is easier to configure in the frontpage files.
I have also added the function to change the volume on the frontpage. See https://github.com/gerard33/frontpage.

Because you have the Sonos as a switch in this solution, you can make if/then/else actions and add timers.
The solution in my first link supports adding Spotify to the queue. It can also check if the Sonos is already playing, so yeah all your questions can be done with this solution.

Re: sonos soco plugin?

Posted: Monday 06 July 2015 11:44
by thorbj
Thank you @G3rard, I will check this out :)

Re: sonos soco plugin?

Posted: Friday 17 July 2015 8:42
by bran2000
Hi,
sorry but where i copy the folder SoCo-master ? is it on scripts folder ? (i downloaded the zip file in the site https://github.com/SoCo/SoCo)
thanks

Re: sonos soco plugin?

Posted: Wednesday 10 February 2016 20:54
by alfred_j_kwak
This is not so Domoticz related, but I have been playing with soco, Arduino and rfid-tags.
I have stack of rfid-cards and Arduino reading those. Arduino sends data to pc which runs python script. Python uses soco to select playlist from Sonos playlists and start playing. When card is removed from reader Sonos stops playing.
So basically I now have modern day cassette player...
My plan is do some custom rfid cards (maybe small album cover and title) so I don't need to reach phone or tablet to play Rammstein, just throw card onto 'player'. Project is still project, but I will upload some pictures when there is something nice to see.

Re: sonos soco plugin?

Posted: Thursday 15 December 2016 10:11
by perottol
alfred_j_kwak wrote:This is not so Domoticz related, but I have been playing with soco, Arduino and rfid-tags.
I have stack of rfid-cards and Arduino reading those. Arduino sends data to pc which runs python script. Python uses soco to select playlist from Sonos playlists and start playing. When card is removed from reader Sonos stops playing.
So basically I now have modern day cassette player...
My plan is do some custom rfid cards (maybe small album cover and title) so I don't need to reach phone or tablet to play Rammstein, just throw card onto 'player'. Project is still project, but I will upload some pictures when there is something nice to see.
Hi alfred_j_kwak,
I happend to have almost the same project as this, except I'm using a Raspberry pi. How is this project going? Would it be possible to get a sneak into your python script for this?

I'm trying to create a sonos controller for my kids. Haha, I can give them a new rfid-card every christmas and birthday.

Re: sonos soco plugin?

Posted: Friday 17 January 2020 20:57
by Damsee
Sorry for digging such an old post but i'm trying to get Sonos script to manage sounds with an alarm setup...

Regarding SoCo, it's working from command line but it's not working from script and i don't understand (since i'm not Python expert nor even noob).

Code: Select all

root@pi:~# /usr/bin/python3 -V
Python 3.7.3
root@pi:~# :~# python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import soco
>>> for zone in soco.discover():
...   print ("Name : ",zone.player_name, " - IP",zone.ip_address, " - Current volume",zone.volume)
...
Name :  Salon  - IP 192.168.1.11  - Current volume 28
Name :  Chambre  - IP 192.168.1.12  - Current volume 14
>>>
So far it's working :)

Code: Select all

root@pi:~# cat /tmp/soco.py
#!/usr/bin/python3
#
import soco
for zone in soco.discover():
  print ("Name : ",zone.player_name, " - IP",zone.ip_address, " - Current volume",zone.volume)
root@pi:~# /tmp/soco.py
Traceback (most recent call last):
  File "/tmp/soco.py", line 3, in <module>
    import soco
  File "/tmp/soco.py", line 4, in <module>
    for zone in soco.discover():
AttributeError: module 'soco' has no attribute 'discover'
root@pi:~#
It's not working while trying to use a script.

If someone has any clue ?

Note : I checked the Wiki for Sonos https://www.domoticz.com/wiki/Sonos but i don't want to use PHP, i tried "Node Sonos HTTP API"but that's using much RAM and i think SoCo (python lib) is lighter.
So if someone has a good or better way for managing Sonos (I'd like a light integration since i just wanna use to play an alarm sound if the alarm is ON)..

Thanks :D