Page 2 of 7

Re: Step by step guide: Sonos integration

Posted: Sunday 24 July 2016 13:42
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
}


Re: Step by step guide: Sonos integration

Posted: Wednesday 10 August 2016 14:21
by scheveningen
No more error :)

Re: Step by step guide: Sonos integration

Posted: Thursday 25 August 2016 17:08
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?

Re: Step by step guide: Sonos integration

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

Re: Step by step guide: Sonos integration

Posted: Friday 02 September 2016 20:54
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

Re: Step by step guide: Sonos integration

Posted: Saturday 03 September 2016 8:37
by dhanjel
Is it your favourite list? I use the same command, and it works for me.

Sent from my Nexus 6P using Tapatalk

Re: Step by step guide: Sonos integration

Posted: Saturday 03 September 2016 9:20
by commentator
yes, the tunein radio channel is in my favorites with this name

Re: Step by step guide: Sonos integration

Posted: Tuesday 04 October 2016 23:04
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?

Re: Step by step guide: Sonos integration

Posted: Wednesday 05 October 2016 20:46
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.

Re: Step by step guide: Sonos integration

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

Re: Step by step guide: Sonos integration

Posted: Friday 07 October 2016 22:03
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?

Re: Step by step guide: Sonos integration

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

Re: Step by step guide: Sonos integration

Posted: Sunday 09 October 2016 14:19
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?

Re: Step by step guide: Sonos integration

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

Re: Step by step guide: Sonos integration

Posted: Sunday 23 October 2016 22:36
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

Re: Step by step guide: Sonos integration

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

Re: Step by step guide: Sonos integration

Posted: Monday 24 October 2016 22:02
by naitsirhc
I will try it, thanks for the quick reply

Re: Step by step guide: Sonos integration

Posted: Tuesday 25 October 2016 0:26
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

Re: Step by step guide: Sonos integration

Posted: Tuesday 25 October 2016 7:03
by Btje
Would be cool to see just the song playing.

Verstuurd vanaf mijn SM-G920F met Tapatalk

Re: Step by step guide: Sonos integration

Posted: Tuesday 08 November 2016 0:06
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!!