Start playing a preset (favourite) on a group of Sonos speakers (not out of sync)


#21

I’m up’n’running with the PI. I’ve set up the server - and I could not copy your pistons, so I’ve written them manually. However, I cannot quite figure out how to use them. Can anyone of you perhaps show me how you use them and/or some more simple pistons?
Or if we look at my original piston - how to play on 3 of my speakers as a group?
Thank you for your help! :slight_smile:


#22

You don’t need to do anything with the first piston, its just used to make the call out to the PI.
The second piston is a demo of how to use, so you just need to insert its code into your pistons where you want to send a speech request.

My piston does allow you send the speech to multiple sonos devices, however, this is not syncronised.

There is a facility to play syncronised using presets, however I can not get this to work. You create a file in the presets directory on the pi e,g
mypreset.json

{
“players”: [
{
“roomName”: “lounge”,
“volume”: 10
},
{
“roomName”: “kitchen”,
“volume”: 15
}
]
}
then use the preset rather than a device name in the url call.
e.g <PI tcp/ip>:5005/saypreset/mypreset/hello


#23

Unfortunatelly the speech request doesn’t work. I have been testing yours, but no sound. I’ve alsp found my way to the presets, but I cannot make that work either…
@bthrock I know you have the preset working - am I right? Could you share your piston perhaps?


#24

In what way doesn’t it work, errors or just no speech?

Can you try calling the url on the PI and seeing if it works?
http://localhost:5005//say/hello

I assume you’ve created a voicess account and added your api key into the settings.json on the PI?


#25

Hi Paul. Yes I’ve created the voice account and put ind the api-key in the setting.json file.
I’ve also created the preset-file and I can see in the log, that it lists the four rooms, names etc. But I cannot call them with /saypreset/my_preset.

I just did a reboot of the PI. Went into the directory "cd /home/pi/sonos/node-etc.etc. and typed:
npm start -> it gives med an error after listing my preset and I have no idea what it means:

2021-01-15T10:58:23.972Z INFO http server listening on port 5005
2021-01-15T10:58:24.496Z ERROR
  TypeError: Cannot read property 'length' of undefined
    at XmlEntities.exports.XmlEntities.XmlEntities.decode (/home/pi/sonos/node-s                                                                                                                                                             onos-http-api-master/node_modules/sonos-discovery/node_modules/html-entities/lib                                                                                                                                                             /xml-entities.js:48:15)
    at NotificationListener.notificationHandler (/home/pi/sonos/node-sonos-http-                                                                                                                                                             api-master/node_modules/sonos-discovery/lib/models/Player.js:262:42)
    at NotificationListener.emit (events.js:327:22)
    at NotificationListener.EventEmitter.emit (domain.js:467:12)
    at /home/pi/sonos/node-sonos-http-api-master/node_modules/sonos-discovery/li                                                                                                                                                             b/NotificationListener.js:125:17
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
2021-01-15T10:58:24.535Z ERROR
  TypeError: Cannot read property 'length' of undefined
    at XmlEntities.exports.XmlEntities.XmlEntities.decode (/home/pi/sonos/node-s                                                                                                                                                             onos-http-api-master/node_modules/sonos-discovery/node_modules/html-entities/lib                                                                                                                                                             /xml-entities.js:48:15)
    at NotificationListener.notificationHandler (/home/pi/sonos/node-sonos-http-                                                                                                                                                             api-master/node_modules/sonos-discovery/lib/models/Player.js:262:42)
    at NotificationListener.emit (events.js:327:22)
    at NotificationListener.EventEmitter.emit (domain.js:467:12)
    at /home/pi/sonos/node-sonos-http-api-master/node_modules/sonos-discovery/li                                                                                                                                                             b/NotificationListener.js:125:17
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
2021-01-15T10:58:24.544Z ERROR
  TypeError: Cannot read property 'length' of undefined
    at XmlEntities.exports.XmlEntities.XmlEntities.decode (/home/pi/sonos/node-s                                                                                                                                                             onos-http-api-master/node_modules/sonos-discovery/node_modules/html-entities/lib                                                                                                                                                             /xml-entities.js:48:15)
    at NotificationListener.notificationHandler (/home/pi/sonos/node-sonos-http-                                                                                                                                                             api-master/node_modules/sonos-discovery/lib/models/Player.js:262:42)
    at NotificationListener.emit (events.js:327:22)
    at NotificationListener.EventEmitter.emit (domain.js:467:12)
    at /home/pi/sonos/node-sonos-http-api-master/node_modules/sonos-discovery/li                                                                                                                                                             b/NotificationListener.js:125:17
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
2021-01-15T10:58:24.559Z ERROR
  TypeError: Cannot read property 'length' of undefined
    at XmlEntities.exports.XmlEntities.XmlEntities.decode (/home/pi/sonos/node-s                                                                                                                                                             onos-http-api-master/node_modules/sonos-discovery/node_modules/html-entities/lib                                                                                                                                                             /xml-entities.js:48:15)
    at NotificationListener.notificationHandler (/home/pi/sonos/node-sonos-http-                                                                                                                                                             api-master/node_modules/sonos-discovery/lib/models/Player.js:262:42)
    at NotificationListener.emit (events.js:327:22)
    at NotificationListener.EventEmitter.emit (domain.js:467:12)
    at /home/pi/sonos/node-sonos-http-api-master/node_modules/sonos-discovery/li                                                                                                                                                             b/NotificationListener.js:125:17
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

#26

I can’t get the preset option to work, although I believe others have it working. I’ve no idea why mine doesn’t work. I’ve given up on it and just use the non synced “say” command.

If you delete your preset files, restart the npm server and try a normal “say” request, does it work?


#27

Still gives med the same error!?! It looks like 4 errors and I have 4 speakers. Weird.
Perhaps I should delete and reinstall it all? Do you know the sudo-commands to do so?


#28

Mine comes up with errors n the log, but still works.

To reinstall I think you can just delete the directories holding the code.

It might be worth looking here for advice, they know way more than me!


#29

The first thing I would do is forget about webCoRE and pistons for a moment. It’s much faster and easier to test your commands in your browser window like this:

01

And here is my “speak.json” preset used in the example above.

{
“players”: [
{ “roomName”: “Sonos Family”, “volume”: 40 },
{ “roomName”: “Sonos Office”, “volume”: 40 },
{ “roomName”: “Sonos Dining”, “volume”: 40 },
{ “roomName”: “Sonos Bedroom”, “volume”: 20 },
{ “roomName”: “Sonos Bathroom”, “volume”: 20 },
{ “roomName”: “Sonos Guest Room”, “volume”: 20 }
]
}


#30

My json looks the same (with different room names), but it doesn’t work, when you call the url on the PI, the browser says waiting, for some time, then fails with “local host did not send any data” Theres nothing on the PI console to indicate anything has happened.

If I use a normal say command e.g http://localhost:5005/lounge/say/hello it works fine


#31

The first thing I would try is running your preset.json through a JSON validator such as this one. It can catch some common errors (such as invalid quotes) that may be causing your json to fail.

Also, be sure the json file is being uploaded to the correct directory as simple text.

I’d have to do some poking around to see what else might be causing this error.


#32

I’ve tried that, it validates fine. If there are json errors, they get reported when you start the process. The log does list the preset as being available, so it seems to be picking it up from the presets directory.

Further, if its not found/invalid, you get an error when you call the url, rather than the timeout/no data.

I should possibly try setting it up on my new PI, the one its running on is about 3 years old, so the OS is out of support.

speak2:
{ players:
[ { roomName: ‘lounge’, volume: 50 },
{ roomName: ‘kitchen’, volume: 50 } ] } }
2021-01-15T18:53:31.336Z INFO http server listening on 0.0.0.0 port 5005


#33

I’ve put the first node-sonos in the trashcan and used this https://github.com/jishi/node-sonos-http-api/wiki/Step-by-Step---RPi3-Install-of-Sonos-http-api guide for installation of the Sonos HTTP API and cloned the files. Suddently I can get the state without any problem, BUT:
I cannot create a settings.json file - I cannot copy anything in to the folder. I don’t have the rights!?! WHY? And what should I do to fix this?


#34

I think the settings.json should be there, you just need to edit it.
try a sudo from the command line (terminal)


#35

Yes thanks. I found my way. Also sudo nano filename.json - gives the ability to make the file right there in the terminal. This is complicated :wink:


#36

Yes, it can be a steep learning curve, but worth it when you get there! I taught myself nodejs on the PI, that was a real challenge, but has opened up some great opportunities for automation.


#37

I’ll never get there - but this is f****** great. It’s working!
Now it’s time to test and play! Perhaps I’ll be back with a lot of questions…
You should try the guide i linked to - it works with the my_presets.json that I created with sudo nano. For instance - it starts playing the favorite I named in my_presets-file by this command:
http://192.168.68.136:5005/preset/my_presets/favorite


#38

Yeah, I was just tossing out whatever random ideas I had without thinking them all the way through. I seem to remember someone else having this same issue; I just can’t remember how they solved it.


#39

I’m going to try setting up again on my new PI, which version of node.js should I use? The version documented above is no longer available.
( wget https://nodejs.org/dist/latest-v8.x/node-v8.16.2-linux-armv6l.tar.gz)


#40

I’ve always just used the version that is installed with Debian, which I update regularly and currently is running node 11.15.0