sonos soco plugin?

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
ivom74
Posts: 52
Joined: Wednesday 03 September 2014 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

sonos soco plugin?

Post 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?
ivom74
Posts: 52
Joined: Wednesday 03 September 2014 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: sonos soco plugin?

Post 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.
dieterdde
Posts: 2
Joined: Tuesday 24 February 2015 20:26
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.2467
Location: Belgium
Contact:

Re: sonos soco plugin?

Post 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
ivom74
Posts: 52
Joined: Wednesday 03 September 2014 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: sonos soco plugin?

Post 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.
hascins
Posts: 2
Joined: Wednesday 04 March 2015 21:42
Target OS: -
Domoticz version:
Contact:

Re: sonos soco plugin?

Post 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 :)
ivom74
Posts: 52
Joined: Wednesday 03 September 2014 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: sonos soco plugin?

Post 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()
hascins
Posts: 2
Joined: Wednesday 04 March 2015 21:42
Target OS: -
Domoticz version:
Contact:

Re: sonos soco plugin?

Post 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()
ivom74
Posts: 52
Joined: Wednesday 03 September 2014 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: sonos soco plugin?

Post 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.
ivom74
Posts: 52
Joined: Wednesday 03 September 2014 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: sonos soco plugin?

Post 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?
ivom74
Posts: 52
Joined: Wednesday 03 September 2014 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: sonos soco plugin?

Post 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))
thorbj
Posts: 113
Joined: Thursday 20 November 2014 22:11
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Norway
Contact:

Re: sonos soco plugin?

Post 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!
2xRaspberry Pi Model 2 w/RaZberry z-wave chip (master/slave)|Fibaro Wall Plug|Fibaro Universal Dimmer 500W|Aeon Labs Multisensor|RFXtrx433E|Nexa WMR-1000|Nexa Pe-3|Nexa Remote|Nexa LGDR3500|Lightify Gateway|Lightify RGBW bulb
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: sonos soco plugin?

Post 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.
Not using Domoticz anymore
thorbj
Posts: 113
Joined: Thursday 20 November 2014 22:11
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Norway
Contact:

Re: sonos soco plugin?

Post by thorbj »

Thank you @G3rard, I will check this out :)
2xRaspberry Pi Model 2 w/RaZberry z-wave chip (master/slave)|Fibaro Wall Plug|Fibaro Universal Dimmer 500W|Aeon Labs Multisensor|RFXtrx433E|Nexa WMR-1000|Nexa Pe-3|Nexa Remote|Nexa LGDR3500|Lightify Gateway|Lightify RGBW bulb
bran2000
Posts: 60
Joined: Saturday 20 June 2015 10:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: sonos soco plugin?

Post 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
alfred_j_kwak
Posts: 110
Joined: Friday 20 September 2013 18:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3530
Location: Finland
Contact:

Re: sonos soco plugin?

Post 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.
perottol
Posts: 1
Joined: Thursday 15 December 2016 10:05
Target OS: -
Domoticz version:
Contact:

Re: sonos soco plugin?

Post 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.
Damsee
Posts: 58
Joined: Thursday 20 April 2017 1:17
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: sonos soco plugin?

Post 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
RPI3 Raspbian Buster + Domoticz v2020.1 stable + RFXtrx433E + Z-Stick Gen5 + Amazon Echo (alexicz)
x5 THGN810 / x5 ZMNHJD1 / x2 Flood sensor FGFS101 / x1 Smoke sensor FGSD002
x1 ZMNHAD1 / x2 FGS213 / x3 Wallplug FGWPE/F / NodOn Soft remote CRC-3-6-0
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest