How to execute the Sonos volumeUp command in a routine?

@granite I could use some clarifications from your instructions; trying to play a locally sourced sound file via Sonos:

  • Step 3 (as pointed out below) should probably be updated (results in Error when adding the Rule due to JSON formatting).
  • Step 4 Is this the Device ID of the Sonos, or is there is a Device ID for the “button device”? If the “button device” has it’s own Device ID, where can that be obtained from?
  • Step 7, could just be updated to point to Samsung account

I am not currently playing any locally hosted audio files via Sonos, so I don’t have any JSON to share. I did discuss my experience trying to play local and cloud stored files above:

But, with the added rules I created previously (Get Sonos Volume and Reset Sonos Volume), I have not needed to host and play my own audio files… yet!

I have just been using the built in ‘Play message on speaker’ after grabbing the prior volume with my first rule and then after my message plays, resetting the volume to its previous state with my second. Here is a screenshot of my mail notification routine using my rules to control volume:

Answering my own question, here’s the easiest steps I figured out for playing a custom wav (or mp3), triggered from a motion sensor:

In Samsung account add the JSON below:

  • First device ID ( abcd) is the motion sensor ID (Get this from the Devices tab)
  • Second device ID (wxyz) is the Sonos Speaker.
  • Got the JSON by creating a routine in the android app, then going to that “Rule” via web and viewing the JSON. Note, I had to remove all key/value pairs for the “type” key (else results in error when adding the custom rule).

The JSON:

[
  {
    "if": {
      "equals": {
        "left": {
          "device": {
            "devices": [
              "abcd"
            ],
            "component": "main",
            "capability": "motionSensor",
            "attribute": "motion",
            "trigger": "Always"
          }
        },
        "right": {
          "string": "active"
        },
        "changesOnly": false
      },
      "then": [
        {
          "command": {
            "devices": [
              "wxyz"
            ],
            "commands": [
              {
                "component": "main",
                "capability": "audioNotification",
                "command": "playTrackAndResume",
                "arguments": [
                  {
                    "string": "http://192.168.0.223:8000/test.wav"
                  }
                ]
              }
            ]
          }
        }
      ],
      "sequence": {
        "then": "Parallel",
        "else": "Parallel"
      }
    }
  }
]

Easy enough to stand up a local (LAN) webserver; here’s one in a single python command:

python3 -m http.server 8000

/cc @JKnight

1 Like