Python plugin: Sonos [new version]

Python and python framework
mvzut
Posts: 429
Joined: Thursday 12 November 2015 11:55
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Python plugin: Sonos [new version]

Post by mvzut » Sunday 17 September 2017 12:32

Hi G3erard,

Thanks for all your effort, this new implementation works great for me!
One thing annoyed me though:
If you stop playback, either via the plugin or via another controller, it actually pauses. There's nothing you can do about that, that is just how Sonos is designed. However, in the paused state, the plugin keeps flooding the log with "Paused" messages, every update interval (which is 5 seconds in my case). The log page of the Sonos state device is also many pages long, almost completely filled with "Paused" states. This makes the Domoticz database unnecessarily large.
I also start a timer after I stop (pause) my Sonos Connect, which switches off the amplifier after a few minutes. But this timer was restarted every 5 seconds, because the paused state was constantly updated.

I now created a workaround, by changing a few lines in your Python code starting from line 392:

Code: Select all

#                if CurrentTransportState  == 'PAUSED_PLAYBACK':
#                    self.playerState = 2
#                    self.mediaDescription = 'Paused'
#                    UpdateDevice(1, 1, self.mediaDescription)
                if CurrentTransportState  == 'STOPPED' or CurrentTransportState  == 'PAUSED_PLAYBACK':
In this way I make the plugin treats the PAUSED state as if it was the STOPPED state (I think...). Maybe it's not a very elegant solution, but it works for me. It would obviously be nicer if the paused state is only updated once. I'll see if I can figure out how to achieve this, but if you have a good idea for this please feel free to help me (us) out!
Raspberry Pi 3 - RFXtrx433 - Aeon Z-Stick gen5 - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - Xiaomi Gateway - Sonos - IP cameras - Wall mounted tablet + Imperihome - MANY switches/sensors

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Python plugin: Sonos [new version]

Post by G3rard » Monday 18 September 2017 22:45

Hi @mvzut,
Thanks for your post! I have fixed the Paused issue in the new v0.91 release which is on Github.
https://github.com/gerard33/sonos
Just tested it and it now works as it should :)
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

josimd
Posts: 70
Joined: Saturday 09 January 2016 20:47
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Sonos [new version]

Post by josimd » Friday 22 September 2017 22:18

installed the python plugin on my Synology NAS, but received error after starting the script....anyone? Thanks!!

admin@iXXXX_NAS:/volume1/appstore/domoticz/plugins/sonos$ python plugin.py
Traceback (most recent call last):
File "plugin.py", line 41, in <module>
import Domoticz
ImportError: No module named Domoticz

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Python plugin: Sonos [new version]

Post by G3rard » Saturday 23 September 2017 0:33

josimd wrote:
Friday 22 September 2017 22:18
installed the python plugin on my Synology NAS, but received error after starting the script....anyone? Thanks!!

admin@iXXXX_NAS:/volume1/appstore/domoticz/plugins/sonos$ python plugin.py
Traceback (most recent call last):
File "plugin.py", line 41, in <module>
import Domoticz
ImportError: No module named Domoticz
Are you starting the script from the command line? That won't work, it needs to be enabled in Domoticz.
Check the Github page for the instructions.
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

josimd
Posts: 70
Joined: Saturday 09 January 2016 20:47
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Sonos [new version]

Post by josimd » Saturday 23 September 2017 20:06

G3rard wrote:
Saturday 23 September 2017 0:33
josimd wrote:
Friday 22 September 2017 22:18
installed the python plugin on my Synology NAS, but received error after starting the script....anyone? Thanks!!

admin@iXXXX_NAS:/volume1/appstore/domoticz/plugins/sonos$ python plugin.py
Traceback (most recent call last):
File "plugin.py", line 41, in <module>
import Domoticz
ImportError: No module named Domoticz
Are you starting the script from the command line? That won't work, it needs to be enabled in Domoticz.
Check the Github page for the instructions.
Hi Gerard, just checked it, I have domoticz running on a Synology NAS, Python 3 package is installed, also the domoticz version has the Python plugin included... but still no Sonos in the hardware tab... hope you can direct me in the right way ;-)

florisi
Posts: 43
Joined: Saturday 30 July 2016 10:14
Target OS: Raspberry Pi
Domoticz version: v4.9732
Location: Arnhem
Contact:

Re: Python plugin: Sonos [new version]

Post by florisi » Saturday 23 September 2017 20:37

I have the same issue.
Installed on a Synology.
No errors, and in the plugin directory there was created a Sonos-dir with plugin.py and a couple of zip-files.
Rebooted the Synology bu still no Sonos hardware.

niclasc
Posts: 63
Joined: Wednesday 09 December 2015 18:04
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Sweden
Contact:

Re: Python plugin: Sonos [new version]

Post by niclasc » Sunday 24 September 2017 10:50

Cant find Sonos Players under hardware. I have python3 and python3-dev installed and have restarted Domoticz

rathmannm
Posts: 25
Joined: Sunday 10 January 2016 19:56
Target OS: Raspberry Pi
Domoticz version: 3.8153
Contact:

Re: Python plugin: Sonos [new version]

Post by rathmannm » Thursday 28 September 2017 19:04

Hi,

it's great to see the plugin continues to be developed. I have an issue however - if I stream from Spotify directly to Sonos it shows up as "Grouped" even though it is technically not. This means none of the controls work. I understand grouping control as such is not supported but any chance to address this bug?

Thanks,
Manuel

josimd
Posts: 70
Joined: Saturday 09 January 2016 20:47
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Sonos [new version]

Post by josimd » Saturday 30 September 2017 21:43

josimd wrote:
Saturday 23 September 2017 20:06
G3rard wrote:
Saturday 23 September 2017 0:33
josimd wrote:
Friday 22 September 2017 22:18
installed the python plugin on my Synology NAS, but received error after starting the script....anyone? Thanks!!

admin@iXXXX_NAS:/volume1/appstore/domoticz/plugins/sonos$ python plugin.py
Traceback (most recent call last):
File "plugin.py", line 41, in <module>
import Domoticz
ImportError: No module named Domoticz
Are you starting the script from the command line? That won't work, it needs to be enabled in Domoticz.
Check the Github page for the instructions.
Hi Gerard, just checked it, I have domoticz running on a Synology NAS, Python 3 package is installed, also the domoticz version has the Python plugin included... but still no Sonos in the hardware tab... hope you can direct me in the right way ;-)
Anyone solved this issue?

josimd
Posts: 70
Joined: Saturday 09 January 2016 20:47
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Sonos [new version]

Post by josimd » Sunday 08 October 2017 18:05

josimd wrote:
Saturday 30 September 2017 21:43
josimd wrote:
Saturday 23 September 2017 20:06
G3rard wrote:
Saturday 23 September 2017 0:33

Are you starting the script from the command line? That won't work, it needs to be enabled in Domoticz.
Check the Github page for the instructions.
Hi Gerard, just checked it, I have domoticz running on a Synology NAS, Python 3 package is installed, also the domoticz version has the Python plugin included... but still no Sonos in the hardware tab... hope you can direct me in the right way ;-)
Anyone solved this issue?
Issue resolved, installed the wrong domoticz version, updated with the python plugin... works like a charm... :D

vgr2
Posts: 91
Joined: Monday 29 August 2016 12:02
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Sonos [new version]

Post by vgr2 » Friday 27 October 2017 17:13

Hi, plugin is working with my new Sonos one, but how can I get my Radio favorites from Sonos?

Mdieli
Posts: 14
Joined: Saturday 14 February 2015 12:18
Target OS: Linux
Domoticz version: BETA
Location: The Netherlands
Contact:

Re: Python plugin: Sonos [new version]

Post by Mdieli » Sunday 19 November 2017 10:26

For some reason, I can't get the plugin visable from the drop-down in the Hardware menu.

System: RPi 3
Domoticz: V3.8742
Python3: 3.5.3
Installed in the "~/domoticz/plugins/sonos" folder.
Restarted Domoticz from the commandline but the plugin is nowhere to be found.
Also, no errors are shown in the Domoticz log.

The funny thing is, I reinstalled the Pi a week or 2 ago, and on the previous installation, it worked like a charm.

EDIT: /Facepalm.... I forget to install python3-dev...
For future persons with similar issues: "sudo apt-get install python3-dev" and afterwards restart Domoticz.

mvzut
Posts: 429
Joined: Thursday 12 November 2015 11:55
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Python plugin: Sonos [new version]

Post by mvzut » Tuesday 21 November 2017 9:02

Plugin works great, using it for a few months now. I just started to use the notification system as well, this is working perfectly too.

I had one problem with notifications though: I have programmed a lot of generic notifications in LUA scripts (using the commandArray['SendNotification'] command). This gave errors, since these notifications are normally sent to all notification systems, and the Sonos notification system doesn't know what to do with a simple text notification.

The answer turned out to be pretty simple, see viewtopic.php?p=116009#p116009
Since one of the recent beta versions, it is possible to indicate which notification systems to use in LUA. This solved it for me. Maybe others with similar problems can be helped with this information too.
Raspberry Pi 3 - RFXtrx433 - Aeon Z-Stick gen5 - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - Xiaomi Gateway - Sonos - IP cameras - Wall mounted tablet + Imperihome - MANY switches/sensors

BakSeeDaa
Posts: 551
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi
Domoticz version:

Re: Python plugin: Sonos [new version]

Post by BakSeeDaa » Wednesday 06 December 2017 20:26

Hi all!

Since I bought a couple of Sonos One I've been experimenting with a Node-js project based on the great Node.js work node-sonos-http-api. I get all player state changes and tracks information pushed into Domoticz and it's updating lighting fast.There is no need for making Domoticz constantly pulling for any data changes. I also use it also for speaking TTS messages in different languages.

Initially I experienced some problems with that Domoticz sent multiple TTS messages and state request changes in a very short time and some of them were never carried out resulting in unpredictable results. I solved that with a task spooler so that every command is executed one by one. I don't know how this plugin has addressed such a scenario.

I sent a pm to @G3rard about if using based on the great Node.js work node-sonos-http-api would be an interesting approach for this Sonos Python Plugin but I haven't had any reply until now.

So to summarize, I've created yet another Sonos Integration project for Domoticz and maybe it doesn't introduce anything new that isn't already available. In such a case there would be no idea for me to share the work. :D

Cheers

Kurtsejr
Posts: 3
Joined: Tuesday 05 December 2017 0:01
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Sonos [new version]

Post by Kurtsejr » Friday 15 December 2017 21:20

It does not work for me, sorry - cant fint Sonos in the drop-down menu

System: RPi 3
Domoticz: V3.8789
Installed in the "~/domoticz/plugins/sonos" folder.
Restarted Domoticz from the commandline
no errors in the Domoticz log.
And I do have the python3-dev installed too
the plugin.py are owned by user pi, but has "755" rights

Any idear?

br Kurt

hvoordes
Posts: 1
Joined: Saturday 16 December 2017 15:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python plugin: Sonos [new version]

Post by hvoordes » Saturday 16 December 2017 16:09

Hello,

I'm having the same problem. None of the plugins is shown in the pull down under hardware.

System: Synlogy DS216j
Domoticz: 3.8770

Where can I find the path for the plugins in the source code? Just to check if I placed the plugins in the right location.
Current location: /usr/local/domoticz/plugins

btw: Trying to get the Sonos plugin visible under hardware.

Kurtsejr
Posts: 3
Joined: Tuesday 05 December 2017 0:01
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Sonos [new version]

Post by Kurtsejr » Sunday 17 December 2017 16:40

Hi all

Still not working for me
According to https://www.domoticz.com/wiki/Using_Python_plugins
It should be possible to fint this in the logfile (setup/log):

PluginSystem: Started, Python version '3.x.y'

But I can't fint this, for me this means that Domoticz does not know my Python needs - is there a setup posibility that I need to set?

/Kurt

Kurtsejr
Posts: 3
Joined: Tuesday 05 December 2017 0:01
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Sonos [new version]

Post by Kurtsejr » Saturday 30 December 2017 18:50

SOLVED !!!!!!
We need to enable EventSystem in the setup menu.

Then it all works :oops:

Rodio
Posts: 40
Joined: Thursday 16 April 2015 10:18
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Sonos [new version]

Post by Rodio » Wednesday 03 January 2018 10:00

Hi,

This plugin works great, great work THX, but .......... ;)
I found a weird type of behaviour.
I've changed the setting of SononsKeuken/Slaapkamer of the Refresh radio list from false to true.
This works, but look at the screenshots.
The 2 newly created devices will (after a restart of domoticz) be the last IDX devices.
They started there journey as IDX 15 and 16 and have now IDX 163 and 164 :roll:

For me it's not a problem, but found it a bit weird.

Using RPI3, jessie, Domoticz 3.8153, SonosPlugin 0,91, python2.7.9

R
Attachments
Schermafbeelding 2018-01-03 om 08.41.15.png
Schermafbeelding 2018-01-03 om 08.41.15.png (174.47 KiB) Viewed 1604 times
Schermafbeelding 2018-01-03 om 08.40.36.png
Schermafbeelding 2018-01-03 om 08.40.36.png (160.14 KiB) Viewed 1604 times

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Python plugin: Sonos [new version]

Post by G3rard » Saturday 06 January 2018 2:16

@Rodio, thanks for your post.
That indeed happens when you have set 'Refresh radio list:' to True in the Hardware settings.
Then with every restart of the plugin the old devices will be deleted and new ones will be created with the updated radio stations.

So if you set this to False no new devices will be made after a restart.

I have made it like this because that's the only way the list with radio stations can be updated.
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

Post Reply

Who is online

Users browsing this forum: moroen and 2 guests