svrooij / sonos2mqtt

:speaker: Sonos mqtt controller. Control your speakers from your mqtt server. mqtt-smarthome insprired.
https://sonos2mqtt.svrooij.io/
MIT License
76 stars 18 forks source link

Run sonos2mqtt without speakers online #131

Open svrooij opened 3 years ago

svrooij commented 3 years ago

Should investigate if it would be possible to run sonos2mqtt when there are no players online. Think battery powered....

Currently this app is build to subscribe to group changes from one player and use that data to power the app.

Needed features:

Prerequisites: At least a single player should be online when starting the app, else it won't know what to do. Or maybe a configuration that says I know there may not be any players, just continue.


Hello everybody,

I would like to reopen and expand this Issues. Is there a way to start the Docker Container if there is currently no Sonos device in the network? The reason for this is that the Sonos devices are not always on power. The container always stops after two attempts.

Thanks :-)

Originally posted by @rliegmann in https://github.com/svrooij/sonos2mqtt/issues/123#issuecomment-753538611

BillSobel commented 3 years ago

Can I suggest you cache your discovery from the previous run? Sonos equipment isn't likely to be added/removed so a cache would be perfect here.

svrooij commented 3 years ago

It's not just a matter of knowing the devices. This entire app is build based in the fact that it will receive events from the speakers.

Maybe it's better to just use the docker restart policy.

Also only a single speaker has to be online when you start sonos2mqtt. Then they can go offline (except the one sending the zone events).

rliegmann commented 3 years ago

Unfortunately I only have one SONOS speaker at the moment. :cry: At the moment, the Docker container keeps restarting in a loop. Maybe you could only loop the "start" metothe in the "index.ts" in interval. As soon as the speaker is back, it continues to run normally.

svrooij commented 3 years ago

Maybe a quick solution would be to make the discovery timeout configurable. Now it’s just static 10 seconds. What if we make that configurable and you set it to 180 seconds

rliegmann commented 3 years ago

Are the 10 seconds defined in the node-somos-ts or in the sonos2mqtt? If the discovery time is increased, does the Docker container still restart? Is there maybe the possibility to let the container run and to let the discovery run further?

svrooij commented 3 years ago

It’s defined here, https://github.com/svrooij/node-sonos-ts/blob/b6e73140375569d25839785c441f512aaa7c354d/src/sonos-manager.ts#L49

but it would be easy to make it configurable in sonos2mqtt

binford6000 commented 2 months ago

I'm using sonos2mqtt since years now but i'm still waiting for this issue to be solved. Any updates on this @svrooij ?

svrooij commented 2 months ago

@binford6000 You want to run it without a single player online?

The thing is, it won't know what to do. I don't have any battery powered speakers, all my speakers are online all the time.

The specs for this feature are really vague so I'm not sure how to resolve this.

binford6000 commented 2 months ago

You want to run it without a single player online?

No but with only one player. All my players are connected to smart plugs and depending on presence/absence/time-of-day i want to switch of some players. But even with restarting s2m with only one player and SONOS2MQTT_DEVICE=10.3.3.142 pointing to the player online i couldn't control the player. At least there have to be two players online.

binford6000 commented 1 month ago

Typical situation in the evening: I turn off a SONOS One player in my office (10.3.3.143) and do a restart of s2m. First everything seems to be fine but then this error occurs in 10s interval: Node.js v20.12.2 2024-09-28T20:24:22.908Z [Information] Starting sonos2mqtt v3.2.0-beta.19 2024-09-28T20:24:22.927Z [Information] LogLevel changed to information 2024-09-28T20:24:22.946Z [Information] Found 3 sonos speakers 2024-09-28T20:24:22.981Z [Information] Mqtt connection changed to connected: true /usr/local/lib/node_modules/sonos2mqtt/node_modules/node-fetch/lib/index.js:1501 reject(new FetchError(request to ${request.url} failed, reason: ${err.message}, 'system', err)); ^ FetchError: request to http://10.3.3.143:1400/xml/device_description.xml failed, reason: connect EHOSTUNREACH 10.3.3.143:1400 at ClientRequest.<anonymous> (/usr/local/lib/node_modules/sonos2mqtt/node_modules/node-fetch/lib/index.js:1501:11) at ClientRequest.emit (node:events:518:28) at Socket.socketErrorListener (node:_http_client:500:9) at Socket.emit (node:events:518:28) at emitErrorNT (node:internal/streams/destroy:169:8) at emitErrorCloseNT (node:internal/streams/destroy:128:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { type: 'system', errno: 'EHOSTUNREACH', code: 'EHOSTUNREACH' } s2m still tries to find the SONOS One at its address 10.3.3.143 although the config file says 10.3.3.142 (SONOS Beam) is the config device. And this device is still up and running btw...