Advanced Sonos Commands for Alexa/Echo (choose playlists/radio, control volume, skip songs, etc.)

Thanks Alex, but I believe my problems are a lot more basic than that. Node.js is just falling over.

I was able to pause an already running sonos by using one of the http requests, but then it fails shortly afterward. I can post up the issues Im having with node.js if that helps.

As I’ve said a few times above, my experience with setting up a node server is limited to the sole instance of following the instructions to which I linked in my post. If I could have provided additional information, I would have already. Except to the troll.

Hi,

I’ve setup basic auth on my server by adding a settings.json file and inserting:
“username”: “admin”,
“password”: “pass”

I’ve tested this from my browser and it works.

But I don’t know what I should do on Lambda or Alexa side to send these login credentials.
Can anyone tell me ?

Thanks.

How exactly is posting that the instructions are not clear, and posting examples of the errors acting like a troll?

For your information I’m already working on a set of instructions that anyone can follow, and as soon as I figure out what steps are going wrong and put these right, I’ll publish the instructions.

But again thanks for your help.

anybody who could help me with Alexa/Lambda side auth parameters ?

I’m happy to try, but you probably know more than me.

Ive now got the server up and running (I think). I have run the command http://localhost:5005/zones and I get a screen full of information about the sonos zones/players in the house.

however on the git/npm console window I have open I see the following error:

2016-10-04T19:57:43.431Z ERROR
{ error: ‘action ‘favicon.ico’ not found’ }

The server keeps on listening, because I can send another command - but if I go to the web page http://localhost:5005/kitchen/queue, then I get no response on the web page and the error in the git/npm window is as follows:

2016-10-04T20:05:49.108Z INFO http server listening on port 5005
C:\Users\chris\projects\sonos\node-sonos-http-api\lib\actions\queue.js:3
return player.coordinator.getQueue(startIndex);
^

ReferenceError: startIndex is not defined
at Object.queue (C:\Users\chris\projects\sonos\node-sonos-http-api\lib\actions\queue.js:3:38)
at handleAction (C:\Users\chris\projects\sonos\node-sonos-http-api\lib\sonos-http-api.js:106:35)
at HttpAPI.requireDir.requestHandler.handleAction.then [as requestHandler] (C:\Users\chris\projects\sonos\node-sonos-http-api\lib\sonos-http-api.js:83:5)
at C:\Users\chris\projects\sonos\node-sonos-http-api\server.js:80:13
at Server.finish (C:\Users\chris\projects\sonos\node-sonos-http-api\node_modules\node-static\lib\node-static.js:111:13)
at finish (C:\Users\chris\projects\sonos\node-sonos-http-api\node_modules\node-static\lib\node-static.js:170:14)

Anyone ideas what could be wrong?

OK. Server is up and running (or at least I think it is) - when I call “http://localhost:5005/Kitchen/pause”

I get the following error showing in the console:

2016-10-04T21:53:29.904Z ERROR
{ error: ‘action ‘favicon.ico’ not found’ }

However, the sonos in the kitchen responds correctly. I had manually set it playing a track and when I call that web page using an external device, it pauses - or plays if I choose /play instead.

So I can conclude that:

the server is working enough to do at least pause and play
port forwarding and firewall is working

however, if I say “alexa, ask sonos to pause in the kitchen”, she thinks for a while and says “OK”, but nothing happens. There is also no action or interaction shown in the npm/git console window (btw what exactly is the right name for this?)

This leads me to think that there now must be some issue with the connectivity between the alexa or lambda and my server.

Again, grateful for any pointers here, but will continue to try and resolve this.

Hi,

I’ve setup basic auth on my server by adding a settings.json file and inserting:
“username”: “admin”,
“password”: “pass”

I’ve tested this from my browser and it works.

But I don’t know what I should do on Lambda or Alexa side to send these login credentials.
Can anyone tell me ?

Thanks.

I believe the section you are looking for is here:

You will need to create a settings.json file and have that uploaded as part of the config in your lambda. This is where you will establish the username and password for it to use - and it is recommended this be done with https as well. I have not personally got to this stage yet, but slowly getting there.

I now believe I have got this working. At least mostly working.

If I manually (using my phone sonos app) start a track or playlist running on a sonos speaker, for example in the kitchen, I can then do the following:

Alexa, ask sonos to pause in the kitchen
Alexa, ask sonos to add the utility room to the kitchen
Alexa, ask sonos to resume in the kitchen.

However, what I cant get it to do is actually start playing something of my choice.

I have tried “ask sonos to play artist queen in the kitchen”, have tried with or without the word “artist”, and differing artists.

The response from Alexa (as mirrored in the developer test page when I write the phrase in), is: “Queued and started artist queen”

However, nothing starts playing, there is no action on the sonos and I see the following error in the npm/git console:

2016-10-05T09:05:36. 953Z ERROR Invalid music service

I have the following set in my opitions file:

defaultRoom: ‘kitchen’, // Allows you to specify a default room when one is not specified in the utterance
defaultMusicService: ‘spotify’, // Supports presets, apple, spotify, deezer, or library
advancedMode: true, // Allows you to specify and change default rooms and music services. Requires additional AWS setup

Ive tried removing the apostrophes around the word spotify, but that just breaks in and there is no response at all from Alexa.

Ive also tried “Ask sonos to play favourite BBC Radio 2 in the kitchen”. This results in the same error as above.

Anyone any ideas on how to resolve these issues?

EDIT - I tried one of the advanvced features and asked sonos to change music to spotify.
Alexa responded with OK. There were no messages appear in the npm/git console to confirm or deny this had happened.

When I then try “tell sonos to play artist queen in the kitchen” I hear “queued and started artist queen” from Alexa, though nothing happens on the sonos, and I receive the following error in the console:
2016-10-05T09:45:15. 098Z ERROR No matches were found

Trying with a different artist, such as “robbie williams” then results in the following error (again nothing happens on the sonos):

Error
at Object.invoke (C:\Users\chris\projects\sonos\node-sonos-http-api\node_modules\sonos-discovery\lib\helpers\soap.js:92:10)
at Player.addURIToQueue (C:\Users\chris\projects\sonos\node-sonos-http-api\node_modules\sonos-discovery\lib\models\Player.js:533:15)
at C:\Users\chris\projects\sonos\node-sonos-http-api\lib\actions\musicSearch.js:299:48
at process._tickCallback (node.js:369:9)

thanks.
got it…

1 Like

Well, it appears Im back at step 1.

I removed all the npm stuff, as I think I hadnt set it up properly. Now I cant install it again to a working state.

I can install node.js fine.

Its at the stage where I have to get a repository from github and run it on node that I struggle. Obviously installing an image on a rasbery pi would be much easier, but I dont have one.

So Im back to the step: “Grab https://github.com/jishi/node-sonos-http-api and run it on that server.”

How do you “grab” this, and how do you “run it”. Ive tried the npm install, and get errors, Ive tried just extracting the zip of all that content to a folder and then running node serevr.js, but that also fails.

Hi,

I have s specific problem. All utterances with a room name are working for me.
For example;
“play test in Lounge”

But a preset in the presets.json file does not work.
For example;
“play test”

I get this error:

2016-10-05T20:07:23.338Z ERROR
TypeError: Cannot read property ‘roomName’ of undefined
at /root/node-sonos-http-api/node_modules/sonos-discovery/lib/prototypes/SonosSystem/applyPreset.js:94:47
at process._tickCallback (node.js:369:9)

Why might this happen @infofiend ?

I believe if you are wanting to run a preset/favourite then these need to be contained in the area where you store the lambda if you want to call them with Echo/Alexa. The presets.json will be used only by the web page commands. Ive not got round to trying to set favourites or presets yet as I got sidetracked with some garage door relays.

The basic functionality is working for me, and I have also written new instructions as I have gone along, as there are a few tweaks that need to be made, especially if you want to set this up in the UK on the European Amazon developer environment.

Once Ive completed these I’ll get them hosted somewhere as it may help others.

If anyone has this working using https hit me up. I can get everything to work fine using http but am getting the below lambda error even though I configured REJECT_UNAUTHORIZED = false.

{
“version”: “1.0”,
“response”: {
“outputSpeech”: {
“type”: “PlainText”,
“text”: “The Lambda service encountered an error: self signed certificate”
},
“shouldEndSession”: true
},
“sessionAttributes”: {}

Can this be used to control amazon music on echo or only what music you have on amazon playlists?