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.
Hanfelt
Posts: 4
Joined: Tuesday 29 March 2016 14:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by Hanfelt » Sunday 24 July 2016 13:42

Updated dzvents code

Code: Select all

active = true,
  on = { ['timer'] = 'every minute' },
  execute = function(domoticz)

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

        local sonos=assert(io.popen('curl http://192.168.50.3:5005/Altan/state'))
        local sonos_name = 'Sonos, Altan'

        local status = sonos:read('*all')
        sonos:close()
        local jsonStatus = json:decode(status)

        playerstate = jsonStatus['playerState']

        if (playerstate == 'PLAYING')
        then
            domoticz.devices[sonos_name].switchSelector(10)
        elseif (playerstate == 'PAUSED_PLAYBACK')
        then
            domoticz.devices[sonos_name].switchSelector(20)
        else
            domoticz.devices[sonos_name].switchSelector(0)
        end

  end
}


scheveningen
Posts: 9
Joined: Thursday 07 July 2016 10:51
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by scheveningen » Wednesday 10 August 2016 14:21

No more error :)

commentator
Posts: 40
Joined: Thursday 23 June 2016 14:41
Target OS: Raspberry Pi
Domoticz version: beta
Location: NL
Contact:

Re: Step by step guide: Sonos integration

Post by commentator » Thursday 25 August 2016 17:08

Holland wrote:There a few options to integrate Sonos with Domoticz

1. via php https://github.com/DjMomo/sonos
2. via the sonos http api; https://github.com/jishi/node-sonos-http-api

I prefer option 2, since it's far more flexible and (for me) easier to implement :P

Below you can find the step by step guide to get this running.

1. First make sure that at least version 4.0.0 of node is running. If it's older; update to the latest version.
....
Hi,
Thanks for the nice tutorial. Added this on my Domoticz pi. And it is working very wel. Except this:
I see this in the errorlog when pressing a button:

Code: Select all

Error: Error opening url: http://myinternalip:5005/woonkamer/play
Looks like a Domoticz issue as the Sonos is playing musica after pressing the button.

Ideas how to solve this?

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 27 August 2016 9:26

@commentator;

It's a known issue. The sonos api doesn't give any response when it received a correct command, and gives a response when the command is incorrect. Ideally it should return like OK. You can safely ignore the error. Actually the sonos http api developer should be contacted, but I haven't done that yet.

viewtopic.php?f=6&t=10211

edit: today I posted a request at github sonos http api; https://github.com/jishi/node-sonos-http-api/issues/275

Now, all we need to do is wait........

commentator
Posts: 40
Joined: Thursday 23 June 2016 14:41
Target OS: Raspberry Pi
Domoticz version: beta
Location: NL
Contact:

Re: Step by step guide: Sonos integration

Post by commentator » Friday 02 September 2016 20:54

Holland wrote:@commentator;

It's a known issue. The sonos api doesn't give any response when it received a correct command, and gives a response when the command is incorrect. Ideally it should return like OK. You can safely ignore the error. Actually the sonos http api developer should be contacted, but I haven't done that yet.

viewtopic.php?f=6&t=10211

edit: today I posted a request at github sonos http api; https://github.com/jishi/node-sonos-http-api/issues/275

Now, all we need to do is wait........

thanks :) Just waiting for a fix :)




An other question, how to start a radio stream from domoticz?
Because:
http://mylocalip:5005/livingroom/favorite/qmusic
doesn't work @ all

dhanjel
Posts: 132
Joined: Tuesday 05 August 2014 22:16
Target OS: Linux
Domoticz version: 3.5146
Location: Sweden
Contact:

Re: Step by step guide: Sonos integration

Post by dhanjel » Saturday 03 September 2016 8:37

Is it your favourite list? I use the same command, and it works for me.

Sent from my Nexus 6P using Tapatalk

commentator
Posts: 40
Joined: Thursday 23 June 2016 14:41
Target OS: Raspberry Pi
Domoticz version: beta
Location: NL
Contact:

Re: Step by step guide: Sonos integration

Post by commentator » Saturday 03 September 2016 9:20

yes, the tunein radio channel is in my favorites with this name

stanv
Posts: 7
Joined: Monday 24 November 2014 23:17
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by stanv » Tuesday 04 October 2016 23:04

I got this very very clear and simple guide working. At least....almost.
Got the JSON lua on, when doing the http-request the Sonos starts and stops.

But, how do I get this as a switch in Domoticz after step 9?

stanv
Posts: 7
Joined: Monday 24 November 2014 23:17
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by stanv » Wednesday 05 October 2016 20:46

stanv wrote:I got this very very clear and simple guide working. At least....almost.
Got the JSON lua on, when doing the http-request the Sonos starts and stops.

But, how do I get this as a switch in Domoticz after step 9?
dumb question, got it.
well, still not sure what the second LUA script is for.

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 06 October 2016 20:49

The lua script is just an example for what you can do with it. In this case, Sonos stops playing, the moment the TV is switched on

Tharland
Posts: 7
Joined: Wednesday 05 October 2016 16:02
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by Tharland » Friday 07 October 2016 22:03

piotr wrote:Get a free api-key from http://www.voicerss.org/ and you can get spoken (TTS) messages like: "The lights are off" when switching lights off.

usage example : http://yourserver:5005/LiveRoom/say/The lights are off

Ps: did anyone find a way the display the artist/track info in Domoticz ?
anyone know where to create the settings.json file?In which folder?

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 08 October 2016 21:45

In the root folder
If you want to change default settings, you can create a settings.json file and put in the root folder.
See: https://github.com/jishi/node-sonos-http-api

Tharland
Posts: 7
Joined: Wednesday 05 October 2016 16:02
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by Tharland » Sunday 09 October 2016 14:19

Holland wrote:In the root folder
If you want to change default settings, you can create a settings.json file and put in the root folder.
See: https://github.com/jishi/node-sonos-http-api
which root folder? i only get a message about i need to register api key, but i have done this. and created a settings.json with the api key in the node-sonos-http-api folder

Can anyone tell me?

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 22 October 2016 22:49

Updated the guide.

Update solves this; viewtopic.php?f=6&t=10211

- Install the most resent version of node-sonos-http-api/
- changed the example lua script, since developper changed the JSON string a bit

naitsirhc
Posts: 22
Joined: Sunday 17 January 2016 12:20
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by naitsirhc » Sunday 23 October 2016 22:36

Hi,

first of all, thank you for the easy to follow how to
I get it all running on my Domoticz system and have a nice Icon at my desktop.
Unortunatly I get stuck at booting on startup.
I'm running on Jessie:
when I do:
2. sudo pm2 startup systemd –u pi....... it kills the proces
3. pm2 start nefiteasyhttpserver.sh....... this one I don't understand, copied from another topic I guess
4. pm2 save....... this one saves it.

So I start with 2.
then I do: cd node-sonos-http-api
then I type: pm2 start server.js
follows by: save pm2
Which delivers me a script in:: /home/pi/.pm2/dump.pm2

Do I have to rename the dump in a *.sh script?

or shortened:
What do I have to do, to run the server at startup :)

Kind regards
Christian

edit: typed wrong code
Und Tschjuß

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 24 October 2016 21:51

@naitsirhc

After you got the service running, check with pm2 list, do the following;

Code: Select all

pm2 startup
This will likely generate the following command;

Code: Select all

sudo su -c "env PATH=$PATH:/usr/local/bin pm2 startup linux -u pi --hp /home/pi"
Execute the command that was generated via pm2 startup

Then, execute;

Code: Select all

pm2 save
Restart and check if it has worked

naitsirhc
Posts: 22
Joined: Sunday 17 January 2016 12:20
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by naitsirhc » Monday 24 October 2016 22:02

I will try it, thanks for the quick reply
Und Tschjuß

ironrider
Posts: 7
Joined: Saturday 13 February 2016 16:27
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by ironrider » Tuesday 25 October 2016 0:26

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

Btje
Posts: 20
Joined: Wednesday 05 October 2016 7:46
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by Btje » Tuesday 25 October 2016 7:03

Would be cool to see just the song playing.

Verstuurd vanaf mijn SM-G920F met Tapatalk

DJBenson
Posts: 12
Joined: Wednesday 19 October 2016 19:26
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by DJBenson » Tuesday 08 November 2016 1:06

Quick heads up to inform that 'playerState' is now 'playbackState' in the node-sonos-http JSON response. Aside from that, this is working perfectly using the dzVents method. Thanks all!!

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests