Re: Step by step guide: Sonos integration
Posted: Sunday 16 September 2018 14:02
its exactly the same
Open source Home Automation System
https://forum.domoticz.com/
The solution is PM2, but I have it running on a RPi. See also the first post in this threat.
Dear all,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-
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¶m=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¶m=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¶m=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
Hi, enter the string in a webbrowser, not in the command line of your Raspberry pi!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.
Code: Select all
pm2 restart server
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 ]
Code: Select all
npm start
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 ]
Dear all,junr wrote: ↑Sunday 18 June 2017 12:18Sven,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
Go to the api directory
Start de pm2 serverCode: Select all
cd node-sonos-http-api
Save the processCode: Select all
sudo pm2 start server.js
The pm2 will save the running process.Code: Select all
sudo pm2 save
It works fine nowCode: Select all
Sudo reboot
Greetz JUNR
Code: Select all
sudo pm2 startup
Code: Select all
cd node-sonos-http-api
sudo pm2 start server.js
sudo pm2 save
sudo reboot