Perform action upon break (of while loop)


#1

1) Give a description of the problem
I have a piston that works fine. But I’m just curious to see if there’s a better way to handle this. I have a piston that makes an annoucement via Echo Speaks every 1 minute that the fridge door is open.

2) What is the expected behaviour?
I’d like to see if maybe there is a better way to do it than the way I’m doing it…for example, a while loop, but then have an “on break do this” condition. This doesn’t appear to exist, but I’m curious if there’s something I haven’t learned yet that could replicate that. I’ve basically implemented this myself by having the inverse logic that’s used in the while loop, but in a second block right after that cancels the pending announcement.

This is a fairly simple example. But I have more complex examples with While loops that have more complicated conditions where having an “on break” condition would be useful.

For example:

execute
    while
        FridgeDoor's contact stays open for 1 minute
    do
        Make a GET request
    on break
    do
        Cancel all pending tasks;
    end while
end execute

Here’s a little more complicated example…where it has two things to watch…motion, and contact…Same basic structure…while loop, with a block right after that has the inverse logic to cancel the pending tasks:


#2

in your original piston, you don’t need the second ONLY WHEN part.
As soon as the door is closed, the piston will stop because the trigger/condition is no longer TRUE.


#3

Huh…that’s really weird. I disabled the cancellation actions and now the fridge piston is working as I would have expected. I only posted this because I’ve been having problems.

For the last few days, I’ve been having problems with the garage piston not cancelling its events after the while loop logic becomes false.

For example, the one for my garage door (the latter screenshot)…after the garage door closed…it would still announce that the garage door is open whenever it was scheduled to do so, as if the event wasn’t getting cancelled. I was going crazy trying to figure out wtf was going on, so finally I stuck those extra cancellation actions in and that fixed the problem. I assumed the fridge one would experience the same issue, so I made a copy of the garage one to create it.

I wonder if the issue has to do with the other logic i’m using in the garage door piston and nothing to do with the while loop logic and task cancellation logic.


#4

I guess whatever issue I was experiencing, I’m guessing is because of whatever logic I’m using in my garage piston. So I’m just going to post a new thread specifically for help on how to build that. And this thread can be ignored. Since it seems the issues I’m experiencing is not what I thought it was.


#5

I had a similar problem actually.
Our cats are not allowed in the M. Bedroom and if door left open they would come in and jump on the bed in a heartbeat. So i setup an alarm,

IF the door contact sensor stays open more than 15 seconds
Do this do that.

once or twice a day I would get false alarms. Even though the door was properly closed, the piston would get triggered.
Turned out that I had a signal problem. The sensor was not registering BEING CLOSED on time to ST hub.

maybe something you should check out?


#6

It’s possible. That makes complete sense for something that fires off if there’s no event for 15 seconds. But I’m not sure if that’s the case for my garage door piston. The problem I was having was that if i closed the garage, it would still announce the door is open (even though I could verify that both SmartThings AND WebCoRE were aware that it was closed).

Based on how the piston was configured, it looks like the [Garage Door:Contact] was not being used as a trigger, but only as a condition. So when the garage door was closed, it wasn’t breaking the while loop.

I’ve spent the last couple hours playing around with tons of variations, and I think I finally came up with one that does exactly what I need it to do…

I need both [Garage Door:Contact] and [Garage Motion Sensor 1 & 2:Motion] to act as triggers.

  • [Garage Door:Contact] = open - should trigger the announcements to start (after 5 minutes)
  • [Garage Door:Contact] = closed - should trigger the announcements to stop/cancel/break
  • [Garage Motion Sensor 1 & 2:Motion] = any active - should trigger the announcements to stop/cancel/break

I tested every scenario I could think of, and this piston acted exactly as I expected it to. So I think this is the final version.