Step by step guide: Sonos integration

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.
DomoRies
Posts: 7
Joined: Friday 25 November 2016 23:46
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Step by step guide: Sonos integration

Post by DomoRies » Saturday 26 November 2016 0:01

Hi al,
Trying to install the program and running npm start i get the following code. What am i doing wrong?
I installed it on my raspberry pi with raspbian jessie
node version 7.2.0
npm version 3.10.9

Code: Select all

[email protected]:~/node-sonos-http-api $ npm start

> [email protected] start /home/pi/node-sonos-http-api
> node server.js

module.js:472
    throw err;
    ^

Error: Cannot find module 'request'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at /home/pi/node-sonos-http-api/node_modules/request-promise/lib/rp.js:26:24
    at Object.<anonymous> (/home/pi/node-sonos-http-api/node_modules/request-promise/lib/rp.js:33:3)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/pi/node-sonos-http-api/node_modules/sonos-discovery/lib/services/deezer.js:2:17)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)

npm ERR! Linux 4.4.32-v7+
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v7.2.0
npm ERR! npm  v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script 'node server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the sonos-http-api package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs sonos-http-api
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls sonos-http-api
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/pi/node-sonos-http-api/npm-debug.log
Ok it's working now :D
Last edited by DomoRies on Tuesday 13 December 2016 13:54, edited 2 times in total.

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

Re: Step by step guide: Sonos integration

Post by josimd » Saturday 26 November 2016 21:36

Hi, I'm running domoticz on Synology...somehow it looks like the program hangs after npm starts.... any suggestions?

~# cd node-sonos-http-api
[email protected]_NAS:~/node-sonos-http-api# npm start

> [email protected] start /root/node-sonos-http-api
> node server.js

2016-11-26T19:30:28.418Z INFO no settings file found, will only use default settings
2016-11-26T19:30:34.097Z INFO Presets loaded: { example:
{ players:
[ { roomName: 'WOONKAMER', volume: 10 },
{ roomName: 'STUDEERKAMER', volume: 10 },
{ roomName: 'Office', volume: 10 },
{ roomName: 'Bedroom', volume: 10 },
{ roomName: 'TV Room', volume: 15 } ],
playMode: { shuffle: true, repeat: 'all', crossfade: false },
pauseOthers: false,
favorite: 'My example favorite' } }
2016-11-26T19:30:34.262Z INFO http server listening on port 5005

mabo21
Posts: 8
Joined: Saturday 07 January 2017 18:17
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by mabo21 » Sunday 08 January 2017 17:09

Hi Holland,
thanks for the great solution! But i have a few issues and hope you can help me in any way... I have done everything you described, but when i start npm i get some errors.

Code: Select all

ash-4.3# npm start

> [email protected] start /volume1/homes/admin/node-sonos-http-api
> node server.js

2017-01-08T14:55:13.489Z INFO no settings file found, will only use default settings
2017-01-08T14:55:14.669Z INFO Presets loaded: { example: 
   { players: 
      [ { roomName: 'Bathroom', volume: 10 },
        { roomName: 'Kitchen', volume: 10 },
        { roomName: 'Office', volume: 10 },
        { roomName: 'Bedroom', volume: 10 },
        { roomName: 'TV Room', volume: 15 } ],
     playMode: { shuffle: true, repeat: 'all', crossfade: false },
     pauseOthers: false,
     favorite: 'My example favorite' } }
2017-01-08T14:55:15.281Z ERROR Port 5005 seems to be in use already. Make sure the sonos
-http-api isn't 
    already running, or that no other server uses that port. You can specify an alternat
ive http port 
    with property "port" in settings.json

npm ERR! Linux 3.10.77
npm ERR! argv "/volume1/@appstore/Node.js_v4/usr/local/bin/node" "/usr/local/bin/npm" "s
tart"
npm ERR! node v4.4.2
npm ERR! npm  v4.0.5
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `node server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script 'node server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the sonos-http-api package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs sonos-http-api
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls sonos-http-api
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /volume1/homes/admin/node-sonos-http-api/npm-debug.log
ash-4.3# 
Server.js is still running.
Node.js version is 4.4.2
npm version is 4.0.5

Please can you take a look and help me?

Thanks a lot and best,
Mario

mabo21
Posts: 8
Joined: Saturday 07 January 2017 18:17
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by mabo21 » Sunday 08 January 2017 21:12

I have uninstall everything and started again. Now it runs without issues.

Best,
Mario
mabo21 wrote:Hi Holland,
thanks for the great solution! But i have a few issues and hope you can help me in any way... I have done everything you described, but when i start npm i get some errors.

Code: Select all

ash-4.3# npm start

> [email protected] start /volume1/homes/admin/node-sonos-http-api
> node server.js

2017-01-08T14:55:13.489Z INFO no settings file found, will only use default settings
2017-01-08T14:55:14.669Z INFO Presets loaded: { example: 
   { players: 
      [ { roomName: 'Bathroom', volume: 10 },
        { roomName: 'Kitchen', volume: 10 },
        { roomName: 'Office', volume: 10 },
        { roomName: 'Bedroom', volume: 10 },
        { roomName: 'TV Room', volume: 15 } ],
     playMode: { shuffle: true, repeat: 'all', crossfade: false },
     pauseOthers: false,
     favorite: 'My example favorite' } }
2017-01-08T14:55:15.281Z ERROR Port 5005 seems to be in use already. Make sure the sonos
-http-api isn't 
    already running, or that no other server uses that port. You can specify an alternat
ive http port 
    with property "port" in settings.json

npm ERR! Linux 3.10.77
npm ERR! argv "/volume1/@appstore/Node.js_v4/usr/local/bin/node" "/usr/local/bin/npm" "s
tart"
npm ERR! node v4.4.2
npm ERR! npm  v4.0.5
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `node server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script 'node server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the sonos-http-api package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs sonos-http-api
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls sonos-http-api
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /volume1/homes/admin/node-sonos-http-api/npm-debug.log
ash-4.3# 
Server.js is still running.
Node.js version is 4.4.2
npm version is 4.0.5

Please can you take a look and help me?

Thanks a lot and best,
Mario

Trigun
Posts: 170
Joined: Wednesday 30 November 2016 12:58
Target OS: Raspberry Pi
Domoticz version: 3.5877
Contact:

Re: Step by step guide: Sonos integration

Post by Trigun » Saturday 21 January 2017 0:43

Hi all,

sorry but I am a complete noob out here.
I really like to use this feature for my domoticz setup but I am not getting any further.
so this is what I did.

>checked that I did have node version 4.0.0
>did the clone
>cd node-sonos-http-api
>sudo npm install --production
>> it installed without any error, assuming that I did the right thing.

but when I enter PM2 start server.js I get the following: command not found.

when I enter: npm start it works perfectly and I even get a page when entering domoticzip:5005

creating a switch is done correctly

But this is where I get stuck.
I have the feeling that I need to setup a config file where I confige the rooms and sonos Ip etc.
but have no idea how to get any further.

I hope someone cn help me out here.

Thanks in advance!

Holland
Posts: 313
Joined: Friday 12 July 2013 13:53
Target OS: Raspberry Pi
Domoticz version: Beta Ch
Location: The Netherlands
Contact:

Re: Step by step guide: Sonos integration

Post by Holland » Monday 23 January 2017 0:45

@Trigun

You need to jump into the sonos-http-api directory; then you can issue: pm2 start server.js

Trigun
Posts: 170
Joined: Wednesday 30 November 2016 12:58
Target OS: Raspberry Pi
Domoticz version: 3.5877
Contact:

Re: Step by step guide: Sonos integration

Post by Trigun » Wednesday 25 January 2017 22:01

Hi Holland, thank you for your reply. but so far no luck. I did what you told but it doesn't seem to start.
below a screenshot of what I did.

Can you please help me out here?
2017-01-25 20_59_15-Clipboard.png
2017-01-25 20_59_15-Clipboard.png (184.31 KiB) Viewed 1490 times
Thanks in advance!

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

Re: Step by step guide: Sonos integration

Post by G3rard » Wednesday 25 January 2017 23:08

If you are on on of the latest beta's then there also is a Python plugin available for Sonos.
Check http://www.domoticz.com/forum/viewtopic ... 3&p=116118 for more information.
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

Holland
Posts: 313
Joined: Friday 12 July 2013 13:53
Target OS: Raspberry Pi
Domoticz version: Beta Ch
Location: The Netherlands
Contact:

Re: Step by step guide: Sonos integration

Post by Holland » Wednesday 25 January 2017 23:13

@Trigun;

Have you installed PM2? It's not part of the Domoticz sd image, or Jessie Light

See http://pm2.keymetrics.io/docs/usage/quick-start/

Trigun
Posts: 170
Joined: Wednesday 30 November 2016 12:58
Target OS: Raspberry Pi
Domoticz version: 3.5877
Contact:

Re: Step by step guide: Sonos integration

Post by Trigun » Wednesday 25 January 2017 23:56

Holland wrote:@Trigun;

Have you installed PM2? It's not part of the Domoticz sd image, or Jessie Light

See http://pm2.keymetrics.io/docs/usage/quick-start/
Hi Holland, I got it working!

NPM start did the job! (since I don't have PM2 running ;) )

next thing is to keep it running when I close the session.

sorry I am a huge noob with commandline. do you perhaps have any suggestions?

Thanks again !

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

Re: Step by step guide: Sonos integration

Post by mvzut » Thursday 26 January 2017 2:18

Hi guys,

Are you aware that there is a new way to integrate hardware in Domoticz, via Python plugins, and that there is already an excellent Sonos plugin created in this way? See viewtopic.php?t=15543
I had it running within a few minutes, without installing anything. There is one prerequisite though, and that is that you use the latest beta.
Raspberry Pi 2B - RFXtrx433 - Aeon Z-Stick gen5 - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - Sonos Connect & PLAY:1 - Kodi - Wall mounted tablet + Imperihome - MANY switches/sensors

Trigun
Posts: 170
Joined: Wednesday 30 November 2016 12:58
Target OS: Raspberry Pi
Domoticz version: 3.5877
Contact:

Re: Step by step guide: Sonos integration

Post by Trigun » Thursday 26 January 2017 15:02

mvzut wrote:Hi guys,

Are you aware that there is a new way to integrate hardware in Domoticz, via Python plugins, and that there is already an excellent Sonos plugin created in this way? See viewtopic.php?t=15543
I had it running within a few minutes, without installing anything. There is one prerequisite though, and that is that you use the latest beta.
Hi mvzut, thanks for you reply,

I have to say that the solution with NPM also works fantastic!

If I manage to get it working after closing the putty session, it works like a charm!
I am aware that it is basic Linuc knowledge for this solution but hey, I'm just starting/beginning :)

if there is anyone who would like to help a noob out here, thanks in advance!

Trigun
Posts: 170
Joined: Wednesday 30 November 2016 12:58
Target OS: Raspberry Pi
Domoticz version: 3.5877
Contact:

Re: Step by step guide: Sonos integration

Post by Trigun » Thursday 26 January 2017 21:53

@ Holland,

thanks for the solution! I installed PM2 and its working perfectly!

what specifi things do I need to edit in de Lua script to get the player state?

Thanks again!

Holland
Posts: 313
Joined: Friday 12 July 2013 13:53
Target OS: Raspberry Pi
Domoticz version: Beta Ch
Location: The Netherlands
Contact:

Re: Step by step guide: Sonos integration

Post by Holland » Saturday 28 January 2017 22:30

@Trigun,

I use the following lua to check a couple of things related to the Sonos group in the livingroom(woonkamer), e.g the status, but also set Sonos to pauze when tv is switched on etc.

Code: Select all

json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()

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

local tv_woonkamer_status = 'TV Woonkamer System Alive'
local sonos_woonkamer = 'Sonos Woonkamer/Eetkamer'

--print("Eerste JSON stappen met LUA")
--print(status)
-- print(jsonStatus)

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

if (playbackState == "STOPPED" or playbackState == "PAUSED_PLAYBACK" or playbackState == "PLAYING") then
	if (playbackState == "PLAYING") then
		if type == "radio" then
			print('Woonkamer/Eetkamer Sonos status: ' ..playbackState.. ' ' ..type.. ' Titel: '..title)
		else
			if artist ~= nil then
				print('Badkamer Sonos status: ' ..playbackState.. ' Artiest: ' ..artist.. ' Titel: '..title)
			else
				print('Badkamer Sonos status: ' ..playbackState.. ' Titel: '..title)
			end	
		end
		if (uservariables["SonosWoonkamerStatus"] == "PAUSED") then
			commandArray['Variable:SonosWoonkamerStatus']='PLAYING'
			print("Uservar SonosWoonkamer updated to PLAYING")
		end
	end
	if (playbackState == "STOPPED" or playbackState == "PAUSED_PLAYBACK") then
		print('Woonkamer/Eetkamer Sonos Status: ' ..playbackState)
		if (uservariables["SonosWoonkamerStatus"] == "PLAYING") then
			commandArray['Variable:SonosWoonkamerStatus']='PAUSED'
			print("Uservar SonosWoonkamer updated to PAUSED")
		end	
	end
else
	--print("2")
	print('<font color="red">Woonkamer/Eetkamer: SONOS-HTTP-API is off-line</font>')
end	

if (playbackState == "STOPPED" or playbackState == "PAUSED_PLAYBACK") then
	switch_status_sonos_woonkamer_eetkamer = otherdevices["Sonos Woonkamer/Eetkamer"]
	print('Sonos Woonkamer/Eetkamer Switch Status: ' ..switch_status_sonos_woonkamer_eetkamer)
	if otherdevices["Sonos Woonkamer/Eetkamer"] == 'Pauze' then
		print('Sonos Woonkamer/Eetkamer Switch Status is correct, should be PAUZE: ' ..switch_status_sonos_woonkamer_eetkamer)
	else
		print('Sonos Woonkamer/Eetkamer Switch Status not correct, should be PAUZE: ' ..switch_status_sonos_woonkamer_eetkamer)
		commandArray['UpdateDevice'] = '43|20|20'
	end
end	

if (playbackState == "PLAYING") then
	switch_status_sonos_woonkamer_eetkamer = otherdevices["Sonos Woonkamer/Eetkamer"]
	print('Sonos Woonkamer/Eetkamer Switch Status: ' ..switch_status_sonos_woonkamer_eetkamer)
	if otherdevices["Sonos Woonkamer/Eetkamer"] == 'Play' then
		print('Sonos Woonkamer/Eetkamer Switch Status is correct, should be PLAY: ' ..switch_status_sonos_woonkamer_eetkamer)
	else
		print('Sonos Woonkamer/Eetkamer Switch Status not correct, should be PLAY: ' ..switch_status_sonos_woonkamer_eetkamer)
		commandArray['UpdateDevice'] = '43|10|10'
	end
end	

if devicechanged[tv_woonkamer_status] == 'On' then 
 	print("TV Woonkamer is net aangezet, status Sonos Woonkamer onderzoeken")
	if (playerstate == "PLAYING" or playbackState == "PLAYING") then
		print("Sonos woonkamer heeft status PLAYING, Sonos Woonkamer/Eetkamer wordt uitgeschakeld")
		commandArray[sonos_woonkamer]='Set Level 20'
	end	
end


return commandArray

markiemajax
Posts: 23
Joined: Monday 18 May 2015 15:45
Target OS: Raspberry Pi
Domoticz version: 3.4834
Contact:

Re: Step by step guide: Sonos integration

Post by markiemajax » Thursday 16 March 2017 17:14

I got it partly working, but what ip do i use?

i got 3 sonos speakers (1 playbar, 2 sonos 1)

Or is it the ip of my domoticz (raspberry)?

Holland
Posts: 313
Joined: Friday 12 July 2013 13:53
Target OS: Raspberry Pi
Domoticz version: Beta Ch
Location: The Netherlands
Contact:

Re: Step by step guide: Sonos integration

Post by Holland » Thursday 16 March 2017 22:01

Just use the ip address of your sonos player. If you have grouped sonos players, use the ip address of the zone coordinator.

markiemajax
Posts: 23
Joined: Monday 18 May 2015 15:45
Target OS: Raspberry Pi
Domoticz version: 3.4834
Contact:

Re: Step by step guide: Sonos integration

Post by markiemajax » Friday 17 March 2017 11:56

This is the log i get. It is still not working.
I put my script in attechment.
2017-03-17 10_51_27-Domoticz.png
2017-03-17 10_51_27-Domoticz.png (205.28 KiB) Viewed 1199 times
Attachments
script_device_sonos_tv_woonkamer.zip
(1.12 KiB) Downloaded 28 times

Holland
Posts: 313
Joined: Friday 12 July 2013 13:53
Target OS: Raspberry Pi
Domoticz version: Beta Ch
Location: The Netherlands
Contact:

Re: Step by step guide: Sonos integration

Post by Holland » Saturday 18 March 2017 11:10

Do you get anything in return if you do this;

http://ip:5005/name of your sonos/state

markiemajax
Posts: 23
Joined: Monday 18 May 2015 15:45
Target OS: Raspberry Pi
Domoticz version: 3.4834
Contact:

Re: Step by step guide: Sonos integration

Post by markiemajax » Sunday 19 March 2017 12:24

Hello,

Yes i get status "error". I use the ip of my domoticz. If i use the ip of my sonos playbar the site is not available.

Something is wrong, but i don't know what.


Holland wrote:Do you get anything in return if you do this;

http://ip:5005/name of your sonos/state

markiemajax
Posts: 23
Joined: Monday 18 May 2015 15:45
Target OS: Raspberry Pi
Domoticz version: 3.4834
Contact:

Re: Step by step guide: Sonos integration

Post by markiemajax » Sunday 19 March 2017 12:27

Hello,

If i use http://ip domoticz:5005/state, i get this.
2017-03-19 11_26_20-10.100.75.113_5005_state.png
2017-03-19 11_26_20-10.100.75.113_5005_state.png (17.53 KiB) Viewed 1166 times
Holland wrote:Do you get anything in return if you do this;

http://ip:5005/name of your sonos/state

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests