Node Red Sonos Join Speaker Issue with Source

Hi All! I have two Sonos Speakers, Kitchen Speaker and an Overhead Speaker, that I intend to always have joined. Sometimes they come unjoined for a variety of reasons so I created the Flow below to check the grouping of these speakers and join them. However when I call the service to join the speakers, the Source changes from TV to no source.

There is no ability to call {“source”:“TV”} because this does nothing. So I have three separate questions:

  1. Is there something wrong with the Flow causing the loss of the Sonos source?
  2. Is there a way to select the Source TV using a call function? I tried in HA as well as Node Red and the service media.player select_source does not even have the option to Select TV (only line-in)?
  3. Is there a better way to design the Flow to avoid this problem.

Flow below:

[{"id":"1e7b9ce287bdc9cd","type":"api-call-service","z":"23b7103827a39559","name":"","server":"6e751b1b.8f17c4","version":5,"debugenabled":false,"domain":"media_player","service":"volume_set","areaId":[],"deviceId":[],"entityId":["media_player.kitchen_overhead_speaker"],"data":"{ \"volume_level\" : {{ volume}} }","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":1090,"y":240,"wires":[[]]},{"id":"f6fb873ca2102366","type":"function","z":"23b7103827a39559","name":"","func":"const msgTV = {};\nconst msgOverhead = { };\n\nvar TV_volume = msg.data.new_state.attributes.volume_level;\n\nif (TV_volume >= 0.15 && TV_volume < 0.8){\n    msgTV.volume = TV_volume;\n    msgOverhead.volume = 1.1 * TV_volume;\n}else if (TV_volume >= 0.8 ){\n    msgTV.volume = TV_volume;\n    msgOverhead.volume = 1;\n}else{\n    msgTV.volume = TV_volume;\n    msgOverhead.volume = 0.0;\n}\n\nreturn [msgTV, msgOverhead];","outputs":2,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":180,"wires":[["f5998d2e67e64c36"],["1e7b9ce287bdc9cd"]]},{"id":"2681c288b53490ea","type":"trigger","z":"23b7103827a39559","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"500","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":580,"y":180,"wires":[["f6fb873ca2102366"]]},{"id":"f5998d2e67e64c36","type":"api-call-service","z":"23b7103827a39559","name":"","server":"6e751b1b.8f17c4","version":5,"debugenabled":false,"domain":"media_player","service":"volume_set","areaId":[],"deviceId":[],"entityId":["media_player.kitchen_tv_speaker"],"data":"{ \"volume_level\" : {{ volume}} }","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":1090,"y":200,"wires":[[]]},{"id":"086ee29fac5f166f","type":"delay","z":"23b7103827a39559","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"outputs":1,"x":350,"y":180,"wires":[["2681c288b53490ea"]]},{"id":"3d20d0a15ff3d71a","type":"server-state-changed","z":"23b7103827a39559","name":"Kitchen Speaker","server":"6e751b1b.8f17c4","version":5,"outputs":1,"exposeAsEntityConfig":"","entityId":"media_player.kitchen_tv_speaker","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":180,"wires":[["086ee29fac5f166f","1433eb2709ccaae9","52031c1fc9ddcd08"]]},{"id":"1433eb2709ccaae9","type":"switch","z":"23b7103827a39559","name":"","property":"data.new_state.attributes.is_volume_muted","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":240,"wires":[["3f41a62a0590b867"],["f779a2680771f549"]]},{"id":"52031c1fc9ddcd08","type":"api-current-state","z":"23b7103827a39559","name":"Group","server":"6e751b1b.8f17c4","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"media_player.kitchen_overhead_speaker","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":310,"y":120,"wires":[["b8b9c50985ac5968","9b1cf36098a5ae07"]]},{"id":"3f41a62a0590b867","type":"api-call-service","z":"23b7103827a39559","name":"Overhead Mute","server":"6e751b1b.8f17c4","version":5,"debugenabled":false,"domain":"media_player","service":"volume_mute","areaId":["family_room"],"deviceId":["07c7d5c86925a4b11435178a2dcb3343"],"entityId":[],"data":"{\"is_volume_muted\":\"true\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":600,"y":220,"wires":[[]]},{"id":"f779a2680771f549","type":"switch","z":"23b7103827a39559","name":"","property":"data.old_state.attributes.is_volume_muted","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":260,"wires":[["12e9cdd26f325421"],[]]},{"id":"28883100e05eaa48","type":"inject","z":"23b7103827a39559","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":640,"y":80,"wires":[["52031c1fc9ddcd08"]]},{"id":"b8b9c50985ac5968","type":"switch","z":"23b7103827a39559","name":"","property":"data.attributes.group_members[1]","propertyType":"msg","rules":[{"t":"null"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":120,"wires":[["54d635c33399b1b5"],[]]},{"id":"9b1cf36098a5ae07","type":"debug","z":"23b7103827a39559","name":"debug 45","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":540,"y":60,"wires":[]},{"id":"12e9cdd26f325421","type":"api-call-service","z":"23b7103827a39559","name":"Overhead Mute Off","server":"6e751b1b.8f17c4","version":5,"debugenabled":false,"domain":"media_player","service":"volume_mute","areaId":["family_room"],"deviceId":["07c7d5c86925a4b11435178a2dcb3343"],"entityId":[],"data":"{\"is_volume_muted\":\"false\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":610,"y":260,"wires":[[]]},{"id":"54d635c33399b1b5","type":"api-call-service","z":"23b7103827a39559","name":"Join Kitchen","server":"6e751b1b.8f17c4","version":5,"debugenabled":false,"domain":"media_player","service":"join","areaId":[],"deviceId":[],"entityId":["media_player.kitchen_overhead_speaker","media_player.kitchen_tv"],"data":"{\t   \"group_members\":[\t       \"media_player.kitchen_tv_speaker\",\t       \"media_player.kitchen_overhead_speaker\"\t   ]\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":590,"y":120,"wires":[[]]},{"id":"6e751b1b.8f17c4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

I can’t comment on how it works in Node-Red but in the Automation Editor it lets you type whatever you want in the Source field (obviously it needs to be an actual source).

Correct. When I type in TV, the source will not change to TV. The only Source I have successfully been able to select is “Line-In” which does me no good.

Which one of your two Sonos speakers is physically connected to your TV?

Kitchen_TV - Sonos Beam

When you join the Beam with the other speaker, is the Beam the master?

Just confirmed. The Beam is the master.