Stop playback on all controllable players

I have SONOS and Google Home Mini speakers. Is there a way to stop playback on all speakers?

I’ve gotten code from ChatGPT (did not work) and Bing AI (works to some extent) and can identify my speakers by inspecting the following:

(device.driverUri === 'homey:app:com.sonos' || 
device.driverUri === '') && 
device.class === 'speaker'

It’s when I run the code for stoping playback it fails. Here’s the script I’m using:

// Stops all controllable playback
// Get all devices
let devices = await Homey.devices.getDevices();

// Iterate over all devices - find SONOS/Google speakers
for(let device of Object.values(devices)) {
    if((device.driverUri === 'homey:app:com.sonos' || device.driverUri === '') && device.class === 'speaker') {
        try {
            await device.makeCapabilityAction('speaker_playing', false).catch(console.error);
            console.log(`Stopped playback on '${}'`);
        } catch (error) {
            console.error(`Failed to stop playback on ${}:`, error);
}   }   }

For both brands of speakers I get the error from this call:
await device.makeCapabilityAction('speaker_playing', false).catch(console.error);

Failed to stop playback on Portable: TypeError: device.makeCapabilityAction is not a function

Anyone know of a way to stop playback of all devices (I’m focusing on ‘speakers’ this time)?

I see I’ve asked a similar question not long ago :- ) and applying the tip I got there I made a simple flow using the “Device Capabilities” app to stop all speakers on my network like this:

But for the sake of learning more HomeyScript, I’m still curious about any solutions out there. If you know how I could have solved this with a script, please share it here. Thanks, all!

1 Like