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.

Moderator: leecollings

Hanfelt
Posts: 4
Joined: Tuesday 29 March 2016 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by Hanfelt »

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 / ODroid
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by scheveningen »

No more error :)
commentator
Posts: 54
Joined: Thursday 23 June 2016 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: NL
Contact:

Re: Step by step guide: Sonos integration

Post by commentator »

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: 179
Joined: Friday 12 July 2013 13:53
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta Ch
Location: The Netherlands
Contact:

Re: Step by step guide: Sonos integration

Post by Holland »

@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: 54
Joined: Thursday 23 June 2016 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: NL
Contact:

Re: Step by step guide: Sonos integration

Post by commentator »

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: 102
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 »

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

Sent from my Nexus 6P using Tapatalk
commentator
Posts: 54
Joined: Thursday 23 June 2016 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: NL
Contact:

Re: Step by step guide: Sonos integration

Post by commentator »

yes, the tunein radio channel is in my favorites with this name
stanv
Posts: 5
Joined: Monday 24 November 2014 22:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by stanv »

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: 5
Joined: Monday 24 November 2014 22:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by stanv »

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: 179
Joined: Friday 12 July 2013 13:53
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta Ch
Location: The Netherlands
Contact:

Re: Step by step guide: Sonos integration

Post by Holland »

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 / ODroid
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by Tharland »

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: 179
Joined: Friday 12 July 2013 13:53
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta Ch
Location: The Netherlands
Contact:

Re: Step by step guide: Sonos integration

Post by Holland »

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 / ODroid
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by Tharland »

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: 179
Joined: Friday 12 July 2013 13:53
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta Ch
Location: The Netherlands
Contact:

Re: Step by step guide: Sonos integration

Post by Holland »

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: 44
Joined: Sunday 17 January 2016 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by naitsirhc »

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: 179
Joined: Friday 12 July 2013 13:53
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta Ch
Location: The Netherlands
Contact:

Re: Step by step guide: Sonos integration

Post by Holland »

@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: 44
Joined: Sunday 17 January 2016 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by naitsirhc »

I will try it, thanks for the quick reply
Und Tschjuß
ironrider
Posts: 11
Joined: Saturday 13 February 2016 15:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by ironrider »

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: 22
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 »

Would be cool to see just the song playing.

Verstuurd vanaf mijn SM-G920F met Tapatalk
DJBenson
Posts: 20
Joined: Wednesday 19 October 2016 19:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Step by step guide: Sonos integration

Post by DJBenson »

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 0 guests