With/do on Multiple Devices


#1

I have a piston that changes the volume on several sonos devices when one of them starts playing.

I understand why this log message is coming out as “Set volume Patio”. What I have been unable to figure out is how to get it to log 3 messages like this:

Set volume Dining Room
Set volume Kitchen
Set volume Patio

I’m actually also surprised that it doesn’t log “Set volume Patio” 3x.


#2

The Log Info statement is not run until after the setVolume command has finished, which means the $currentEventDevice variable is going to contain only the last device, in this instance, Patio.

Despite how it may appear, the setVolume command is run sequentially on each specified device, not concurrently.


#3

I believe it is setting Patio because the event was triggered by the Patio device (if Patio’s playback status changes).

If I change line 17 to a different device, $currentEventDevice changes to that because that’s the device that triggered the event.

Also if it’s truly looping through my do block; then why are there not 3 log entries being produced?


#4

The detailed log would probably show you the three set volume commands you’re looking for. But in this case as @bthrock mentioned, $currentEventDevice will only refer to the device that triggered the event, not the devices you’re acting on. If you really wanted to see the actions, you can enable Advanced Statements and create a For Loop on a device variable that contains all the media player devices.


#5

Ah! Thank you both very much. This is very helpful.

You are right that I don’t really need to log every row. It was just something I was running into and didn’t quite understand how it was working how it was, so I was troubleshooting as I was learning.

Now that I’ve seen the advanced options I went down the foreach loop idea just to see how that works.

Works exactly like I would expect now. Except I can’t figure out how to do a setVolume. The drop-down has a bunch of actions, but not setVolume. Is there a way to freestyle type something in?


#6

In the with $currentEventDevice statement, pick also one of your Sonos device to make the setVolume command available, you can remove the device from the with statement after you add the setVolume statement you want.


#7

Brilliant! Thank you.