SONOS + IKEA Tradfri

I did not find a similar project, so I started hacking away and got it working (finally). Sharing the code with anybody who cares. If you have suggestions, please let me know :).

Setup: RPi3 with Openhabian, Node-Red, cr2531USB dongle, SONOS Play 1 and IKEA Tradfri Remote.

Requirements:
Button left & right: Change Radiostation (Streaming)
Button up & down: Change Volume
Center Button: Un-/Mute

[{"id":"48ec5f34.b0f0f","type":"tab","label":"Sonos & IKEA Remote ","disabled":false,"info":""},{"id":"4d0d0c46.5c4db4","type":"switch","z":"48ec5f34.b0f0f","name":"","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"toggle","vt":"str"},{"t":"eq","v":"arrow_right_click","vt":"str"},{"t":"eq","v":"arrow_left_click","vt":"str"},{"t":"eq","v":"brightness_up_click","vt":"str"},{"t":"eq","v":"brightness_down_click","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":210,"y":200,"wires":[["a14e02ea.439ae"],["ba69bb32.3de5c8"],["ba69bb32.3de5c8"],["d8a061c2.e63f5"],["f3a32ee.999fcd"]]},{"id":"98b11022.cb08b","type":"zigbee2mqtt-in","z":"48ec5f34.b0f0f","name":"Remote","server":"14016201.7769ae","friendly_name":"IKEA Remote","device_id":"0xbc33acfffe1c2b84","state":"0","outputAtStartup":true,"x":70,"y":200,"wires":[["4d0d0c46.5c4db4"]]},{"id":"a14e02ea.439ae","type":"toggle","z":"48ec5f34.b0f0f","name":"","onOffTopic":"","onValue":"on","onType":"str","offValue":"off","offType":"str","toggleTopic":"","toggleValue":"","toggleType":"any","passOnOff":"ifChanged","x":370,"y":140,"wires":[["9dc6ad09.ce9cc"]]},{"id":"d8a061c2.e63f5","type":"better-sonos-control","z":"48ec5f34.b0f0f","confignode":"723d00ae.be99a","name":"Vol Up","mode":"","track":"","volume":"vol_up","volume_value":"","x":370,"y":240,"wires":[]},{"id":"f3a32ee.999fcd","type":"better-sonos-control","z":"48ec5f34.b0f0f","confignode":"723d00ae.be99a","name":"Vol Down","mode":"","track":"","volume":"vol_down","volume_value":"","x":380,"y":280,"wires":[]},{"id":"9dc6ad09.ce9cc","type":"switch","z":"48ec5f34.b0f0f","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":590,"y":140,"wires":[["128cabcc.584194"],["5172d452.b140ac"]]},{"id":"128cabcc.584194","type":"sonos-universal","z":"48ec5f34.b0f0f","confignode":"25ad6a24.132e56","compatibilityMode":false,"command":"player.set.mutestate","state":"on","stateType":"str","name":"Mute ON","x":860,"y":60,"wires":[[]]},{"id":"5172d452.b140ac","type":"sonos-universal","z":"48ec5f34.b0f0f","confignode":"25ad6a24.132e56","compatibilityMode":false,"command":"player.set.mutestate","state":"off","stateType":"str","name":"Mute OFF","x":860,"y":120,"wires":[[]]},{"id":"e8edb8dc.d4a158","type":"sonos-manage-mysonos","z":"48ec5f34.b0f0f","confignode":"25ad6a24.132e56","compatibilityMode":false,"command":"mysonos.stream.item","state":"Bayern 3","stateType":"str","name":"Bayern 3","x":860,"y":180,"wires":[["73c981db.9fe68"]]},{"id":"59af349.6c1f0cc","type":"sonos-manage-mysonos","z":"48ec5f34.b0f0f","confignode":"25ad6a24.132e56","compatibilityMode":false,"command":"mysonos.stream.item","state":"Jazz24 - KNKX-HD2","stateType":"str","name":"Jazz","x":850,"y":240,"wires":[["123e1910.4f2fc7"]]},{"id":"ce8d3248.2591a","type":"sonos-manage-mysonos","z":"48ec5f34.b0f0f","confignode":"25ad6a24.132e56","compatibilityMode":false,"command":"mysonos.stream.item","state":"Classix Radio","stateType":"str","name":"Pop100","x":860,"y":300,"wires":[["1f0e05b.ac034fa"]]},{"id":"3ebe4bbe.dbe3b4","type":"sonos-manage-mysonos","z":"48ec5f34.b0f0f","confignode":"25ad6a24.132e56","compatibilityMode":false,"command":"mysonos.stream.item","state":"Klassik Radio Piano","stateType":"str","name":"Klassik","x":860,"y":360,"wires":[["d1862827.2f0338"]]},{"id":"e726ab74.46f2f8","type":"switch","z":"48ec5f34.b0f0f","name":"Radio Index to Station","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":640,"y":200,"wires":[["e8edb8dc.d4a158"],["59af349.6c1f0cc"],["ce8d3248.2591a"],["3ebe4bbe.dbe3b4"]]},{"id":"ba69bb32.3de5c8","type":"function","z":"48ec5f34.b0f0f","name":"Station Increment","func":"var radioStationIndex = flow.get('radioStationIndex') || 0;\n\nif (msg.payload.action === \"arrow_right_click\") {\n    radioStationIndex = radioStationIndex + 1;\n        if (radioStationIndex > 3) {\n            radioStationIndex = 0;\n        }\n} else if (msg.payload.action === \"arrow_left_click\") {\n    radioStationIndex = radioStationIndex - 1;\n    if (radioStationIndex < 0) {\n            radioStationIndex = 3;\n        }\n}\n\n\n//msg.payload = radioStationIndex; \nflow.set('radioStationIndex',radioStationIndex);\n//return msg.payload;\n\nvar newMsg = { payload: radioStationIndex };\nreturn newMsg;","outputs":1,"noerr":0,"x":410,"y":200,"wires":[["e726ab74.46f2f8"]]},{"id":"73c981db.9fe68","type":"sonos-universal","z":"48ec5f34.b0f0f","confignode":"25ad6a24.132e56","compatibilityMode":false,"command":"group.play","state":"on","stateType":"str","name":"Group Play","x":1030,"y":180,"wires":[["e3a63deb.6e22f"]]},{"id":"e3a63deb.6e22f","type":"sonos-universal","z":"48ec5f34.b0f0f","confignode":"25ad6a24.132e56","compatibilityMode":false,"command":"player.set.mutestate","state":"off","stateType":"str","name":"Mute OFF","x":1200,"y":180,"wires":[[]]},{"id":"a69a89ef.747518","type":"sonos-universal","z":"48ec5f34.b0f0f","confignode":"25ad6a24.132e56","compatibilityMode":false,"command":"player.set.mutestate","state":"off","stateType":"str","name":"Mute OFF","x":1200,"y":240,"wires":[[]]},{"id":"123e1910.4f2fc7","type":"sonos-universal","z":"48ec5f34.b0f0f","confignode":"25ad6a24.132e56","compatibilityMode":false,"command":"group.play","state":"on","stateType":"str","name":"Group Play","x":1030,"y":240,"wires":[["a69a89ef.747518"]]},{"id":"3e981515.3b272a","type":"sonos-universal","z":"48ec5f34.b0f0f","confignode":"25ad6a24.132e56","compatibilityMode":false,"command":"player.set.mutestate","state":"off","stateType":"str","name":"Mute OFF","x":1200,"y":300,"wires":[[]]},{"id":"1f0e05b.ac034fa","type":"sonos-universal","z":"48ec5f34.b0f0f","confignode":"25ad6a24.132e56","compatibilityMode":false,"command":"group.play","state":"on","stateType":"str","name":"Group Play","x":1030,"y":300,"wires":[["3e981515.3b272a"]]},{"id":"c3f6edf9.78171","type":"sonos-universal","z":"48ec5f34.b0f0f","confignode":"25ad6a24.132e56","compatibilityMode":false,"command":"player.set.mutestate","state":"off","stateType":"str","name":"Mute OFF","x":1200,"y":360,"wires":[[]]},{"id":"d1862827.2f0338","type":"sonos-universal","z":"48ec5f34.b0f0f","confignode":"25ad6a24.132e56","compatibilityMode":false,"command":"group.play","state":"on","stateType":"str","name":"Group Play","x":1030,"y":360,"wires":[["c3f6edf9.78171"]]},{"id":"14016201.7769ae","type":"zigbee2mqtt-server","z":"","name":"thebrain","host":"thebrain.local","mqtt_port":"1883","mqtt_username":"openhabian","mqtt_password":"geheim99","base_topic":"zigbee2mqtt"},{"id":"723d00ae.be99a","type":"better-sonos-config","z":"","name":"Wohnzimmer","serialnum":"B8-E9-37-5A-C1-5E:7","ipaddress":""},{"id":"25ad6a24.132e56","type":"sonos-config","z":"","name":"Wohnzimmer Play1","ipaddress":"192.168.1.152","port":""}]
1 Like