@guxdude Thank You for your response. In Answer to your questions…
What is triggering the speaker to ‘ungroup’?
A TV is. It is attached to a Sonos Playbar that when the TV turns on and sends sound through the Digital Audio Port, this causes the Sonos Playbar to ungroup automatically from the group it is part of. This is a hardware feature of Sonos.
I would be happy to provide an example the combination of Alexa Routines, Broadlink Scenes and Webcore Pistons I use to accomplish this, but I haven’t as of yet, as I felt it was not germane to my original question.
Perhaps instead just ignore the switch and trigger on the the change of the groupmode if you can.
I need to use the switch (Contact Sensor 37 in the Green Snapshote) because:
- There are situations I will not want the change of state in the groupRole to automatically run a piston
- I will be using the switch’s state in other pistons
- I will be using the switch in Alexa Routines
- 2 and 3 combined
- When I can figure out how to pause a piston until a condition is met, I want to use it in other scenarios. For example, when a Grouping of Sonos Speakers is complete, setting the volume of each speaker, setting a favorite to play. However, until the Grouping or Ungrouping is complete, I can’t apply the other tasks.
Part of the issue here is the Samsung implementation of the Sonos integration with SmartThings. Samsung is not providing many features including the ability to manage “Grouping” or “Ungrouping” speakers, as the two other major Home Automation platforms do. Even Wink (which I moved from) did a better job than Samsung’s SmartThings implementation. But I digress .
I am aware I can accomplish this using a Harmony and/or IFTTT and/or the jishi/ node-sonos-http-api . However, the goal is to do it all within Webcore. I don’t want to pay for an additional service or buy any additional hardware to accomplish this.
Regrettably, I am not familiar with the use of For Loop, For Each Loop, While Loop and Repeat Loop as I have not yet had a call to use them. My hope was to use some type of looping method that keeps checking the state of groupRole and when it is “ungrouped” carry on with the remaining tasks in the Piston. Along with taking into consideration the comments of @E_Sch, maybe include a break or exit after X number of times tried, to ensure no resources are wasted or failure due to resource limiters that will terminate the execution due to the use of too many resources.