Git Product home page Git Product logo

sonos2mqtt's Introduction

Sonos2mqtt

Sonos2mqtt npm Sonos api documentation Sonos typescript this library Sonos cli Join us on Discord

github issues docker pulls Downloads/week License Support me on Github

All Contributors

mqtt-smarthome semantic-release

This node application is a bridge between the Sonos and a mqtt server. The status of all your sonos devices will be published to mqtt and you can control the sonos speakers over mqtt.

It's intended as a building block in heterogenous smart home environments where an MQTT message broker is used as the centralized message bus. See MQTT Smarthome on Github for a rationale and architectural overview.

Check out the other bridges in the software list

Documentation

See: https://svrooij.github.io/sonos2mqtt

Node-sonos-ts

Sonos typescript this library

This library depends on node-sonos-ts which I also developed. All other libraries using node-sonos-ts should also be able to implemented all the nice features included there. Like notifications or text-to-speech which are the coolest new additions for sonos2mqtt!

Beer or Coffee

I'm a big fan of beer and coffee. To provide something extra to everybody who is sponsoring me, I'll provide a hosted TTS server for all my sponsors.

This bridge and the sonos package took me a lot of hours to build, so I invite everyone using it to at least have a look at my Sponsor page. Even though the sponsoring tiers are monthly you can also cancel anytime 😉

Special thanks

The latest version of this bridge is inspired on hue2mqtt.js by Sabastian Raff. That was a great sample on how to create a globally installed, command-line, something2mqtt bridge.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Stephan van Rooij

💻 📖

Sven Werner

📦 💻

Matthias Burgfried

💻

mqtt-fan

💻

Martin Roth

📖

Doug Melton

🐛

Sebastian

💻

Emmanuel Venisse

📖

Jonas Hansen

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

sonos2mqtt's People

Contributors

allcontributors[bot] avatar cheanrod avatar dependabot[bot] avatar evenisse avatar jonasmh avatar matthias-burgfried avatar mqtt-fan avatar renovate-bot avatar renovate[bot] avatar sebbo2002 avatar svrooij avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sonos2mqtt's Issues

Best way of grouping speakers

This is perhaps not wholly related to sonos2mqtt, but I hope you don't mind me asking the question since you (and probably other users of this project) seems very knowledgeable about Sonos.

I have quite a few speakers and I group them differently depending of use. In the morning the Alexa alarm triggers music on certain speakers, when I arrive home in the evening I want others and so on.

I solve this by sending a leavegroup to the speaker I'd like to be the coordinator, joingroup to the other players and then play to the coordinator. I stagger the commands by approx 500ms to not overwhelm the system. It works, sonos2mqtt does its work, but the Sonos system itself is slow, and not all that stable. Most of the time it works although it takes a fairly long time. A lot of the time one or more speaker doesn't join or join but doesn't play. (That last one is a bit weird)

Is there a better way to do this?

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Not restoring playing after notification

I am listening to the music.

I play the notification using the given example, but after playing the notification, the music is not restore and I get this error message.

1|bridge | { Error: Request failed with status code 500
1|bridge | at createError (/home/pi/.nvm/versions/node/v10.16.1/lib/node_modules/sonos2mqtt/node_modules/axios/lib/core/createError.js:16:15)
1|bridge | at settle (/home/pi/.nvm/versions/node/v10.16.1/lib/node_modules/sonos2mqtt/node_modules/axios/lib/core/settle.js:18:12)
1|bridge | at IncomingMessage.handleStreamEnd (/home/pi/.nvm/versions/node/v10.16.1/lib/node_modules/sonos2mqtt/node_modules/axios/lib/adapters/http.js:202:11)
1|bridge | at IncomingMessage.emit (events.js:203:15)
1|bridge | at endReadableNT (_stream_readable.js:1145:12)
1|bridge | at process._tickCallback (internal/process/next_tick.js:63:19)
1|bridge | config:
1|bridge | { adapter: [Function: httpAdapter],
1|bridge | transformRequest: { '0': [Function: transformRequest] },
1|bridge | transformResponse: { '0': [Function: transformResponse] },
1|bridge | timeout: 0,
1|bridge | xsrfCookieName: 'XSRF-TOKEN',
1|bridge | xsrfHeaderName: 'X-XSRF-TOKEN',
1|bridge | maxContentLength: -1,
1|bridge | validateStatus: [Function: validateStatus],
1|bridge | headers:
1|bridge | { Accept: 'application/json, text/plain, /',
1|bridge | 'Content-Type': 'text/xml; charset=utf8',
1|bridge | SOAPAction: '"urn:schemas-upnp-org:service:AVTransport:1#Seek"',
1|bridge | 'User-Agent': 'axios/0.18.1',
1|bridge | 'Content-Length': 289 },
1|bridge | method: 'post',
1|bridge | url:
1|bridge | 'http://192.168.2.181:1400/MediaRenderer/AVTransport/Control',
1|bridge | data:
1|bridge | '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:Seek xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">0TRACK_NR2</u:Seek></s:Body></s:Envelope>' },
1|bridge | request:
1|bridge | ClientRequest {
1|bridge | _events:
1|bridge | [Object: null prototype] {
1|bridge | socket: [Function],
1|bridge | abort: [Function],
1|bridge | aborted: [Function],
1|bridge | error: [Function],
1|bridge | timeout: [Function],
1|bridge | prefinish: [Function: requestOnPrefinish] },
1|bridge | _eventsCount: 6,
1|bridge | _maxListeners: undefined,
1|bridge | output: [],
1|bridge | outputEncodings: [],
1|bridge | outputCallbacks: [],
1|bridge | outputSize: 0,
1|bridge | writable: true,
1|bridge | _last: true,
1|bridge | chunkedEncoding: false,
1|bridge | shouldKeepAlive: false,
1|bridge | useChunkedEncodingByDefault: true,
1|bridge | sendDate: false,
1|bridge | _removedConnection: false,
1|bridge | _removedContLen: false,
1|bridge | _removedTE: false,
1|bridge | _contentLength: null,
1|bridge | _hasBody: true,
1|bridge | _trailer: '',
1|bridge | finished: true,
1|bridge | _headerSent: true,
1|bridge | socket:
1|bridge | Socket {
1|bridge | connecting: false,
1|bridge | _hadError: false,
1|bridge | _handle: [TCP],
1|bridge | _parent: null,
1|bridge | _host: null,
1|bridge | _readableState: [ReadableState],
1|bridge | readable: true,
1|bridge | _events: [Object],
1|bridge | _eventsCount: 7,
1|bridge | _maxListeners: undefined,
1|bridge | _writableState: [WritableState],
1|bridge | writable: false,
1|bridge | allowHalfOpen: false,
1|bridge | _sockname: null,
1|bridge | _pendingData: null,
1|bridge | _pendingEncoding: '',
1|bridge | server: null,
1|bridge | _server: null,
1|bridge | parser: null,
1|bridge | _httpMessage: [Circular],
1|bridge | [Symbol(asyncId)]: 845,
1|bridge | [Symbol(lastWriteQueueSize)]: 0,
1|bridge | [Symbol(timeout)]: null,
1|bridge | [Symbol(kBytesRead)]: 0,
1|bridge | [Symbol(kBytesWritten)]: 0 },
1|bridge | connection:
1|bridge | Socket {
1|bridge | connecting: false,
1|bridge | _hadError: false,
1|bridge | _handle: [TCP],
1|bridge | _parent: null,
1|bridge | _host: null,
1|bridge | _readableState: [ReadableState],
1|bridge | readable: true,
1|bridge | _events: [Object],
1|bridge | _eventsCount: 7,
1|bridge | _maxListeners: undefined,
1|bridge | _writableState: [WritableState],
1|bridge | writable: false,
1|bridge | allowHalfOpen: false,
1|bridge | _sockname: null,
1|bridge | _pendingData: null,
1|bridge | _pendingEncoding: '',
1|bridge | server: null,
1|bridge | _server: null,
1|bridge | parser: null,
1|bridge | _httpMessage: [Circular],
1|bridge | [Symbol(asyncId)]: 845,
1|bridge | [Symbol(lastWriteQueueSize)]: 0,
1|bridge | [Symbol(timeout)]: null,
1|bridge | [Symbol(kBytesRead)]: 0,
1|bridge | [Symbol(kBytesWritten)]: 0 },
1|bridge | _header:
1|bridge | 'POST /MediaRenderer/AVTransport/Control HTTP/1.1\r\nAccept: application/json, text/plain, /\r\nContent-Type: text/xml; charset=utf8\r\nSOAPAction: "urn:schemas-upnp-org:service:AVTransport:1#Seek"\r\nUser-Agent: axios/0.18.1\r\nContent-Length: 289\r\nHost: 192.168.2.181:1400\r\nConnection: close\r\n\r\n',
1|bridge | _onPendingData: [Function: noopPendingOutput],
1|bridge | agent:
1|bridge | Agent {
1|bridge | _events: [Object],
1|bridge | _eventsCount: 1,
1|bridge | _maxListeners: undefined,
1|bridge | defaultPort: 80,
1|bridge | protocol: 'http:',
1|bridge | options: [Object],
1|bridge | requests: {},
1|bridge | sockets: [Object],
1|bridge | freeSockets: {},
1|bridge | keepAliveMsecs: 1000,
1|bridge | keepAlive: false,
1|bridge | maxSockets: Infinity,
1|bridge | maxFreeSockets: 256 },
1|bridge | socketPath: undefined,
1|bridge | timeout: undefined,
1|bridge | method: 'POST',
1|bridge | path: '/MediaRenderer/AVTransport/Control',
1|bridge | _ended: true,
1|bridge | res:
1|bridge | IncomingMessage {
1|bridge | _readableState: [ReadableState],
1|bridge | readable: false,
1|bridge | _events: [Object],
1|bridge | _eventsCount: 3,
1|bridge | _maxListeners: undefined,
1|bridge | socket: [Socket],
1|bridge | connection: [Socket],
1|bridge | httpVersionMajor: 1,
1|bridge | httpVersionMinor: 1,
1|bridge | httpVersion: '1.1',
1|bridge | complete: true,
1|bridge | headers: [Object],
1|bridge | rawHeaders: [Array],
1|bridge | trailers: {},
1|bridge | rawTrailers: [],
1|bridge | aborted: false,
1|bridge | upgrade: false,
1|bridge | url: '',
1|bridge | method: null,
1|bridge | statusCode: 500,
1|bridge | statusMessage: 'Internal Server Error',
1|bridge | client: [Socket],
1|bridge | _consuming: false,
1|bridge | _dumped: false,
1|bridge | req: [Circular],
1|bridge | responseUrl:
1|bridge | 'http://192.168.2.181:1400/MediaRenderer/AVTransport/Control',
1|bridge | redirects: [] },
1|bridge | aborted: undefined,
1|bridge | timeoutCb: null,
1|bridge | upgradeOrConnect: false,
1|bridge | parser: null,
1|bridge | maxHeadersCount: null,
1|bridge | _redirectable:
1|bridge | Writable {
1|bridge | _writableState: [WritableState],
1|bridge | writable: true,
1|bridge | _events: [Object],
1|bridge | _eventsCount: 2,
1|bridge | _maxListeners: undefined,
1|bridge | _options: [Object],
1|bridge | _redirectCount: 0,
1|bridge | _redirects: [],
1|bridge | _requestBodyLength: 289,
1|bridge | _requestBodyBuffers: [],
1|bridge | _onNativeResponse: [Function],
1|bridge | _currentRequest: [Circular],
1|bridge | _currentUrl:
1|bridge | 'http://192.168.2.181:1400/MediaRenderer/AVTransport/Control' },
1|bridge | [Symbol(isCorked)]: false,
1|bridge | [Symbol(outHeadersKey)]:
1|bridge | [Object: null prototype] {
1|bridge | accept: [Array],
1|bridge | 'content-type': [Array],
1|bridge | soapaction: [Array],
1|bridge | 'user-agent': [Array],
1|bridge | 'content-length': [Array],
1|bridge | host: [Array] } },
1|bridge | response:
1|bridge | { status: 500,
1|bridge | statusText: 'Internal Server Error',
1|bridge | headers:
1|bridge | { 'content-length': '347',
1|bridge | 'content-type': 'text/xml; charset="utf-8"',
1|bridge | ext: '',
1|bridge | server: 'Linux UPnP/1.0 Sonos/51.1-66240 (ZPS18)',
1|bridge | connection: 'close' },
1|bridge | config:
1|bridge | { adapter: [Function: httpAdapter],
1|bridge | transformRequest: [Object],
1|bridge | transformResponse: [Object],
1|bridge | timeout: 0,
1|bridge | xsrfCookieName: 'XSRF-TOKEN',
1|bridge | xsrfHeaderName: 'X-XSRF-TOKEN',
1|bridge | maxContentLength: -1,
1|bridge | validateStatus: [Function: validateStatus],
1|bridge | headers: [Object],
1|bridge | method: 'post',
1|bridge | url:
1|bridge | 'http://192.168.2.181:1400/MediaRenderer/AVTransport/Control',
1|bridge | data:
1|bridge | '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:Seek xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">0TRACK_NR2</u:Seek></s:Body></s:Envelope>' },
1|bridge | request:
1|bridge | ClientRequest {
1|bridge | _events: [Object],
1|bridge | _eventsCount: 6,
1|bridge | _maxListeners: undefined,
1|bridge | output: [],
1|bridge | outputEncodings: [],
1|bridge | outputCallbacks: [],
1|bridge | outputSize: 0,
1|bridge | writable: true,
1|bridge | _last: true,
1|bridge | chunkedEncoding: false,
1|bridge | shouldKeepAlive: false,
1|bridge | useChunkedEncodingByDefault: true,
1|bridge | sendDate: false,
1|bridge | _removedConnection: false,
1|bridge | _removedContLen: false,
1|bridge | _removedTE: false,
1|bridge | _contentLength: null,
1|bridge | _hasBody: true,
1|bridge | _trailer: '',
1|bridge | finished: true,
1|bridge | _headerSent: true,
1|bridge | socket: [Socket],
1|bridge | connection: [Socket],
1|bridge | _header:
1|bridge | 'POST /MediaRenderer/AVTransport/Control HTTP/1.1\r\nAccept: application/json, text/plain, /\r\nContent-Type: text/xml; charset=utf8\r\nSOAPAction: "urn:schemas-upnp-org:service:AVTransport:1#Seek"\r\nUser-Agent: axios/0.18.1\r\nContent-Length: 289\r\nHost: 192.168.2.181:1400\r\nConnection: close\r\n\r\n',
1|bridge | _onPendingData: [Function: noopPendingOutput],
1|bridge | agent: [Agent],
1|bridge | socketPath: undefined,
1|bridge | timeout: undefined,
1|bridge | method: 'POST',
1|bridge | path: '/MediaRenderer/AVTransport/Control',
1|bridge | _ended: true,
1|bridge | res: [IncomingMessage],
1|bridge | aborted: undefined,
1|bridge | timeoutCb: null,
1|bridge | upgradeOrConnect: false,
1|bridge | parser: null,
1|bridge | maxHeadersCount: null,
1|bridge | _redirectable: [Writable],
1|bridge | [Symbol(isCorked)]: false,
1|bridge | [Symbol(outHeadersKey)]: [Object] },
1|bridge | data:
1|bridge | '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><s:Fault>s:ClientUPnPError701</s:Fault></s:Body></s:Envelope>' } }

autostart

Hi,

is there ar way to autostart sonos2mqtt on system boot?

Grouped speakers get the status "playing"?

Hello, I have observed a behavior that I do not understand. When I group a player (player 1) with a second player (player 2), the status of player 1 is "playing", although both players are not playing anything (they are stopped or paused).
Is this behavior intended?

%j placeholder doesn't work

%j placeholder doesn't work in log statements as e.g.

log.debug('Error parsing json %j', e)

The statement leads to the following output:

2020-01-18 12:51:27.628 <debug> Error parsing json %j

Substituted by %s the output show the correct output:

2020-01-18 12:53:34.046 <debug> Error parsing json SyntaxError: Unexpected token o in JSON at position 1 at JSON.parse (<anonymous>) at ConvertToObjectIfPossible (/Users/swerner/Documents/src/sonos2mqtt/src/bridge.js:401:17) at setalarm (/Users/swerner/Documents/src/sonos2mqtt/src/bridge.js:277:13) at handleGenericCommand (/Users/swerner/Documents/src/sonos2mqtt/src/bridge.js:255:14) at MqttClient.handleIncomingMessage (/Users/swerner/Documents/src/sonos2mqtt/src/bridge.js:113:12) at MqttClient.emit (events.js:223:5) at MqttClient._handlePublish (/Users/swerner/Documents/src/sonos2mqtt/node_modules/mqtt/lib/client.js:1162:12) at MqttClient._handlePacket (/Users/swerner/Documents/src/sonos2mqtt/node_modules/mqtt/lib/client.js:351:12) at work (/Users/swerner/Documents/src/sonos2mqtt/node_modules/mqtt/lib/client.js:283:12) at Writable.writable._write (/Users/swerner/Documents/src/sonos2mqtt/node_modules/mqtt/lib/client.js:294:5)

I didn't figure out the cause until now. https://nodejs.org/en/knowledge/getting-started/the-console-module/ suggests that %j is a valid placeholder and should print the JSON representation of the object.

The name of the group doesn't change.

I use the current docker build and have observed that the group name does not change when I group speakers.

Grouped:
sonos/RINCON_B8E9111111111111 {"uuid":"RINCON_B8E9111111111111","name":"Bath","groupName":"Bath","coordinatorUuid":"RINCON_B8E9111111111111","transportState":"PLAYING","playmode":"NORMAL","ts":1590419121686,"volume":{"Master":43,"LF":100,"RF":100},"mute":{"Master":false,"LF":false,"RF":false}}

Not grouped:
sonos/RINCON_B8E9111111111111 {"uuid":"RINCON_B8E9111111111111","name":"Bath","groupName":"Bath","coordinatorUuid":"RINCON_B8E9111111111111","currentTrack":{"AlbumArtUri":"http://192.168.1.23:1400/getaa?s=1&u=x-sonosapi-stream:s25111%3fsid%3d254%26flags%3d8224%26sn%3d0","Title":"radioeins vom rbb","UpnpClass":"object.item","ItemId":"-1","ParentId":"-1","TrackUri":"x-sonosapi-stream:s25111?sid=254&flags=8224&sn=0","ProtocolInfo":"sonos.com-http:*:application/octet-stream:*"},"enqueuedMetadata":{"Title":"radioeins vom rbb","UpnpClass":"object.item.audioItem.audioBroadcast","ItemId":"-1","ParentId":"-1"},"transportState":"STOPPED","playmode":"NORMAL","ts":1590419234677,"volume":{"Master":43,"LF":100,"RF":100},"mute":{"Master":false,"LF":false,"RF":false}}

2.0.0: MQTT connection issue

I can't seem to get the dockerized v2.0.0 to connect to Mosquitto:

2019-12-25 10:13:35.008 mqtt reconnect
2019-12-25 10:13:35.010 mqtt closed mqtt://xxxx:[email protected]

I can't see anything in the Mosquitto logs. Anybody else have any issues with this?

how to setup MQTT server

Hi,

is there a way to configure the MQTT server, because mine is on a different machine.

Thanks
Markus

Need at least node 7.5 for sonos2mqtt to work

Hi,

I had some problems running sonos2mqtt on node v6. I got error message listed below:

pi@raspberry2:~ $ node ./sonos_test.js
/home/pi/node_modules/sonos/lib/sonos.js:66
var implicitListen = async function (event, listener) {
^^^^^^^^
SyntaxError: Unexpected token function
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/home/pi/node_modules/sonos/index.js:1:80)
at Module._compile (module.js:570:32)
pi@raspberry2:~ $ node -v
v6.10.0

When I upgraded to node 9 it all worked. Seems this is related to async package that at least needs node 7.5

EXPOSE port incorrect according to documentation

In all parts of the documentation the listen port is specified as 6329:
Examples:

Run docker run --env-file .env -p 6329:6329 svrooij/sonos2mqtt

and

Docker-compose

version: "3.7"
 services:
  sonos:
    ...
    ports:
      - "6329:6329"

However, the Dockerfile exposes 6326, which is incorrect / inconsistent with the provided mappings and will not work.

EXPOSE 6326

Multi architecture docker image

Currently we are building a linux/amd64 docker image, but the base image supports multiple architectures.

This image should build without any problem for every platform supported by the base image, but I need some help setting up the automated builds. So in theory you can run this app on a raspberry pi in docker, but (for now) you should build it yourself on the raspberry pi until we have set-up automatic builds.

I should all go automatically, but I have no special preference for a specific platform.

  • Github Actions
  • Azure DevOps
  • Docker hub builds

I found some template here but I'm kinda lost on how to implement it.

Switching Radio-Favorites results in mutliple STOPPED transportSate messages

Hi Stephan,

first of all: thank you for your implementation. Installation and start working with it was really easy :)

My Problem:
Switching my Radio-Favorites (TuneIn) with the sonos mac app results in mutliple STOPPED transportSate messages (at least 2) and after that transmission and playing starts. I am receiving the messages with my node red mqtt node...

Can you or anyone else confirm this behaviour or do you need more details?

Cheers
Nils

Create option to use UUID or speaker name in all topics

With the release of the single topic to get all the device info, I choose to use the UUID instead of the name in the topic. This is because the UUID is always connected to a player and the name isn't good for players that are a stereo pair.

For backwards compatibility I left the original topic as is.
An option to have the old topic use the UUID as well, could solve those issues on the old topics.

How to Browse

Thanks for the updated documentation, it helped a bunch. I'm just still having trouble with the browsing commands. This one works:

{
  "command": "adv-command",
  "input": {
    "cmd": "GetFavorites",
    "reply": "GetFavoritesReply"
  }
}

And it looks like it's a shortcut to this one. But this one doesn't work (I've tried many variations on both BrowseParsed and BrowseParsedWithDefaults). I'm assuming once I figure this one out, searching by artist (like here) or searching for all playlists ("SQ:") will be obvious.

{
  "command": "adv-command",
  "input": {
    "cmd": "ContentDirectoryService.BrowseParsedWithDefaults",
    "input": {
      "ObjectID": "FV:2"
    },
    "reply": "GetFavoritesReply"
  }
}

=>

{"command":"adv-command","error":{"Action":"Browse","FaultCode":"s:Client","Fault":"UPnPError","UpnpErrorCode":701,"name":"SonosError"}}

Sonos S2 - No status changes?

Good evening. I updated my system to S2 yesterday and I ran into a problem. I can still control the system, but I can't get any more system changes via MQTT.

# docker logs sonos2mqtt -f
2020-06-11T19:44:36.349Z [Information] Starting sonos2mqtt
2020-06-11T19:44:36.358Z [Information] LogLevel changed to information
2020-06-11T19:44:36.372Z [Information] Found 6 sonos speakers
2020-06-11T19:44:36.419Z [Information] Mqtt connection changed to connected: true
# mosquitto_sub -h 10.10.10.10 -v -t sonos/#
sonos/connected 2

docker-compose.yml

...
sonos2mqtt:
    image: svrooij/sonos2mqtt
    container_name: sonos2mqtt
    environment:
      - SONOS2MQTT_DEVICE=${SONOS1}
      - SONOS2MQTT_MQTT=mqtt://${MQTT}:1883
      - SONOS_LISTENER_HOST=${DOCKER_HOST}
      - TZ=Europe/Berlin
    depends_on:
      - mqtt
    restart: unless-stopped
...

My question: I' m using the Docker image, how can I turn on debug logging?

UPnPError when executing speak while streaming TuneIn-station

Running the latest version of sonos2mqtt (v2.0.10) in Docker and whenever I publish a MQTT message to sonos/set/MYDEVICE/speak , the message gets spoken but my Sonos speaker won't resume playing whatever Tune-in station they were playing.
Sonos2mqtt throws the following error message:

<error> Error executing speak for MYDEVICENAME {"Action":"SetAVTransportURI","FaultCode":"s:Client","Fault":"UPnPError","UpnpErrorCode":402,"name":"SonosError"}

I'm not sure if it's relevant but I have also tried running docker with the --network host flag. Unfortunately thats yielding the same error.

The above error is only when streaming from a TuneIn-station.

However when playing an Album or when playing a Spotify playlist there are other issues:
Most times the spoken message fails and is replaced with a very short period of silence. (Timing issue?) (In my Sonos app I can see the message clip name showing up briefly) Sometimes the message gets spoken correctly. Playing is always resumed. Please advise me if you would you like me to submit a separate issue for that.

More details possible ?

Hello,

Thanks for this github project.
I am coming to you to ask if it is possible to have more data sent to broker ?
I want to have a good integration in my home automation system. i am using jeedom and i need as far as i see one more information, which is the model of the speaker (play 1 / play 3 / etc).

Thanks for your help
TaG

SetAVTransportURI command not working for live streams?

Like the title says, I can't get SetAVTransportURI to work for live radio streams. I know this uri should work because it's what I use in my own android app (using a library I've developed). I've tried both of these and they're met with different error messages.

{
  "command": "adv-command",
  "input": {
    "cmd": "SetAVTransportURI",
    "val": {
      "InstanceID": 0,
      "CurrentURI": "x-rincon-mp3radio://http://ice3.somafm.com/groovesalad-64-aac",
      "CurrentURIMetaData": ""
    }
  }
}

=>

2020-05-25T01:38:53.445Z [Debug] Mqtt parsing adv-command for rincon_b8e93783163601400
2020-05-25T01:38:53.447Z [Warning] Error executing adv-command for Office (RINCON_B8E93783163601400)
 TypeError: trackUri.replace is not a function
    at Function.GuessTrack (/usr/src/app/node_modules/@svrooij/sonos/lib/helpers/metadata-helper.js:104:50)
    at Function.GuessMetaDataAndTrackUri (/usr/src/app/node_modules/@svrooij/sonos/lib/helpers/metadata-helper.js:95:41)
    at SonosDevice.SetAVTransportURI (/usr/src/app/node_modules/@svrooij/sonos/lib/sonos-device.js:374:59)
    at SonosDevice.ExecuteCommand (/usr/src/app/node_modules/@svrooij/sonos/lib/sonos-device.js:138:48)
    at Function.ExecuteCommand (/usr/src/app/lib/sonos-command-mapping.js:17:41)
    at Function.ExecuteControl (/usr/src/app/lib/sonos-command-mapping.js:7:46)
    at EventEmitter.<anonymous> (/usr/src/app/lib/sonos-to-mqtt.js:79:67)
    at EventEmitter.emit (events.js:310:20)
    at SmarthomeMqtt.handleIncomingMessage (/usr/src/app/lib/smarthome-mqtt.js:97:29)
    at MqttClient.<anonymous> (/usr/src/app/lib/smarthome-mqtt.js:35:74)
{
	"command": "setavtransporturi",
	"input": "x-rincon-mp3radio://http://ice3.somafm.com/groovesalad-64-aac"
}

=>
Causes an error in the sonos app, a toast that says

Unable to play 'groovesalad-64-aac' - cannot connect to http%3a because the server cannot be found

Problem with the setting --distinct

Hello,

I like this git for my sonos player, but I've a problem I didnt undestand hox to make the setting on true.
I would like to use Distinct messages but I Don't find how to use it.

I use docker to use sonos2mqtt and I've created the file .env but I dont find how to change the settings --distinct Simply

Thanks for your help, to help me to understand this

npm install -g failed

After installing s2m with
npm install -g sonos2mqtt

the 1st line of the "executable" is missing

diff :-)
`diff sonos2mqtt /usr/bin/sonos2mqtt
0a1,2

#!/usr/bin/env node
`

sorry didn't find this file in the git :-(

Thx Wuppi68 from fhem forum

One topic for commands

Hi.

I recently found this project when I was looking for alternatives to sonos-http-api. Love it, great job!

I'm currently in the process of migrating my Node-RED flows to it, and I was wondering of you would consider adding one command topic instead of or in addition to the multiple command topics approach you're using? Instead of publishing an empty message to sonos/set/Office/next or sonos/set/Office/play I would like to be able to sending next or play as a message to sonos/set/Office, for example. It would make thinks a lot simpler.

Even better would be a combined command and parameter JSON,

{ "cmnd: "notify", "uri": "https://archive.org/download/Doorbell_1/doorbell.mp3", "volume": 10 }

Thanks!

Initial run fails with message: Cannot read property 'ParseMember' of undefined

To reproduce:

  1. Delete any previous Docker container and image
  2. Make an .env file as described
  3. Issue command: docker run --env-file .env -p 6329:6329 svrooij/sonos2mqtt
Unable to find image 'svrooij/sonos2mqtt:latest' locally
latest: Pulling from svrooij/sonos2mqtt
c9b1b535fdd9: Pull complete
99c818a1969a: Pull complete
fced71a1b5bc: Pull complete
799240489e66: Pull complete
211283277c6a: Pull complete
aeb42f5bb289: Pull complete
9dd1d4ca5b76: Pull complete
0bb55f60af26: Pull complete
Digest: sha256:8439f6177616e05dc42af0d3d452bbf89ae0c1359e369ba16806e94545aa646f
Status: Downloaded newer image for svrooij/sonos2mqtt:latest
2020-02-18 20:14:36.965 <info>  sonos2mqtt 0.0.0-development starting
2020-02-18 20:14:36.966 <info>  Parsing url mqtt://MYHOST
2020-02-18 20:14:36.994 <info>  Start from device 192.168.4.82
2020-02-18 20:14:37.005 <info>  Connected to mqtt mqtt://MYHOST
2020-02-18 20:14:37.016 <error> Error in device discovery TypeError: Cannot read property 'ParseMember' of undefined
    at ParseGroup (/usr/src/app/node_modules/@svrooij/sonos/lib/services/zone-group-topology.service.js:71:95)
    at Array.map (<anonymous>)
    at ZoneGroupTopologyService.GetParsedZoneGroupState (/usr/src/app/node_modules/@svrooij/sonos/lib/services/zone-group-topology.service.js:59:23)

Here is my .env file:

# Set the IP of one known sonos speaker (device discovery doesnt always work inside docker.)
SONOS2MQTT_DEVICE=192.168.4.82
# Set the mqtt connection string
SONOS2MQTT_MQTT=mqtt://MYHOST
# Set the IP of the docker host (so node-sonos-ts knows where the events should be send to)
SONOS_LISTENER_HOST=192.168.4.44
# Set text-to-speech endpoint (optional)
SONOS_TTS_ENDPOINT=http://MYHOST:5601/api/generate

I had things up and running recently.

response for mute and cmd switchtotv not working

Hi Stephan,
Thanks for your sonos module.
I am evaluate the sonos2mqtt in connection with fhem.
There is unfortunately no response if I send mute to any speaker. All items "mute_" will be every time in state false. I have no idea why.

I have two players who switchtotv should working: beam and playbase
I will get every time the response not implemented (see error message)
I found two Items who may be a bug?

  1. sonos-command-mapping.ts line 98 should there SwitchToTV instead of SwitchToQueue?
  2. https://github.com/svrooij/node-sonos-ts/blob/master/src/sonos-device.ts
    Line 448 should there spdif instead of spdiff ?
    Kindly regards
    Otto

Errormessage:
[Warning] Error executing switchtotv for Wohnzimmer (RINCON_B8E93743FCBE01400) Error: Command 'switchtotv' not implemented at Function.ExecuteCommand (/home/pi/node_modules/sonos2mqtt/lib/sonos-command-mapping.js:99:23) at Function.ExecuteControl (/home/pi/node_modules/sonos2mqtt/lib/sonos-command-mapping.js:7:46) at EventEmitter.mqtt.Events.on (/home/pi/node_modules/sonos2mqtt/lib/sonos-to-mqtt.js:81:67) at EventEmitter.emit (events.js:198:13) at SmarthomeMqtt.handleIncomingMessage (/home/pi/node_modules/sonos2mqtt/lib/smarthome-mqtt.js:102:29) at MqttClient.mqttClient.on (/home/pi/node_modules/sonos2mqtt/lib/smarthome-mqtt.js:37:74) at MqttClient.emit (events.js:198:13) at MqttClient._handlePublish (/home/pi/node_modules/mqtt/lib/client.js:1162:12) at MqttClient._handlePacket (/home/pi/node_modules/mqtt/lib/client.js:351:12) at work (/home/pi/node_modules/mqtt/lib/client.js:283:12)

Group commands

I just noticed that commands like for example sonos/cmd/pauseall doesn't work on a group. Same thing with sonos/room/pause for a grouped speaker. How do I send commands to a group?

How to play a playlist or a favorite

How's the best way to play a playlist or a favorite (with sonos2mqtt)? Is it setAVTransportURI? But then how's the best way to list URI's of favorites/playlists?

Thanks!

Title and artist are not set when streaming from TuneIn

When streaming from TuneIn artist and title information are not parsed and only a stream URI is published under title.

{"ts":1577457006391,
"name":"Bad",
"val":
{"title":"x-sonosapistream:...",
"albumArt":"http://192.168.178.XX:1400/...",
"trackUri":"x-sonosapi-stream:..."
}}

The information in the stream URI is cut for privacy reason.

Right albumARTURI

I am getting the following info:

1|bridge | 2019-08-04 19:34:16.105 New track data for 7828CAE16694

{"id":null,
"parentID":null,
"title":"Ni La Hora",
"artist":"Juan Magan",
"album":"Ni La Hora",
"albumArtURI":"http://192.168.2.181:1400/getaa?s=1&u=x-sonosapi-hls-static%3acatalog%252ftracks%252fB07F4168P2%252f1c15af08-336a-4da1-9e50-d58636657b26%252facbea5c5-65ad-46a9-943f-090ab5924ef8%252fA3S8QLFWY3FC9K%252fn%252fUNLIMITED%252fba71af7f-eafe-4710-af94-30adc3db3c1c%252fUNLIMITED_STATION%252f3f258197-c78f-4a9b-8ba5-5210e76ffd6c%252f%3fsid%3d201%26flags%3d0%26sn%3d2",
"uri":"x-sonosapi-hls-static:catalog%2ftracks%2fB07F4168P2%2f1c15af08-336a-4da1-9e50-d58636657b26%2facbea5c5-65ad-46a9-943f-090ab5924ef8%2fA3S8QLFWY3FC9K%2fn%2fUNLIMITED%2fba71af7f-eafe-4710-af94-30adc3db3c1c%2fUNLIMITED_STATION%2f3f258197-c78f-4a9b-8ba5-5210e76ffd6c%2f?sid=201&flags=0&sn=2",
"duration":198,
"queuePosition":2}

albumARTURI is not functional, because it returns an URL of the speaker. Any help?

Getting stuck without fully crashing after a couple of hours running in pm2

After a couple of hours it get's stuck while running in pm2. But it seems not to crash fully/ exit because pm2 isn't restarting it. So it stops working completely.

The logs then show this:

FetchError: request to http://192.168.178.49:1400/ZoneGroupTopology/Event failed, reason: connect ETIMEDOUT 192.168.178.49:1400
6|sonos2mq |     at ClientRequest.<anonymous> (/home/pi/.nvm/versions/node/v12.18.3/lib/node_modules/sonos2mqtt/node_modules/node-fetch/lib/index.js:1455:11)
6|sonos2mq |     at ClientRequest.emit (events.js:315:20)
6|sonos2mq |     at Socket.socketErrorListener (_http_client.js:426:9)
6|sonos2mq |     at Socket.emit (events.js:315:20)
6|sonos2mq |     at emitErrorNT (internal/streams/destroy.js:92:8)
6|sonos2mq |     at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
6|sonos2mq |     at processTicksAndRejections (internal/process/task_queues.js:84:21) {
6|sonos2mq |   type: 'system',
6|sonos2mq |   errno: 'ETIMEDOUT',
6|sonos2mq |   code: 'ETIMEDOUT'
6|sonos2mq | }

But as said it didn't seem to crash because pm2 shows it's running and isn't restarting it.

I am running v3.0.10-beta.2 from #114

Is it possible to play notifications using a local file?

I'd like to play a notification stored in a mp3 file on local file system.

So I've tried posting to MQTT Topic: sonos/set/MYROOMNAME/notify with payload: { "trackUri": "file://opt/openhab/conf/sounds/katching.mp3", "volume": 40, "timeout": 15, "onlyWhenPlaying": false } and some other variants but without success.

Is it possible to do what I want? If not, can it be put on the list of requests for enhancements?

Other Streaming Services (Deezer/Apple Music/Amazon Music/...)?

I tried hard to get my Sonos stuff play some music from a streamingservice different than Spotify - but had no success. Does anyone know, how to adress track/album/playlist on deezer/apple music/amazon music)?

When switching to a playlist from deezer via Sonos App, spotify is mentioned in the item ID- is this correct?:

payload.EnqueuedTransportURIMetaData:
{ "Artist":"[MyUsername]", "AlbumArtUri":"https://cdns-images.dzcdn.net/images/cover/[...].jpg", "Title":"[MyPlaylistTitle]", "UpnpClass":"object.container.playlistContainer.#DEFAULT", "ItemId":"10060a6cplaylist_spotify%3aplaylist-5299030562", "ParentId":"10fe2664playlists" }

Is any other service supported?

Sample favorite album from deezer:
{"AlbumArtUri":"http://e-cdn-images.deezer.com/images/cover/135571ae1243feba64f4858fe90e11c3/250x250-000000-80-0-0.jpg","Title":"All For You (Originals International Version)","UpnpClass":"object.itemobject.item.sonos-favorite","ItemId":"FV:2/66","ParentId":"FV:2","TrackUri":"x-rincon-cpcontainer:1004006calbum-119589?sid=2&flags=108&sn=3","ProtocolInfo":"x-rincon-cpcontainer:*:*:*"}

Sample favorite playlist from deezer:
{"AlbumArtUri":"http://e-cdn-images.deezer.com/images/playlist/2ecfca5836a2249f9669973fa2af4a3f/250x250-000000-80-0-0.jpg","Title":"Café del Mar Ibiza","UpnpClass":"object.itemobject.item.sonos-favorite","ItemId":"FV:2/113","ParentId":"FV:2","TrackUri":"x-rincon-cpcontainer:1006006cplaylist_spotify:playlist-4045469642?sid=2&flags=108&sn=16","ProtocolInfo":"x-rincon-cpcontainer:*:*:*"}

Group Control: Publishing and Playbackinfo

Hello Stephan,

I'm trying to build a player for FHEM.
I came across the topic of groups.

Whenever a group consists of several players, there is a master. The problem is that the slaves no longer receive status updates and always think they are still playing music. You only get status updates from the slaves within a group if you e.g. the volume changes. But even then "PLAYING" is also broadcast in the payload. Even if no more music is played.
If the slave leaves the group, it is immediately correct again.

It would be good if slaves in a group would get the information from the master.

Attached a picture. In this you can clearly see what I mean. (I hope)
This is a graphical representation of payload.

Sorry for my english!
fhem_group_control

MAC Address

Hi,

Thanks for your excellent work!

I would need to have the mac address of the speakers in order to identify them. Room name is too generic.

Any help on this?

Thanks!
Jorge

Documentation: Document configuration when running against a splitted (S1/S2) system

Hi,
I have to Sonos networks. One with old Play 5 players (controlled via Sonos S1 app) and newer Play 1 players (controlled via 'normal' Sonos app).
Depending on the setting of SONOS2MQTT_DEVICE I can control the old players or the new players but not both at the same time.
Is there any hack to control both together?
Currently I'm thinking about using two Docker container (one for the old players, one for the new players) but it feels like overkill. And I don't have an idea if node-sonos-ts (SONOS_LISTENER_HOST) is able to work with two containers.

Best regards

AlbumArt is missing

Version: 2.0.1

Since version 2.0.0 of sonos2mqtt the album arts are missing in the json object published to the track topic.

I'm not using the --publish-distinct parameter.

No updated events if the topology changed

I'm using 3 Sonos 1 and 1 Sonos Connect. Because the Connect tends to heat up my tv cabinet even when it is not in use I cut the power regularly. In case this happens, i. e. the topology changes, sonos2mqtt doesn't send events any more. This can be worked around by restarting the container.

"prefix" not working for control

When I use the prefix argument (through docker as -e SONOS2MQTT_PREFIX=devices/sonos) topics get populated correctly but my control commands seem to be ignored.

Input wanted: Return data from command

A lot of sonos commands return data, like the following:

Currently you could execute these commands, but the response is only displayed in the debug logging.

I'm trying to figure out what is the best way to return the data for these commands.

Suggestion 1 🚀 : Return all responses in a single topic per player. Like:

TOPIC: sonos/UUID/lastCommand
{
  "cmd": "RenderingControlService.GetVolume",
  "response": {
    "CurrentVolume": 40
  }
}

Suggestion 2 👀 : Return the command result in a topic with the name of the command

TOPIC: sonos/uuid/RenderingControlService/GetVolume
{
  "CurrentVolume": 40
}

Can everybody please vote for their solution with the respected emoji?

Related to #100

issue with capital letters in command

I send the following:

sonos/set/Dusche/play

and nothing happens except this in my syslog

Aug 14 17:31:31 kodi-1 sonos2mqtt[4251]: 2019-08-14 17:31:31.331 #33[37m#033[1m#033[41m#33[49m#033[22m#033[39m Device with name dusche not found

sonos2mqtt 1.4.4 running on a raspbian

have you anything changed? --> yes :-) I found it in src/bridge :-)
downgraded to [email protected] and it is not working again

if you need further information feel free to order it :-)

Improperly escaped port colon in CurrentURI

Here's a snippet from my node red configuration. This gets added to sonos with the server:port colon urlescaped. Here's the error message:
Screenshot_20201020-171518

const uri = "x-rincon-mp3radio://cde:8000/stream";

node.send({
    "topic": "devices/sonos/set/office/adv-command",
    "payload": {
        "cmd": "AVTransportService.SetAVTransportURI",
        "val": {
            "InstanceID": 0,
            "CurrentURI": uri,
            "CurrentURIMetaData": {
                "Title": "My Stream",
                "AlbumArtUri": "http://myserver.com/albumart.png",
                "UpnpClass": "object.item.audioItem.audioBroadcast"
            }
        }
    }
});
node.send({
    "topic": "devices/sonos/set/office/play",
    "payload": ''
});

Spoken message appears as a short gap of silence if streaming/playing

On v2.0.11

When playing an Album or when playing a Spotify playlist on the Sonos, most times the spoken message fails and is replaced with a very short period of silence. (Timing issue?) (In my Sonos app I can see the message clip file name showing up briefly) Sometimes, randomly the message gets spoken correctly. When that happens resuming the streamin/playing wont happen. Furthermore volume level is not restored to the level that was actual when streaming/playing.

FWIW I don't know anything why this happens but it sounds like a series of commands are sent to Sonos asynchronously. Maybe Sonos can not handle that. Sonos might not have a command queue and as a result discards previous commands when a new comes in. Just a thought.

Spotify trackURI

I'm trying to figure out how to encode a trackURI for Spotify, and I just don't get it.

So, from the dokumentation, the format should look like this:

x-sonos-spotify:spotify:track:30cW9fD87IgbYFl8o0lUze?sid=9&flags=8224&sn=7

The first part is easy enough, and I can get the Spotify URI from the Spotify client which brings me to:

x-sonos-spotify:spotify:track:3b9xTm2eiaCRTGqUEWuzxc

What trips me up is sid, flags and sn. I can't find any information on what that is and how to find them.

Error executing joingroup

I'm having some problems joining devices together into groups.

For example, I have one device named "Vardagsrum" and another named "Kök". I've tried the following:

/sonos/set/kök/command -> JSON {"cmd":"joingroup", "val":"Vardagsrum"}
/sonos/set/kök/joingroup -> String Vardagsrum

/sonos/set/kök/command -> JSON {"cmd":"joingroup", "val":"vardagsrum"}
/sonos/set/kök/joingroup -> String vardagsrum

...and the other way around. In all cases I get " Error executing joingroup for Kök {}" in the logfile. Leavegroup, play, stop and so forth works just fine. I even tried renaming Kök to Kok to see if it was an UTF-8 problem, same result.

Am I doing something stupid? ;)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.