Had this rule working but it failed today

I have this rule setup to let me know when my tea is done brewing so I can move it to the fridge before all the ice melts. The "Tea Brewing" is a virtual switch that I use to trigger Alexa to announce the tea is ready. Today when it was first turned on the While right after failed. How can that be it just got turned on?!?!?!?

What kind of device is "Tea Brewing"? In any case, you can see from the logs (and it's consistent with the actual behavior) that the switch is still reporting as off in that moment, even though it was just turned on. This is likely because the actions were 103 ms apart, and the event may not have been committed yet. This is particularly likely to happen with a real (Z-Wave, Zigbee, etc.) device, but even for a virtual device, it might not always be quite fast enough. That could explain the difference. As you can see, when this happens, the condition your "Repeat While" is predicated on is false, so the whole thing is skipped.

There are two ways around this. A kludgy one that is easy to work into your existing rule is to try a small delay (or really I'd use "Wait for events: elapsed time") before this While, maybe just a second or so. Speaking of delays, your "Cancel Delayed Actions" step at the beginning of this rule won't ever do anything--you don't have any actual delays in your rule. (Waits are different.) But it also won't cause any problems.

A cleaner way, since you apparently always want this repeat to execute at least once, would be to use Repeat ... Until instead of (Repeat) While ... END-REP. They are similar in that they will both repeat and stop if the expression becomes true, except Until checks at the end instead of the beginning. This does mean that it may run an "extra" time if the expression becomes true after the end of the loop (your Until) was reached, but I'm not sure if that's a problem for you since I can't tell what the actions inside really mean in your setup. You can use yet another form of repeat or possibly test some condition inside towards the end of your repeat if it is.

1 Like

Ya itโ€™s just a virtual switch. I had already added a new wait for next time but maybe Iโ€™ll redo it with the until option.


It just surprised me that a virtual switch when turned on would need any delay. Live and learn.

Okay I give up... trying to add a Repeat Until. I click the + to add an action and then Repeat Actions and under the SELECT WHICH ACTION box I have Repeat Actions, Repeat While Expression, and Stop Repeating Actions. I don't see an Until option. I must be doing something wrong what am I missing?

The "Until" is what closes it out, replacing END-REP. So, you'd choose "Repeat Actions" to start, and then "Until (expression)" where the repeat ends.

I swear I'm not this dense... Where do I find UNTIL?

I have Repeat 5 times every 00:05:00 and everything indents but I don't see where the UNTIL is. Maybe I need a drink? :smiley:

Okay I found some other posts and it's not really an UNTIL command it's just an IF and Stop Repeating I think. I'm a retired programmer and we and DO WHILE and DO UNTIL loops so I was thinking along those lines assuming there was an UNTIL command.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.