Python plugin: Sonos [old version]

Python and python framework

Moderator: leecollings

HomeAutomation
Posts: 9
Joined: Saturday 28 February 2015 19:52
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6838
Location: The Netherlands
Contact:

Re: Python plugin: Sonos

Post by HomeAutomation »

tester22 wrote:
RayAmsterdam wrote:
bdormael wrote: Now I have the voice fields, so I have added my key and language for each of my devices, but what do I need to do now to test it ?
(how can I send a line of text to a certain device ?)
I've got the same question. Another question: Does it restore to the same state as before playing the tts?
Right now it does not resume state. But I think I will reverse this since I have found an problem without any possible solution. If the players load data straight from Voicerss it interprets is as radio, hence it repeats the message indefinitely. Node-Sonos have solved that by downloading the data and expose it using an internal http server. This is not posdible ewith the current Domoticz python framework and all workaround includes adding additional components and that is something I want to avoid.
@tester22, how's live going?
After your last reply about the issue with TTS, it's quiet in this topic.
As a user of your plugin I'm curious about your plans with the pluging. In other words: What's in the pipeline for the next 2 months?

With regards,
Jan
Heursqem
Posts: 18
Joined: Sunday 20 March 2016 14:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Sonos

Post by Heursqem »

I have the plugin working, great!!!

This is what I would love to achieve

#1 - Someone pushes my doorbell
#2 - I capture the current state of my sonos player (medium, song, volume etc) and save this for later
#3 - I play my own sound through the sonos player (ding-dong)
#4 - I go back to to captured/saved state and listen to original music again

Would all of this be possible with this sonos plugin?
pvdhelm
Posts: 29
Joined: Tuesday 14 March 2017 17:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Skendel
Contact:

Re: Python plugin: Sonos

Post by pvdhelm »

can't find the sonos controller.
I'm on the latest beta version of domotics
placed the files in the /domoticz/plugins/Sonos directory.
restarted the server.
in hardware i can't find Sonos.

what goes wrong here??
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

Post by mvzut »

pvdhelm wrote:can't find the sonos controller.
I'm on the latest beta version of domotics
placed the files in the /domoticz/plugins/Sonos directory.
restarted the server.
in hardware i can't find Sonos.

what goes wrong here??
Do you have Python installed?
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
pvdhelm
Posts: 29
Joined: Tuesday 14 March 2017 17:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Skendel
Contact:

Re: Python plugin: Sonos

Post by pvdhelm »

yep python is installed.

got it working now but server crashes every 30 minutes. Now try a fresh installation of the server and sonos plugin.
tomorrow i let you know if this works

tnx
tester22
Posts: 49
Joined: Tuesday 20 December 2016 17:43
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Sweden
Contact:

Re: Python plugin: Sonos

Post by tester22 »

dhanjel wrote:It would be nice to be able to set the media source (Sonos favourite for instance), if possible.

I currently use a nodejs middle tier for doing that, and it would be nice to get rid of external dependencies.

I use it to automatically play some lounge music in the bathroom when there is motion :)
How would you suggest that it is displayed in the ui in an generic way?
tester22
Posts: 49
Joined: Tuesday 20 December 2016 17:43
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Sweden
Contact:

Re: Python plugin: Sonos

Post by tester22 »

Heursqem wrote:
dhanjel wrote:It would be nice to be able to set the media source (Sonos favourite for instance), if possible.

I currently use a nodejs middle tier for doing that, and it would be nice to get rid of external dependencies.

I use it to automatically play some lounge music in the bathroom when there is motion :)
Is it (already) possible to do this with core plugin? Would be really great feauture.

Cheers
Heursqem
Not possible right now. Tecnically it is not so advanced but I have no idea on how to create the gui for it.
Last edited by tester22 on Friday 24 March 2017 20:57, edited 1 time in total.
tester22
Posts: 49
Joined: Tuesday 20 December 2016 17:43
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Sweden
Contact:

Re: Python plugin: Sonos

Post by tester22 »

HomeAutomation wrote:
tester22 wrote:
RayAmsterdam wrote: I've got the same question. Another question: Does it restore to the same state as before playing the tts?
Right now it does not resume state. But I think I will reverse this since I have found an problem without any possible solution. If the players load data straight from Voicerss it interprets is as radio, hence it repeats the message indefinitely. Node-Sonos have solved that by downloading the data and expose it using an internal http server. This is not posdible ewith the current Domoticz python framework and all workaround includes adding additional components and that is something I want to avoid.
@tester22, how's live going?
After your last reply about the issue with TTS, it's quiet in this topic.
As a user of your plugin I'm curious about your plans with the pluging. In other words: What's in the pipeline for the next 2 months?

With regards,
Jan
Right not I think the plugin is more or less feature complete. Sonos players does not work well with the TTS services I have seen so far unless the tts file is downloaded and exposed with a webserver, that is something the the current python framework doesn't allow therefor TTS isn't possible right now.

Also this would require the calls to be made syncronos and the idea behind the python framework was that communication should be asyncronos.
tester22
Posts: 49
Joined: Tuesday 20 December 2016 17:43
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Sweden
Contact:

Re: Python plugin: Sonos

Post by tester22 »

Heursqem wrote:I have the plugin working, great!!!

This is what I would love to achieve

#1 - Someone pushes my doorbell
#2 - I capture the current state of my sonos player (medium, song, volume etc) and save this for later
#3 - I play my own sound through the sonos player (ding-dong)
#4 - I go back to to captured/saved state and listen to original music again

Would all of this be possible with this sonos plugin?
This would require the calls to be made syncronos and the idea behind the python framework was that communication should be asyncronos.
But maybe it would be possible to implement anyway. The audio to be played would need to be saved in an local music library and it would need special naming but might be possible tom implement. Will think about it.
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

Post by G3rard »

tester22 wrote: This would require the calls to be made syncronos and the idea behind the python framework was that communication should be asyncronos.
But maybe it would be possible to implement anyway. The audio to be played would need to be saved in an local music library and it would need special naming but might be possible tom implement. Will think about it.
Currently I am using PHP code for this, see https://github.com/gerard33/sonos/blob/ ... s.php#L379.
Maybe that can be of any use.
tester22 wrote:
dhanjel wrote:It would be nice to be able to set the media source (Sonos favourite for instance), if possible.
I currently use a nodejs middle tier for doing that, and it would be nice to get rid of external dependencies.
I use it to automatically play some lounge music in the bathroom when there is motion :)
How would you suggest that it is displayed in the ui in an generic way?
You can use the selector switch for this. It's used in Denon plugin of Dnpwwo.
In that plugin it's possible to change the name of the value in the selector switch, and it can be mapped in the hardware page, so you know which value to send.

See the screenshot below.
marantz.png
marantz.png (50.51 KiB) Viewed 3231 times
Not using Domoticz anymore
tester22
Posts: 49
Joined: Tuesday 20 December 2016 17:43
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Sweden
Contact:

Re: Python plugin: Sonos

Post by tester22 »

G3rard wrote:
tester22 wrote: This would require the calls to be made syncronos and the idea behind the python framework was that communication should be asyncronos.
But maybe it would be possible to implement anyway. The audio to be played would need to be saved in an local music library and it would need special naming but might be possible tom implement. Will think about it.
Currently I am using PHP code for this, see https://github.com/gerard33/sonos/blob/ ... s.php#L379.
Maybe that can be of any use.
tester22 wrote:
dhanjel wrote:It would be nice to be able to set the media source (Sonos favourite for instance), if possible.
I currently use a nodejs middle tier for doing that, and it would be nice to get rid of external dependencies.
I use it to automatically play some lounge music in the bathroom when there is motion :)
How would you suggest that it is displayed in the ui in an generic way?
You can use the selector switch for this. It's used in Denon plugin of Dnpwwo.
In that plugin it's possible to change the name of the value in the selector switch, and it can be mapped in the hardware page, so you know which value to send.

See the screenshot below.
marantz.png
If I am reading your code right you are saving the file locally here before sending it to the sonos players:
https://github.com/gerard33/sonos/blob/ ... s.php#L420

This is where I get stuck since the python framework does not support exposing the url's where the Sonos players can read data.

Regaring the selector switch. That is ofcourse possible but to have what all users suggest one user would like to have "Search and play the first found album by artist X", another one wan't to have line in and so on.
One possible solution would be that I Populate the dropdown with all the Sonos favorites that are defined. That way it would be an generic solution even that all the creterias above won't be possible to have.
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

Post by G3rard »

tester22 wrote: If I am reading your code right you are saving the file locally here before sending it to the sonos players:
https://github.com/gerard33/sonos/blob/ ... s.php#L420

This is where I get stuck since the python framework does not support exposing the url's where the Sonos players can read data.

Regaring the selector switch. That is ofcourse possible but to have what all users suggest one user would like to have "Search and play the first found album by artist X", another one wan't to have line in and so on.
One possible solution would be that I Populate the dropdown with all the Sonos favorites that are defined. That way it would be an generic solution even that all the creterias above won't be possible to have.
The PHP is indeed saving the file locally. It first checks if the file is already there, if not then it will be downloaded.
Can't the files be downloaded in the a subfolder of the plugin directory? I also store the files in a subfolder of the PHP files and play it from there.

For the selector switch I think it is a good option to get the Sonos favorites. I think the selector switch can only handle 10 values (at least when using via Domoticz GUI), so that is something to take into consideration.
Not using Domoticz anymore
tester22
Posts: 49
Joined: Tuesday 20 December 2016 17:43
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Sweden
Contact:

Re: Python plugin: Sonos

Post by tester22 »

G3rard wrote:
tester22 wrote: If I am reading your code right you are saving the file locally here before sending it to the sonos players:
https://github.com/gerard33/sonos/blob/ ... s.php#L420

This is where I get stuck since the python framework does not support exposing the url's where the Sonos players can read data.

Regaring the selector switch. That is ofcourse possible but to have what all users suggest one user would like to have "Search and play the first found album by artist X", another one wan't to have line in and so on.
One possible solution would be that I Populate the dropdown with all the Sonos favorites that are defined. That way it would be an generic solution even that all the creterias above won't be possible to have.
The PHP is indeed saving the file locally. It first checks if the file is already there, if not then it will be downloaded.
Can't the files be downloaded in the a subfolder of the plugin directory? I also store the files in a subfolder of the PHP files and play it from there.

For the selector switch I think it is a good option to get the Sonos favorites. I think the selector switch can only handle 10 values (at least when using via Domoticz GUI), so that is something to take into consideration.
No it is currently not possible to expose files with the python framework. I know this is considered and when it is possible I will try if it would work for this purpose.
User avatar
Dynamic
Posts: 109
Joined: Friday 12 July 2013 14:50
Target OS: -
Domoticz version:
Location: Enschede
Contact:

Re: Python plugin: Sonos

Post by Dynamic »

I am trying to get this plugin running, but I'm stuck.

I get this error in the Domoticz log:

Code: Select all

 2017-03-30 16:22:06.543 PluginSystem: Failed dynamic library load, install the latest libpython3.x library that is available for your platform. 
I tried to install libpython on my raspberry, but he can't find the package?
swevm
Posts: 23
Joined: Friday 16 September 2016 20:04
Target OS: Raspberry Pi / ODroid
Domoticz version: 8718
Location: Sweden
Contact:

Re: Python plugin: Sonos

Post by swevm »

Dynamic wrote:I am trying to get this plugin running, but I'm stuck.

I get this error in the Domoticz log:

Code: Select all

 2017-03-30 16:22:06.543 PluginSystem: Failed dynamic library load, install the latest libpython3.x library that is available for your platform. 
I tried to install libpython on my raspberry, but he can't find the package?
Did you follow
https://www.domoticz.com/wiki/Using_Python_plugins
Page that outline prerequisites and install method for Python?
Domoticz on RPi3 with Razberry: 10xZME WALLC-S, 14x Fib Switch, 6x Fib Wallplug, 1x Fib Motion Sensor, 2x Fib Smoke Sensor, 1x Fib Universal sensor (with 1-wire), 3x SwiidInter cordsw, ESPEasy [1-wire and relay], Kodi, Node-Red [Onkyo NR-828, UI etc]
User avatar
Dynamic
Posts: 109
Joined: Friday 12 July 2013 14:50
Target OS: -
Domoticz version:
Location: Enschede
Contact:

Re: Python plugin: Sonos

Post by Dynamic »

swevm wrote: Did you follow
https://www.domoticz.com/wiki/Using_Python_plugins
Page that outline prerequisites and install method for Python?
I did now, but I'm now stuck with 'change CMakeLists.txt'. I can't find how to do this? I tried to search for that file & tried to google it, but can't find it anywhere. If someone could help me out, that would be really appreciated!
swevm
Posts: 23
Joined: Friday 16 September 2016 20:04
Target OS: Raspberry Pi / ODroid
Domoticz version: 8718
Location: Sweden
Contact:

Re: Python plugin: Sonos

Post by swevm »

Dynamic wrote:
swevm wrote: Did you follow
https://www.domoticz.com/wiki/Using_Python_plugins
Page that outline prerequisites and install method for Python?
I did now, but I'm now stuck with 'change CMakeLists.txt'. I can't find how to do this? I tried to search for that file & tried to google it, but can't find it anywhere. If someone could help me out, that would be really appreciated!
What platform are you installing on. RPi? What OS are you using?
I never had to edit any files to get Python runtime to install.
Neither should you have to do that to install a plugin (unless the plugin depend on stuff you need to compile before it can be installed) as it's as simple as copying plugin.py to correct plugins folder and restart Domiticz so that it get picked up by Domoticz.
Domoticz on RPi3 with Razberry: 10xZME WALLC-S, 14x Fib Switch, 6x Fib Wallplug, 1x Fib Motion Sensor, 2x Fib Smoke Sensor, 1x Fib Universal sensor (with 1-wire), 3x SwiidInter cordsw, ESPEasy [1-wire and relay], Kodi, Node-Red [Onkyo NR-828, UI etc]
User avatar
Dynamic
Posts: 109
Joined: Friday 12 July 2013 14:50
Target OS: -
Domoticz version:
Location: Enschede
Contact:

Re: Python plugin: Sonos

Post by Dynamic »

I'm getting somewhere. I can see this in my logfile:

Code: Select all

2017-03-31 17:16:13.345 PluginSystem: Started, Python version '3.5.2'.
2017-03-31 17:16:15.760 PluginSystem: Entering work loop. 
So, i created this directory: /domoticz/plugins/sonos/
I created the file plugin.py, added the code from Github.
chmod the file to 755.
issued sudo service domoticz.sh restart

Went to domoticz / hardware. Added sonos. But now I get this error:

Code: Select all

2017-03-31 17:31:49.316 Error: (Sonos) failed to load 'plugin.py', Python Path used was '/home/pi/domoticz/plugins/sonos/:/usr/local/lib/python35.zip:/usr/local/lib/python3.5/:/usr/local/lib/python3.5/plat-linux:/usr/local/lib/python3.5/lib-dynload'. 
2017-03-31 17:31:49.316 Error: (Sonos) Module Import failed, exception: 'IndentationError' 
2017-03-31 17:31:49.317 Error: (Sonos) Import detail: File: /home/pi/domoticz/plugins/sonos/plugin.py, Line: -1234606240, offset: 275 
2017-03-31 17:31:49.317 Error: (Sonos) Error Line 'return False
hpnisse
Posts: 2
Joined: Monday 17 April 2017 13:51
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python plugin: Sonos

Post by hpnisse »

Hey!
I have a Synology DS1515+ NAS with DSM version 6.1-15047.
And I have installed Domoticz Beta v3.7320 by jumbotroll, that should support Python Plugin Beta.
The problem is that when I add plugins, Sonos, the Domoticz installation can't find it.

The logs from Domoticz startup is:
Spoiler: show
2017-04-17 14:14:34.832 Domoticz V3.7320 (c)2012-2017 GizMoCuz
2017-04-17 14:14:34.832 Build Hash: 61a03b6-modified, Date: 2017-04-13 13:28:23
2017-04-17 14:14:34.832 Startup Path: /usr/local/domoticz/
2017-04-17 14:14:34.993 EventSystem: reset all events...
2017-04-17 14:14:35.055 PluginSystem: Started, Python version '3.5.1'.
...
2017-04-17 14:14:37.498 PluginSystem: Entering work loop.
...
The startup seems to do something with plugin support , but I can´t find the Sonos plugin in "Hardware" - "Type" list.

The plugin files is in right folder I think?!
.../domoticz/plugins/Sonos/
Spoiler: show
sonos nas.PNG
sonos nas.PNG (18.69 KiB) Viewed 2870 times
Any ideas?
Thanks!
GuyTreepbush
Posts: 19
Joined: Thursday 12 January 2017 13:26
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python plugin: Sonos

Post by GuyTreepbush »

Your file permissions are wrong. Set permissions for plug-in.py file to 0777
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest