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 === 'homey:app:com.google.chromecast') &&
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 === 'homey:app:com.google.chromecast') && device.class === 'speaker') {
try {
await device.makeCapabilityAction('speaker_playing', false).catch(console.error);
console.log(`Stopped playback on '${device.name}'`);
} catch (error) {
console.error(`Failed to stop playback on ${device.name}:`, error);
} } }
For both brands of speakers I get the error from this call:
await device.makeCapabilityAction('speaker_playing', false).catch(console.error);
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)?