Page 6 of 7

Re: Step by step guide: Sonos integration

Posted: Sunday 16 September 2018 14:02
by josimd
its exactly the same

Re: Step by step guide: Sonos integration

Posted: Sunday 16 September 2018 14:15
by Holland
Almost out of idea's. Apparently the link between the button and the device is gone.

I would delete the selector switch and the dummy.

Then recreate a dummy for each Sonos group/or device. Recreate the selector switch for each Sonos group/or device

Re: Step by step guide: Sonos integration

Posted: Sunday 16 September 2018 19:29
by josimd
yes that did the trick! its working now in Domoticz. Do you also how to run the api continuously, now, when I close the terminal de pipe is broken. Is there an option within synology which I can use?

Re: Step by step guide: Sonos integration

Posted: Sunday 16 September 2018 21:00
by Holland
josimd wrote: Sunday 16 September 2018 19:29 yes that did the trick! its working now in Domoticz. Do you also how to run the api continuously, now, when I close the terminal de pipe is broken. Is there an option within synology which I can use?
The solution is PM2, but I have it running on a RPi. See also the first post in this threat.

Don't know if PM2 can run on a synology.

Re: Step by step guide: Sonos integration

Posted: Friday 21 September 2018 18:42
by josimd
I have it running on my synology NAS, instead of PM2 you can run node server.js via another way, see link below.

https://www.youtube.com/watch?v=tkbu3TT5LT8

Re: Step by step guide: Sonos integration

Posted: Monday 10 December 2018 19:47
by AllesVanZelf
How do I update the Sonos HTTP API from git without loosing my settings?
git pull in this directory?

Re: Step by step guide: Sonos integration

Posted: Monday 24 December 2018 11:56
by JeroenL
rjpost wrote: Monday 29 May 2017 11:20 Hello Guys,

I was wondering if you could provide me with some guidance in regards to getting this Sonos integration to work the way i would like to.

I have the following objective. I want to use a sonos connect ( not the amp version). When I select play on that specific sonos I want my to turn my receiver on and set it to input AUX. I want to achieve this through the Harmony HUB. I can control that perfectly through domoticz however I need to determine whether or not a specific sonos player is playing music.
I wanted to create an event with blocky to sent a command to the harmony hub when the sonos switch is set to status playing.

<deleted>

Can some explain to me where I should change the variables so it will work in my setup.
any help is appreciated.
Thanks a lot.

- Ronald-
Dear all,

Wanted to achieve the same with my Onkyo AV Receiver. Thinking that if I start my Sonos connect in the Living Room, Domoticz should turn on automatically the receiver and switch to the right input channel. Made a small modification to the script elsewhere in this thread, and it works like a charm. Hope it useful for someone else.
regards, Jeroen

Code: Select all

--
--
-- Domoticz LUA Script to turn Onkyo Receiver on when Sonos is playing
-- Date: 2018-12-24
-- 
--
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()

local sonos=assert(io.popen('curl http://192.168.178.55:5005/Woonkamer/state'))
local status = sonos:read('*all')
sonos:close()
local jsonStatus = json:decode(status)
local sonos_woonkamer = 'Sonos Woonkamer'

local onkyo_switch = 'Onkyo versterker'
local onkyo_input = 'Versterker Ingang'


--print(status)

playerstate = jsonStatus['playbackState']
-- artist = jsonStatus['currentTrack']['artist']
-- title  = jsonStatus['currentTrack']['title']
-- album  = jsonStatus['currentTrack']['album']
-- streaminfo = jsonStatus['currentTrack']['streamInfo']
   
commandArray = {}

if (playerstate == "PLAYING" or playerstate == "STOPPED" or playerstate == "PAUSED_PLAYBACK") then
   if playerstate == "PLAYING" then
      if	otherdevices[sonos_woonkamer]~='Playing' then
			commandArray[sonos_woonkamer]='Set Level 10'
			--os.execute('curl http://192.168.1.4:8080/json.htm?type=command&param=switchlight&idx=103&switchcmd=Set%20Level&level=10')
            print('Sonos Woonkamer status: ' ..playerstate)
      end
      if	otherdevices[onkyo_switch]~='On' then
			commandArray[onkyo_switch]='On'
			print('Onkyo switched on because Sonos Woonkamer is playing.')

			if	otherdevices[onkyo_input]~='Sonos' then
			    commandArray[onkyo_input]='Set Level 20'
			    print('Onkyo switched to Sonos, as input was on different channel.')
            end
        
      end

end
   if playerstate == "PAUSED_PLAYBACK" then
      if	otherdevices[sonos_woonkamer]~='Paused' then
			commandArray[sonos_woonkamer]='Set Level 20'
			--os.execute('curl http://192.168.1.4:8080/json.htm?type=command&param=switchlight&idx=103&switchcmd=Set%20Level&level=20')
            print('Sonos Woonkamer: ' ..playerstate)
      end
   end
   if playerstate == "STOPPED" then
      if	otherdevices[sonos_woonkamer]~='Off' then
			commandArray[sonos_woonkamer]='Set Level 0'
			--os.execute('curl http://192.168.1.4:8080/json.htm?type=command&param=switchlight&idx=103&switchcmd=Set%20Level&level=20')
            print('Sonos Woonkamer: ' ..playerstate)
      end
   end
else
   --print("2")
   --print('</font color="red">Sonos Woonkamer: SONOS-HTTP-API is off-line</font>')
end   

return commandArray

Re: Step by step guide: Sonos integration

Posted: Thursday 04 April 2019 1:35
by Dutchsea
Asterixenobelix wrote: Monday 22 May 2017 18:46 Anyone else any suggestions about my above mentioned problem? Is there a way to uninstall the sonos-api and install it again? I keep getting the error message when entering the right http-command.
Hi, enter the string in a webbrowser, not in the command line of your Raspberry pi!

And for IP use the ip address of your Pi

Re: Step by step guide: Sonos integration

Posted: Thursday 04 April 2019 12:38
by Dutchsea
Hi, i have Sonos up and running and 4 rooms work perfect. I just get errors for 1 room.
I changed the room name in the Sonos app as it had spaces in the name. But still i get errors.
I used the command: http:/ip:5005/zones to get info on the zones. In the info i see the old name still present eventhough the sonos app uses the new name. Is the Domoticz plugin storing the names at initial install that dont change when the names in the sonos system are changed? If so, how do i change the old name in the new name?

Re: Step by step guide: Sonos integration

Posted: Friday 05 April 2019 0:52
by Holland
@Dutchsea

I think a restart of the server instance would do it, assuming that the name server.js is still valid in your case

Code: Select all

pm2 restart server

Re: Step by step guide: Sonos integration

Posted: Friday 05 April 2019 12:11
by Dutchsea
Thank you. I rebooted the Pi twice. After the second time the name matched.

Re: Step by step guide: Sonos integration

Posted: Saturday 18 May 2019 10:19
by gerardosamara
Hi,

I have followed the installation procedure ... https://github.com/jishi/node-sonos-http-api

But the process failed at this step

start the server by running
npm start


Attached the log

Code: Select all

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose config Skipping project config: /home/gerardosamara/.npmrc. (matches userconfig)
5 verbose stack Error: ENOENT: no such file or directory, open '/home/gerardosamara/package.json'
5 verbose stack     at Error (native)
6 verbose cwd /home/gerardosamara
7 error Linux 4.9.0-9-amd64
8 error argv "/usr/bin/node" "/usr/bin/npm" "start"
9 error node v4.9.1
10 error npm  v2.15.12
11 error path /home/gerardosamara/package.json
12 error code ENOENT
13 error errno -2
14 error syscall open
15 error enoent ENOENT: no such file or directory, open '/home/gerardosamara/package.json'
15 error enoent This is most likely not a problem with npm itself
15 error enoent and is related to npm not being able to find a file.
16 verbose exit [ -2, true ]

Please advise .
Thank you

Re: Step by step guide: Sonos integration

Posted: Saturday 18 May 2019 14:15
by Holland
@gerardosamara

Try to follow my guide, see first post.

Therefore, skip the

Code: Select all

npm start
part.

Re: Step by step guide: Sonos integration

Posted: Sunday 19 May 2019 9:56
by gerardosamara
@Holland,

Finally I re-installed and it works following the installation guide in post#1 , on my Debian9 machine

Pm2 was not installed .
After installing Pm2 , "Pm2 list" shows the server on line

Step#8 : Basic commands play" , "pause" , "state" are OK

==> GREAT !

Re: Step by step guide: Sonos integration

Posted: Monday 20 May 2019 10:28
by gerardosamara
The step #8 has been completed successfully ( Sonos selector switch)

But the server does not run automatically after a reboot ( need to do a pm2 start server.js )
How to setup the automotic start at boot in a Debian 9 installation , There is no procedure in this post#1 stet by step procedure ?

Thank you

Re: Step by step guide: Sonos integration

Posted: Friday 31 May 2019 15:29
by silver323
Cant get this running without issues...

Code: Select all

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose stack Error: ENOENT: no such file or directory, open '/home/pi/package.json'
4 verbose stack     at Error (native)
5 verbose cwd /home/pi
6 error Linux 4.19.42-v7+
7 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
8 error node v5.6.0
9 error npm  v3.6.0
10 error path /home/pi/package.json
11 error code ENOENT
12 error errno -2
13 error syscall open
14 error enoent ENOENT: no such file or directory, open '/home/pi/package.json'
15 error enoent ENOENT: no such file or directory, open '/home/pi/package.json'
15 error enoent This is most likely not a problem with npm itself
15 error enoent and is related to npm not being able to find a file.
16 verbose exit [ -2, true ]

Re: Step by step guide: Sonos integration

Posted: Wednesday 28 August 2019 22:41
by rensbr
Thank you for all the work! It works like a charm.

I did however changed the dz script from anfelt, so now the played numbers / radio station are displayed in a seperate device. I also updated the icons from dhanjel, so now they don't have white borders anymore.

The script can be found at Github.

I had some problems with the auto-start of pm2, so I followed the steps from junr and that works like a charm. Of course you need pm2 in order for this to work, you can install that the help of this post. And pm2 do also need autostart, you can set that up with.
Sonos.zip
(8.98 KiB) Downloaded 150 times

Re: Step by step guide: Sonos integration

Posted: Wednesday 11 September 2019 19:50
by leecollings
Any plans for the Sonos plug-in to be added to the stable release yet? Is it working reliably on the beta?

Re: Step by step guide: Sonos integration

Posted: Sunday 13 October 2019 12:41
by Polforum
Hi All,

First thanks for all the good work!

I have the Sonos plugin up and running and it works well, except one thing...
After a notification Sonos won't start automatically when playing music directly from the Spotify app(Spotify connect).
If I play music by the Sonos app everything seems to be ok, but I prefer the Spotify app.
In the log I get the following error:

2019-10-13 11:50:30.677 Error: (Sonos Veranda) Unexpected response status received in function sendMessage (500, Internal Server Error). The following command is sent: urn:schemas-upnp-org:service:AVTransport:1#Seek, /MediaRenderer/AVTransport/Control

I'm running Domoticz 4.10717, Python 3.5.3, Raspberry Pi

Anyone who can help me?

Re: Step by step guide: Sonos integration

Posted: Saturday 11 January 2020 17:20
by Damsee
junr wrote: Sunday 18 June 2017 12:18
ironrider wrote:Hi,

i have to start server.js after a Domoticz reset.
Is ist possible to make the server.js running as a service.
Thanx

Sven
Sven,

Go to the api directory

Code: Select all

cd node-sonos-http-api 
Start de pm2 server

Code: Select all

 sudo pm2 start server.js 
Save the process

Code: Select all

 sudo pm2 save 
The pm2 will save the running process.

Code: Select all

Sudo reboot
It works fine now

Greetz JUNR
Dear all,

I just setup the node-sonos-http-api on my pi3 with raspbian buster which is working like a charm :)
Just wanna add than i add to run

Code: Select all

sudo pm2 startup
before the other ones to make pm2 and the Sonos API available after reboot ;)

Code: Select all

cd node-sonos-http-api
sudo pm2 start server.js
sudo pm2 save
sudo reboot