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

joiner.play.notification temporarily sets group volume to notification volume #288

Closed The0sirian closed 5 months ago

The0sirian commented 6 months ago

Description

When playing a joiner.play.notification the joiner leaves the group correctly and plays the notification. After the notification has been played the group sets itself to the volume supplied to the notification, and when the joiner rejoins the group, slowly the group resets its volume back to the original value. The joiner joins the group with the correct volume already applied.

I inject the joiner.play.notification with msg.volume 75. If i don't supply a volume in the injecting payload the group volume doesn't change which makes sense because the notification uses its volume state

What node/command (topic)/state (payload)

node: Universal command: joiner.play.notification

In case of a bug: Are you able to reproduce the error

yes

Versions and Infrastructure

what system: Home Assistant on a thin client node-red-contrib-sonos-plus version: Latest Node-RED version: v18.19.1 NodeJS version: not sure, i think v3.1.8 (i am new to this sorry)

hklages commented 6 months ago

Hi. Is the joiner different from the coordinator of the group? Update on 2024-04-06: Sorry for that question - the package checks that and there thats not possible.

In my test environment the joiner leaves the group, plays the mp3 with the given volume and the other players keep there volume, even after the joiner having joined the group.

Can it be that in your installation in the meanwhile other flows or Home Assistant increases the volume?

The0sirian commented 6 months ago

Hi, thanks for getting back to me. I haven't been able to reply sooner because i was away for the weekend.

As you stated it is not the joiner indeed, when trying a forced player that is also the joiner i get an error message.

The player leaves the group just fine and plays the notification at the volume i give it. When it's trying to return the volume of the speakers in that group goes up to the value i've given to the notification. They reset after a little while but this is annoying when music is playing off course. I have recorded it on my phone for you. I have recorded it from the group screen, because the volume screen pops out after a few seconds. That is why it seems as if the player does not leave the group.

https://www.youtube.com/shorts/JYeIjDy8P_M

My node red setup (while testing) is an inject with "msg.playerName: Sonos - Werkkamer - Klok" and "msg.volume: 75" leading into the joiner.play.notification node that has a url to the MP3 file as the payload.

hklages commented 6 months ago

hi. Is noder-RED installed as a Home Assistant add on? Are you able to edit a file with vi, vscode Or nano? Then we can enable debugging and get more information.

On Sun, Apr 7, 2024, 23:44 The0sirian @.***> wrote:

Hi, thanks for getting back to me. I haven't been able to reply sooner because i was away for the weekend.

As you stated it is not the joiner indeed, when trying a forced player that is also the joiner i get an error message.

The player leaves the group just fine and plays the notification at the volume i give it. When it's trying to return the volume of the speakers in that group goes up to the value i've given to the notification. I have recorded it on my phone for you. I have recorded it from the group screen, because the volume screen pops out after a few seconds. That is why it seems as if the player does not leave the group.

https://www.youtube.com/shorts/JYeIjDy8P_M

My node red setup (while testing) is an inject with "msg.playerName: Sonos

  • Werkkamer - Klok" and "msg.volume: 75" leading into the joiner.play.notification node that has a url to the MP3 file as the payload.

— Reply to this email directly, view it on GitHub https://github.com/hklages/node-red-contrib-sonos-plus/issues/288#issuecomment-2041618666, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEDZCH5PAO6AHYUB7HT4S3DY4G45FAVCNFSM6AAAAABFYU4GAKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGYYTQNRWGY . You are receiving this because you were assigned.Message ID: @.***>

The0sirian commented 5 months ago

Yeah i have Node-RED installed as an addon in Home Assistant. VScode is installed and i can access the nodered folder in my config from it.

hklages commented 5 months ago

How do you define the groups? In Home Assistent with Mediaplayer or in Node-RED?

Do you use any Home Assistent scripts or automations controlling the SONOS player?

My guess is that there is something in the background messing up the notification.

On Mon, Apr 8, 2024, 06:56 The0sirian @.***> wrote:

Yeah i have Node-RED installed as an addon in Home Assistant. VScode is installed and i can access the nodered folder in my config from it.

— Reply to this email directly, view it on GitHub https://github.com/hklages/node-red-contrib-sonos-plus/issues/288#issuecomment-2041861545, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEDZCH2GQTZ3SFKNYHLXVUTY4IPOBAVCNFSM6AAAAABFYU4GAKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRHA3DCNJUGU . You are receiving this because you were assigned.Message ID: @.***>

The0sirian commented 5 months ago

The groups have been defined in the Sonos app itself. I don't have any automations within Home Assistant, apart from the flows in Node-RED. None of them are active at the moment of testing.

Your reply has put me on the right track though. I ungrouped all speakers through the Sonos app. I then group them through node-RED (player.join.group). When i play a notification now it works as it is supposed to. So the issue was that the groups were created with the Sonos app.

Tremendous thanks for helping me on this. I will continue to test this out the coming days and report back to you if my findings change, but it seems like this was the issue.

hklages commented 5 months ago

super! Instead of player.join.group you can also define groups with household.create.group - that should be faster and is a single command.

It is new to me that the SONOS app tracks the group definition. I will also do some tests during the next day.

Thanks for the feedback and letting me know that!

The0sirian commented 5 months ago

Sadly i could not get household.create.group to work, i think it has to do with my player names being "Sonos - Werkkamer - Kast" But my next project is to get that working :D including how to queue commands so that nothing interferes

hklages commented 5 months ago

That's a reasonable name. It should work.

Let me see what I can do to make it work.

When I implemented that function some years ago I was was very restrictive regarding the syntax of the player names. But definitely too restrictive ...

On Wed, Apr 10, 2024, 07:22 The0sirian @.***> wrote:

Sadly i could not get household.create.group to work, i think it has to do with my player names being "Sonos - Werkkamer - Kast" But my next project is to get that working :D

— Reply to this email directly, view it on GitHub https://github.com/hklages/node-red-contrib-sonos-plus/issues/288#issuecomment-2046559057, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEDZCH5HIZCB6S6IW36TDB3Y4TEBNAVCNFSM6AAAAABFYU4GAKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBWGU2TSMBVG4 . You are receiving this because you were assigned.Message ID: @.***>

The0sirian commented 5 months ago

It must have to do with the -'s in my names. When i only link "Slaapkamer" and "Woonkamer Voor" but as soon as i add one with a - in it it gives me an error. So i am just gonna remove the -'s from my list.

If you have the time, it would be greatly appreciated if you could guide me into the direction of how to queue commands. I cannot find out how i do that exactly. Is this a node from your integration?

hklages commented 5 months ago

Right. You can use either Sonos-Werkkamer-Kast or Sonos Werkkamer Kast

When using create group you need to separate each player by "," and must not add any blanks.

On Wed, Apr 10, 2024, 07:22 The0sirian @.***> wrote:

Sadly i could not get household.create.group to work, i think it has to do with my player names being "Sonos - Werkkamer - Kast" But my next project is to get that working :D

— Reply to this email directly, view it on GitHub https://github.com/hklages/node-red-contrib-sonos-plus/issues/288#issuecomment-2046559057, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEDZCH5HIZCB6S6IW36TDB3Y4TEBNAVCNFSM6AAAAABFYU4GAKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBWGU2TSMBVG4 . You are receiving this because you were assigned.Message ID: @.***>

hklages commented 5 months ago

... What do you mean with the "queue command"? Example? What would you like to achieve?

On Wed, Apr 10, 2024, 08:05 The0sirian @.***> wrote:

It must have to do with the -'s in my names. When i only link "Slaapkamer" and "Woonkamer Voor" but as soon as i add one with a - in it it gives me an error. So i am just gonna remove the -'s from my list.

If you have the time, it would be greatly appreciated if you could guide me into the direction of how to queue commands. I cannot find out how i do that exactly. Is this a node from your integration?

— Reply to this email directly, view it on GitHub https://github.com/hklages/node-red-contrib-sonos-plus/issues/288#issuecomment-2046598853, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEDZCHZ55LRVWWMQU4PRSWLY4TJBNAVCNFSM6AAAAABFYU4GAKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBWGU4TQOBVGM . You are receiving this because you were assigned.Message ID: @.***>

The0sirian commented 5 months ago

The wiki for joiner.play.notification describes needing to queue commands in order to not have any other commands interfere. However i have no idea how to do this, haven't had time to play around today but will do soon.

hklages commented 5 months ago

You only need to implement a queue if there is a chance that 2 notifications arrive at a player at almost the same time. 2 or mored notification at same time will mess up the playing as the notification command is hand made (not a build in SONOS function) and consists of several basic commands executed consecutively.

Here is a simple flow with a queue implemented as function. keep in mind that the status node must be linked to the command group.play.notification / joiner.play.notification.

flow_with_queue

Use the following to import:

[{"id":"e6614d38.1300d","type":"function","z":"6d603261.4bb86c","name":"queue","func":"// modified version - originally from https://gist.github.com/dceejay/cea8afa28b7a93ebdc0f \n\n// restartQueue = create new\nif (msg.hasOwnProperty(\"restartQueue\")) {\n    context.queue = []\n    \n// if queue doesn't exist, create it    \n} else {\n    context.queue = context.queue || []\n    context.busy = context.busy || false\n\n    // if the msg is a trigger one release next message\n    if (msg.hasOwnProperty(\"releaseNext\")) {\n        if (context.queue.length > 0) {\n            var m = context.queue.shift()\n            node.status({ fill: 'green', shape: 'dot', text: context.queue.length })\n            return m \n        }\n        else {\n            context.busy = false;\n        }\n    }\n    else {\n        if (context.busy) {\n            // if busy add to queue\n            context.queue.push(msg);\n        }\n        else {\n        // otherwise we are empty so just pass through and set busy flag\n            context.busy = true;\n            node.status({ fill: 'green', shape: 'dot', text: context.queue.length })\n            return msg;\n        }\n    }\n}\nnode.status({ fill: 'green', shape: 'dot', text: context.queue.length })\n\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":543,"y":325,"wires":[["864a0ad4.6b8df8"]]},{"id":"b35d5186.74779","type":"comment","z":"6d603261.4bb86c","name":"Example 3: From Internet with queue - READ ME","info":"Having added the function node you are able to send several notifications and they all are being played with out mixing up the content. ","x":220,"y":276,"wires":[]},{"id":"79f7acba.65acc4","type":"change","z":"6d603261.4bb86c","name":"with volume","rules":[{"t":"set","p":"volume","pt":"msg","to":"40","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":364,"y":325,"wires":[["e6614d38.1300d"]]},{"id":"864a0ad4.6b8df8","type":"sonos-universal","z":"6d603261.4bb86c","confignode":"88e9fa70.4a53e8","command":"group.play.notification","state":"","stateType":"str","avoidCheckPlayerAvailability":false,"name":"","x":722,"y":325,"wires":[[]]},{"id":"2f9703a1.261d5c","type":"comment","z":"6d603261.4bb86c","name":"↑modify","info":"Select your config node.","x":784,"y":360,"wires":[],"icon":"font-awesome/fa-edit"},{"id":"9ed82e6e.6c0fc","type":"comment","z":"6d603261.4bb86c","name":"↑modify","info":"Modify the path to your file.","x":210,"y":355,"wires":[],"icon":"font-awesome/fa-edit"},{"id":"2f3f7fba.4ad46","type":"change","z":"6d603261.4bb86c","name":"initiate next","rules":[{"t":"set","p":"releaseNext","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":724,"y":282,"wires":[["e6614d38.1300d"]]},{"id":"f9335023.08dea","type":"status","z":"6d603261.4bb86c","name":"","scope":["45324393.696ebc","864a0ad4.6b8df8"],"x":554,"y":282,"wires":[["2f3f7fba.4ad46"]]},{"id":"1e427c4e.1b74d4","type":"inject","z":"6d603261.4bb86c","name":"reset queue","props":[{"p":"restartQueue","v":"true","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":524,"y":380,"wires":[["e6614d38.1300d"]]},{"id":"e4a0f59bdd234061","type":"inject","z":"6d603261.4bb86c","name":"https soundbible foghorn","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"https://soundbible.com/mp3/foghorn-daniel_simon.mp3","payloadType":"str","x":150,"y":325,"wires":[["79f7acba.65acc4"]]},{"id":"88e9fa70.4a53e8","type":"sonos-config","name":"your_player_dns","serialnum":"","ipaddress":"sonoskitchen.fritz.box"}]
hklages commented 5 months ago

It just comes to my mind: There is a new build in function to play a notification - but only on a single player - no group support. It is "player.play.clip" - so far it is un-documented. you can try it.

msg.payload uri of clip (such as http://) msg.volume volume at what the clip is being played msg.playerName SONOS-Playername

For that you don't need any "queue" and it is a nice implementation from SONOS.

The0sirian commented 5 months ago

Oh wow, that is exactly what i needed. I recently moved from Homey (another smart home system) to Home Assistant. This function was exactly what Homey did when playing a notification. Just playing it while the player stayed in the group. Thanks for letting me know this existed!

I have to say i am genuinely amazed at how incredibly helpful the Home Assistant and Node-Red community is. Going the extra mile to help a newbie! Thanks a bunch, enjoy your cappuccino!

hklages commented 5 months ago

Good to hear that we found a solution for your issue.

What was the reason that you moved from homey to Home Assistant? Homey has a good reputation .. that was at least my impression so far. You can use my email @.***" for an answer.

In any case let me know if you have any questions. HA and NodeRED are my hobbies.

And thanks for the cappuccino :-)

On Thu, Apr 11, 2024, 22:21 The0sirian @.***> wrote:

Oh wow, that is exactly what i needed. I recently moved from Homey (another smart home system) to Home Assistant. This function was exactly what Homey did when playing a notification. Just playing it while the player stayed in the group. Thanks for letting me know this existed!

I have to say i am genuinely amazed at how incredibly helpful the Home Assistant and Node-Red community is. Going the extra mile to help a newbie! Thanks a bunch, enjoy your cappuccino!

— Reply to this email directly, view it on GitHub https://github.com/hklages/node-red-contrib-sonos-plus/issues/288#issuecomment-2050458172, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEDZCH3MSFPCIJUJ2LQSMY3Y43WFFAVCNFSM6AAAAABFYU4GAKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJQGQ2TQMJXGI . You are receiving this because you were assigned.Message ID: @.***>