hklages / node-red-contrib-sonos-plus

A set of Node-RED nodes to control SONOS player in your local network.
MIT License
76 stars 14 forks source link

Play notification on ALL (or a group of) players and resume with anything they did before #26

Closed Markus- closed 4 years ago

Markus- commented 4 years ago

Hi,

just discovered this node and I am playing around.

How would you achieve this? I want to use my speakers as doorbell, but after playing the notification the music doesn't resume.

Regards Markus

Markus- commented 4 years ago

Ok, I kept playing around and it seems that the queue is kept.

So pseudo-code

  1. get state of all players
  2. Get position in queue / song
  3. play notification
  4. resume on players which were playing before a. Starting the queue again is no problem b. How can I start the queue at a given song at a given time?

Regards Markus

hklages commented 4 years ago

There is no perfect solution so far. Is your "grouping" topology static? In that case you can use play_notification and send it to all group leaders and maybe check before whether they are playing (get_state).

Can you explain: "... but after playing the notification the music doesn't resume." Did you use play_notification?

Markus- commented 4 years ago

I have 8 Sonos Players in 7 Groups (1 pair).

If I hear music my office while my wife listening to a radio station in the kitchen the doorbell should ring on all speakers in the house. But after the bell the office and the kitchen should resume playing while all other players remains off.

I tried play_notification but then the mp3 is played an it stops afterwards.

As posted above the queue seems to stay in its original state.

So can you answer 4b? Is it possible to start the song at a given time? I now <#Number>:play_song start the correct song, but I would need to resume the song at e.g. 3:45.

ma-gu-16 commented 4 years ago

Same Problem and the following error in Debug:

"play notification - Request failed with status code 412 :: Details: {"stack":"Error: Request failed with status code 412\n at createError (/usr/local/addons/redmatic/var/node_modules/node-red-contrib-sonos-plus/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/usr/local/addons/redmatic/var/node_modules/node-red-contrib-sonos-plus/node_modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.handleStreamEnd (/usr/local/addons/redmatic/var/node_modules/node-red-contrib-sonos-plus/node_modules/axios/lib/adapters/http.js:236:11)\n at IncomingMessage.emit (events.js:203:15)\n at IncomingMessage.EventEmitter.emit (domain.js:448:20)\n at endReadableNT (_stream_readable.js:1143:12)\n at process._tickCallback (internal/process/next_tick.js:63:19)","message":"Request failed with status code 412","config":{}}"

hklages commented 4 years ago

Hi, can you pleas try:

payload: play_notification topic: http://soundbible.com/mp3/foghorn-daniel_simon.mp3 and send it to a player not being in any group.

Does that work? If not, what is playing when you start play_notification

Im not able to reproduce the error.

I will revise this command in the next weeks. The error/debug messages don't provide sufficient information. I opened already an issue at sonos-bean but so far does not have any solution.

hklages commented 4 years ago

@Markus, regarding 4b. The underlying package node-sonos provides a "seek" command to move forward a specific amount of seconds. That is used in play_notification. If it helps I can make it available here. That only works for songs in the queue - obviously.

play_song accepts already as topic the number of the song in queue.

Markus- commented 4 years ago

That would be awesome. I could test it if you want. Regards Markus

ma-gu-16 commented 4 years ago

Hi short Feedback,

It works if i send notification to just 1 speaker , he leaves group playes notification und after he joins group back.

i guess it should be possible to send notfication to all speakers.

thx

Markus- commented 4 years ago

I think you are talking about sth. different.

This issue is about the following scenario:

ma-gu-16 commented 4 years ago

I think you are talking about sth. different.

This issue is about the following scenario:

  • I listen to music in my office
  • The doorbell / any other event triggers a notification
  • My office speaker plays the notification
  • After the notification I want the original music to play (from the point it stops)

Excatly, this scenario works already as you descriped. There is Just a problem if you want send it to every speaker AT Same time.

Markus- commented 4 years ago

Not for me. Could you post an example flow?

Tested:

Markus

ma-gu-16 commented 4 years ago

Hi ,

sure:

[ { "id": "3fb54d4d.eaad72", "type": "comment", "z": "86bfc13c.62e37", "name": "Klingel", "info": "", "x": 110, "y": 1120, "wires": [] }, { "id": "99368111.3f76e", "type": "inject", "z": "86bfc13c.62e37", "name": "trigger", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 130, "y": 1180, "wires": [ [ "4749a06d.4b1f9" ] ] }, { "id": "4749a06d.4b1f9", "type": "change", "z": "86bfc13c.62e37", "name": "play_notification - local file - with volume", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "play_notification", "tot": "str" }, { "t": "set", "p": "topic", "pt": "msg", "to": "http://192.168.0.999/addons/red/static/bell.mp3", "tot": "str" }, { "t": "set", "p": "volume", "pt": "msg", "to": "30", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 360, "y": 1226, "wires": [ [ "4aad6823.1a13d8" ] ] }, { "id": "4aad6823.1a13d8", "type": "sonos-control-player", "z": "86bfc13c.62e37", "confignode": "31fa4195.a148ee", "name": "", "x": 640, "y": 1220, "wires": [ [] ] }, { "id": "ae2e3e43.f469d", "type": "ccu-value", "z": "86bfc13c.62e37", "name": "", "iface": "HmIP-RF", "channel": "001498A99873F2:0 Klingel:0", "datapoint": "RSSI_DEVICE", "mode": "", "start": true, "change": true, "cache": false, "queue": false, "on": 0, "onType": "undefined", "ramp": 0, "rampType": "undefined", "working": false, "ccuConfig": "38263145.35ea0e", "topic": "${CCU}/${Interface}/${channel}/${datapoint}", "x": 120, "y": 1260, "wires": [ [ "4749a06d.4b1f9", "a2ef847b.440e08" ] ] }, { "id": "a2ef847b.440e08", "type": "debug", "z": "86bfc13c.62e37", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 270, "y": 1280, "wires": [] }, { "id": "31fa4195.a148ee", "type": "sonos-config", "z": "", "name": "Sonos Schlafzimmer", "serialnum": "xx-xx-xx-xx-xx-xx:2", "ipaddress": "192.168.0.99" }, { "id": "38263145.35ea0e", "type": "ccu-connection", "z": "", "name": "localhost", "host": "localhost", "regaEnabled": true, "bcrfEnabled": true, "iprfEnabled": true, "virtEnabled": true, "bcwiEnabled": true, "cuxdEnabled": false, "regaPoll": true, "regaInterval": "30", "rpcPingTimeout": "60", "rpcInitAddress": "127.0.0.1", "rpcServerHost": "127.0.0.1", "rpcBinPort": "2047", "rpcXmlPort": "2048", "queueTimeout": "5000", "queuePause": "250", "contextStore": "" } ]

My current Flow: I have 4 Sonos Speaker, I Set Spotify Playlist to Livingroom Speaker, take the Name of Livingroom Speaker and group all the other Speakers to Livingroom.

I observed everthing with the sonos app for windows.

If I ring the door now, the Bedroom speaker leaves the group and play bell.mp3 after he is finished he joins back the group and continue playing on same seek/time as the others.

Greetings.

Markus- commented 4 years ago

It looks like mine. Probably the reason is that I use Napster?

@hklages: Is this possible? I created an issue for Napster (u already commented). Beside this the seek-function could be very helpful.

Markus

hklages commented 4 years ago

Hi again.

regarding see: seek is already working in my test environment and will be publish together with other features next week.

regarding play_notification You can test it by your own: Play any TuneIn radio station or a playlist form your NAS or ... and try play_notification. That should work.

As ma-gu-16 wrote: play_notification works fine at least with Spotify, Amazon, TuneIn (maybe with more - not tested ). Sending the command to a "slave" in a group causes the player to leave the group, play notification and then join the group again. Sending a command to a master/leader means play it on all grouped players and after return to the previous song.

Markus- commented 4 years ago

Hi. Nice that you will integrate the seek functionality.

I can not get the play-notification-thing. I created an example-flow: Could you retry it - I used a radio-station.

Does the following flow works for you? [{"id":"ff1848c8.05b548","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"7205d0ab.f49eb","type":"change","z":"ff1848c8.05b548","name":"Play Radio WDR2","rules":[{"t":"set","p":"payload","pt":"msg","to":"play_tunein","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"s24896","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":473,"y":223,"wires":[["99abec29.d2b9c"]]},{"id":"99abec29.d2b9c","type":"sonos-manage-radio","z":"ff1848c8.05b548","confignode":"1298581.c93bfa8","name":"","x":670,"y":223,"wires":[["10cd5bc2.8f06a4"]]},{"id":"9bd68af7.b59f78","type":"inject","z":"ff1848c8.05b548","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":272.5,"y":223,"wires":[["7205d0ab.f49eb"]]},{"id":"10cd5bc2.8f06a4","type":"delay","z":"ff1848c8.05b548","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":935.5,"y":221,"wires":[["fa1c10a.65099f"]]},{"id":"fa1c10a.65099f","type":"change","z":"ff1848c8.05b548","name":"play_notification - local file - with volume","rules":[{"t":"set","p":"payload","pt":"msg","to":"play_notification","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"http://soundbible.com/mp3/foghorn-daniel_simon.mp3","tot":"str"},{"t":"set","p":"volume","pt":"msg","to":"5","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1248,"y":224,"wires":[["c2640dba.4ecd7"]]},{"id":"c2640dba.4ecd7","type":"sonos-control-player","z":"ff1848c8.05b548","confignode":"1298581.c93bfa8","name":"","x":1596,"y":226,"wires":[[]]},{"id":"1298581.c93bfa8","type":"sonos-config","z":"","name":"SONOS-AZM","serialnum":"","ipaddress":"10.10.0.7"}]

hklages commented 4 years ago

Yes. your flow works at my system. (Raspberry Pi 4, node-red). Player: Beam, Sonos5, Sonos3.

I changed the player config name and the flow first switches to SWR3 (in spite of the node text WDR2), then plays the horn notification and after it continues to play SWR3.

What players do you use?

hklages commented 4 years ago

@ma-gu-16: when do you receive that error - message?

Markus- commented 4 years ago

Yes. your flow works at my system. (Raspberry Pi 4, node-red).

Ok, good to know

What players do you use?

Only Play:1 (old version without micro).

Probably my network is the problem. The speakers are in another subnet. I will check my igmp-repeater.

Regards Markus

ma-gu-16 commented 4 years ago

@ma-gu-16: when do you receive that error - message?

Hi, the Error occurs, when i try to send notification to the "main"- sonos speaker. Its not like you described, the notification doesnt sound on alle speakers.

i send now the notification to all sub speakers by my own. so 1 speaker is still playing musik, thats fine for me.

greetings

hklages commented 4 years ago

I tested it on a Play1 - it works also there.

So either network or infrastructure.

This is my installation: node-red: 1.0.3 node-red-contrib-sonos-plus: 1.3.0 sonos: 1.12.6 (the library i use) axios: 0.19.0 (is for http requests) node: v10.15.2

node version: shell, just enter node -v. All other information are in package.json in the corresponding directory under node-red.

Markus- commented 4 years ago

Ok, will check it (hopefully this weekend). Thanks for the info.

Regards Markus

Markus- commented 4 years ago

Sorry for the delay, because of being in "production" and my wife's "presence" at home I am not able to rebuild my network...

I think you can close this issue because a. You provided a "fix" for me with manual seeking the correct position b. it works for others than me.

Thanks a lot for your help - I will try it as soon as possible.

Regards Markus

Markus- commented 4 years ago

Hi.

It works now. After implementing igmp-proxy and some firewall-rules everything works as expected. THANKs.

hklages commented 4 years ago

Great to hear. Thanks for the feedback. Does Napster also work?

Markus- commented 4 years ago

I think so. But I have to check a little bit more.

I created a flow where I send a notification through links to 6 Speakers at once. This seems to produce an error: "play notification - Request failed with status code 412 :: Details: {"stack":"Error: Request failed with status code 412\n at createError (/usr/local/addons/redmatic/var/node_modules/node-red-contrib-sonos-plus/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/usr/local/addons/redmatic/var/node_modules/node-red-contrib-sonos-plus/node_modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.handleStreamEnd (/usr/local/addons/redmatic/var/node_modules/node-red-contrib-sonos-plus/node_modules/axios/lib/adapters/http.js:236:11)\n at IncomingMessage.emit (events.js:203:15)\n at endReadableNT (_stream_readable.js:1145:12)\n at process._tickCallback (internal/process/next_tick.js:63:19)","message":"Request failed with status code 412","config":{}}"

Markus- commented 4 years ago

Should I open a new issue for this error?

It worked at the beginning when I played around with a single player. Then after I sent the message to all players those error occurred.

From then the notification is played, but it does not return to the original playback. And also this error message occurres.

hklages commented 4 years ago

Yes please open a new issue.

Please install 2.1.4 (I made a small change in the notification command). And please provide some more information: Does it work for 1 or 2 speaker? Are the speaker grouped? What flow? Thanks.

hklages commented 4 years ago

@ma-gu-16: You wrote:

If I ring the door now, the Bedroom speaker leaves the group and play bell.mp3 after he is finished he joins back the group and continue playing on same seek/time as the others.

You are right - in several cases the speaker leaves the group and joins it later. I some case the group is untouched and only the volume is adjusted for one player.