Is this a correct use of "Repeat"


#1

1) Give a description of the problem
Am I using “Repeat” correctly here. (See Green Snapshot.) Is there a more efficient method to accomplished this?

2) What is the expected behaviour?
The Piston should wait until a condition is met. In this case Unknown Device 1 (Sonos Speaker) changes from “grouped” to “ungrouped”. Then the Piston is to compete the other tasks.

While I could just use a WAIT for X number of seconds, which I have tried. The wait period can vary based on the number of devices to group, network traffic, the phase of the moon, etc. The issue I am having is the different times (delays) that it takes to ungroup the device.

3) What is happening/not happening?
If I don’t wait until Unknown Device 1 is “ungrouped” it can effect the resetting/setting of the volume on the device.

**4) Post a Green Snapshot of the piston!

5) Attach logs after turning logging level to Full
(PASTE YOUR LOGS HERE THEN HIGHLIGHT ALL OF THE LOGS AND CLICK ON THE </> ICON TO FORMAT THEM CORRECTLY)

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

it is better for automations to be event driven vs. poll driven.

I don’t know this particular device, but polling / looping to check something is wasteful of resources (and likely to fail due to resource limiters that will terminate the execution due to use of too much resources)


#3

Thanks @E_Sch for the insight, do you have any suggestions for a more efficient method to accomplish the requirement. Basically I need to pause the Piston until the state of the attribute changes (eg. Unknown Device 1 (Sonos Speaker) changes from “grouped” to “ungrouped”. )


#4

What is triggering the speaker to ‘ungroup’? Is it the same switch you are triggering on here? Perhaps instead just ignore the switch and trigger on the the change of the groupmode if you can.


#5

@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:

  1. There are situations I will not want the change of state in the groupRole to automatically run a piston
  2. I will be using the switch’s state in other pistons
  3. I will be using the switch in Alexa Routines
  4. 2 and 3 combined
  5. 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 :blush:.

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.


#6

Have you thought about triggering using groupRole changes to ungrouped, as that seems to be the key event, and then checking whether the contact sensor has recently changed to on?

Alternatively use the contact sensor switch changes to on to set a flag, and then when the groupRole changes to ungrouped check the flag.


#7

I wasn’t saying not to usr the switch anywhere. In this piston it seems you should trigger off the grouprole change rather than the switch. (As @orangebucket also stated above.)


#8

@guxdude apologies for misunderstanding :slight_smile:


#9

@orangebucket thank you for the suggestions.

Yes I believe

triggering using groupRole changes to ungrouped , as that seems to be the key event, and then checking whether the contact sensor has recently changed to on

Would Work for items 1-4

  1. There are situations I will not want the change of state in the groupRole to automatically run a piston.
  1. I will be using the switch’s state in other pistons
  2. I will be using the switch in Alexa Routines
  3. 2 and 3 combined

Below is what I believe you are suggesting.