Python plugin: Sonos [new version]

Python and python framework

Moderator: leecollings

mvzut
Posts: 443
Joined: Thursday 12 November 2015 10:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Python plugin: Sonos [new version]

Post by mvzut »

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 4 - RFXtrx433 - CC2531 Zigbee - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - 6 x Sonos - 4 x IP cameras - Wall mounted tablet + Dashticz - Google Home integration - MANY switches/sensors
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: Python plugin: Sonos [new version]

Post by G3rard »

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

Re: Python plugin: Sonos [new version]

Post by josimd »

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

Re: Python plugin: Sonos [new version]

Post by G3rard »

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

Re: Python plugin: Sonos [new version]

Post by josimd »

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: 78
Joined: Saturday 30 July 2016 10:14
Target OS: Linux
Domoticz version: 2020beta
Location: Arnhem
Contact:

Re: Python plugin: Sonos [new version]

Post by florisi »

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: 28
Joined: Wednesday 09 December 2015 17:04
Target OS: Linux
Domoticz version: 4.10854
Location: Sweden
Contact:

Re: Python plugin: Sonos [new version]

Post by niclasc »

Cant find Sonos Players under hardware. I have python3 and python3-dev installed and have restarted Domoticz
rathmannm
Posts: 15
Joined: Sunday 10 January 2016 18:56
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Contact:

Re: Python plugin: Sonos [new version]

Post by rathmannm »

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: 59
Joined: Saturday 09 January 2016 19:47
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Sonos [new version]

Post by josimd »

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: 59
Joined: Saturday 09 January 2016 19:47
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Sonos [new version]

Post by josimd »

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: 71
Joined: Monday 29 August 2016 12:02
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Sonos [new version]

Post by vgr2 »

Hi, plugin is working with my new Sonos one, but how can I get my Radio favorites from Sonos?
Mdieli
Posts: 12
Joined: Saturday 14 February 2015 11:18
Target OS: Linux
Domoticz version: BETA
Location: The Netherlands
Contact:

Re: Python plugin: Sonos [new version]

Post by Mdieli »

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: 443
Joined: Thursday 12 November 2015 10:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Python plugin: Sonos [new version]

Post by mvzut »

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 4 - RFXtrx433 - CC2531 Zigbee - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - 6 x Sonos - 4 x IP cameras - Wall mounted tablet + Dashticz - Google Home integration - MANY switches/sensors
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: Python plugin: Sonos [new version]

Post by BakSeeDaa »

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: 24
Joined: Monday 04 December 2017 23:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Danmark
Contact:

Re: Python plugin: Sonos [new version]

Post by Kurtsejr »

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 14:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python plugin: Sonos [new version]

Post by hvoordes »

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: 24
Joined: Monday 04 December 2017 23:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Danmark
Contact:

Re: Python plugin: Sonos [new version]

Post by Kurtsejr »

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: 24
Joined: Monday 04 December 2017 23:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Danmark
Contact:

Re: Python plugin: Sonos [new version]

Post by Kurtsejr »

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

Then it all works :oops:
Rodio
Posts: 39
Joined: Thursday 16 April 2015 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Sonos [new version]

Post by Rodio »

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 3933 times
Schermafbeelding 2018-01-03 om 08.40.36.png
Schermafbeelding 2018-01-03 om 08.40.36.png (160.14 KiB) Viewed 3933 times
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: Python plugin: Sonos [new version]

Post by G3rard »

@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.
Not using Domoticz anymore
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest