Sonos, and Harmony, and Node-Red, oh why?

We use Sonos for all our home audio needs (some behind amps) and love them. Most of the functionality works great for us as is, except one thing. When our TV’s is turned on the Playbase/Sub attached to it, are removed from our “whole house” groups in Sonos. Sonos does this automatically to allow them play TV sound on the devices (as it should).

My issue WAS that Sonos does NOT put those units back into the group when the TV is turned off. The units are centrally located in the home, and sorely missed when not in the “whole house” group. That often meant going to the iPad and putting them back into the group manually (I know right!).

That’s where this little NR sequence comes in. Yes it is fairly basic, but effective. If you have these devices, and face this minor inconvenience here’s a solutions.

Summary - When the Harmony Hub is turned on, it reads the current volume for that ‘Zone’ and stores it in a global variable. Then when the hub is turned off, it gets that stored variable, restores the original volume, and moves the units back into the group. This is helpful since we often listen to TV (movies) louder than we do when using the devices in the “whole house” Sonos group. This extra step restores the balance between zones.

Sequence

[{"id":"1e7bc09e.b40caf","type":"group","z":"f9597acb.134848","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["320b0623.8a660a","1760ab96.415fa4","dc7e49f7.8e0ae8","49febb9d.8a2604","54f2aa56.576894","9df8c397.41fbc","f42717f6.aeeb78","5a9283a9.b0366c","b79cd93c.d1af98"],"x":34,"y":119,"w":1092,"h":222},{"id":"320b0623.8a660a","type":"sonos-universal","z":"f9597acb.134848","g":"1e7bc09e.b40caf","confignode":"a2851dcd.8e5b3","compatibilityMode":false,"command":"player.join.group","state":"Kitchen Sonos","stateType":"str","name":"","x":1020,"y":260,"wires":[[]]},{"id":"1760ab96.415fa4","type":"comment","z":"f9597acb.134848","g":"1e7bc09e.b40caf","name":"Set Living Room Sonos Volume/Move back to Group when Off","info":"","x":500,"y":300,"wires":[]},{"id":"dc7e49f7.8e0ae8","type":"function","z":"f9597acb.134848","g":"1e7bc09e.b40caf","name":"Get playbaseVolume setting","func":"var msg = {};\n\nvar playbaseVolume = global.get(\"playbaseVolume\")\n\n\nif (playbaseVolume) {\n    msg.payload = playbaseVolume ;\n    return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":260,"wires":[["5a9283a9.b0366c"]]},{"id":"49febb9d.8a2604","type":"hubitat device","z":"f9597acb.134848","g":"1e7bc09e.b40caf","deviceLabel":"Living Room - -Harmoney Hub","name":"","server":"e03140c5.bed32","deviceId":"257","attribute":"switch","sendEvent":true,"x":190,"y":220,"wires":[["f42717f6.aeeb78"]]},{"id":"54f2aa56.576894","type":"sonos-universal","z":"f9597acb.134848","g":"1e7bc09e.b40caf","confignode":"a2851dcd.8e5b3","compatibilityMode":false,"command":"player.get.volume","state":"","stateType":"str","name":"","x":570,"y":200,"wires":[["9df8c397.41fbc"]]},{"id":"9df8c397.41fbc","type":"change","z":"f9597acb.134848","g":"1e7bc09e.b40caf","name":"set playbaseVolume","rules":[{"t":"set","p":"playbaseVolume","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":200,"wires":[[]]},{"id":"f42717f6.aeeb78","type":"switch","z":"f9597acb.134848","g":"1e7bc09e.b40caf","name":"On/Off","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":390,"y":220,"wires":[["54f2aa56.576894"],["dc7e49f7.8e0ae8"]]},{"id":"5a9283a9.b0366c","type":"sonos-universal","z":"f9597acb.134848","g":"1e7bc09e.b40caf","confignode":"a2851dcd.8e5b3","compatibilityMode":false,"command":"player.set.volume","state":"","stateType":"str","name":"","x":830,"y":260,"wires":[["320b0623.8a660a"]]},{"id":"b79cd93c.d1af98","type":"comment","z":"f9597acb.134848","g":"1e7bc09e.b40caf","name":"Get Living Room Sonos Volume when TV is turned on. ","info":"","x":480,"y":160,"wires":[]},{"id":"a2851dcd.8e5b3","type":"sonos-config","name":"Living Room Sonos","serialnum":"B8:E9:37:46:C4:36","ipaddress":"10.20.1.92"},{"id":"e03140c5.bed32","type":"hubitat config","name":"Apps Hub","usetls":false,"host":"10.20.1.22","port":"80","appId":"899","nodeRedServer":"http://10.13.9.28:1880","webhookPath":"/hubitat/webhook___","autoRefresh":true,"useWebsocket":false}]

5 Likes

Nice!

I don’t use the same Sonos nodes, but I also do something similar with the nodes that I use, which require node-sonos-http-api.

One of my Sonos sequences that I particularly like automatically raises/lowers the Sonos Playbar volume in my Living Room based on whether the HVAC air-handler is on or not.

I put a current sensor switch on the neutral for the air-handler blower, and wired it to the external terminals of a GoControl contact sensor. When the air-handler comes on, the sensor signals “closed”, the Playbar volume is raised by 10, and then is lowered by 10 when the air-handler turns off.

A simple yet valuable sequence that promotes laziness! :smile:

But, in the end, isn’t that what automation’s all about?

2 Likes

Do those nodes offer additional functionality? It seems they may.

I don’t know, I’ve never used the other ones. These are much older. I think the ones you use are better - I just never got around to updating …