Log not executing outside trigger IF block

I have a piston that checks for a garage door that is left open. I don’t want it to trigger an alert unless it is after sundown and only if the garage door is left open for more than 20 minutes. It appears to be working correctly, but I have noticed in the logs that the exit log statement does not execute when certain conditions are met. I find this odd and makes me understand that the pistons don’t work like I expect them to, so I want to try and understand why.

Here is the piston:

Unfortunately, I edited the piston while making this post and lost the logs. I have another garage door with logs, but it does not have the entry that shows the issue since that garage door is rarely used. To give you an idea, this is from the rarely used garage door:
11/1/2019, 8:01:59 AM +49ms
+117ms ║Entering Script
+184ms ║It is not after sunset.
+192ms ║Exiting Script
11/1/2019, 8:00:59 AM +88ms
+226ms ║Entering Script
+341ms ║It is after sunset. Checking garage door…
+359ms ║Exiting Script
10/31/2019, 6:28:59 PM +74ms
+121ms ║Entering Script
+205ms ║It is after sunset. Checking garage door…
+222ms ║Exiting Script

What I saw was an entry that had
Entering Script
It is after sunset. Checking garage door…
Garage door is open, waiting…

And then nothing. I would expect to see the “Exiting Script” log, but I don’t on all of those entries where it hits the Wait block. Can someone explain why the piston exits? I would expect it to simply fall out of the inner IF, then the While loop, then the outer IF and then hit the exit log statement.

Thanks

The problem you are going to run into is that this script is going to run every minute because you don’t have a true trigger in it. Do you see those little lightning bolts? Those are the triggers that the piston will be executed because of. So, what you really want to do is this:

This will only trigger when the door is left open between the times specified in the restriction. You see the lightning bolt next to the if part of the piston? That means that it is the only trigger that will cause the piston to execute.

You can import the piston using the backup code at the top if you want to.

1 Like

That is great, thanks. I did not realize that you could check for an open door like that. I am a seasoned programmer, but find webcore to be a tough nut to crack when it comes to what things it can do and the best way to do them.

I will implement your changes because it is clearly better, but I am still curious on why the other piston did not complete like I would expect. No other code I have ever written would act the same way. Thoughts?

There is one other problem with your new script - If the garage door has been opened during the day and stays open past sunset, I would like to get notified. The old script handled this fine, but this new one looks like it will exit if the garage is opened, say, 1 hour before sunset and then continues to stay open until after sunset.

Would it be best to alter this piston to handle multiple triggers, or create a new piston that handles just that distinct use case?

Ah…you didn’t say that you wanted to check for that. :slight_smile: for that you will need another trigger, this being the the time is sunset.

The best way to look at webcore isn’t like a program, because it isn’t. You’re not writing a C++ program a java script. You’re basically writing a logic statement. So, throw out a lot of what you know about programming. If you want to use that knowledge, you should look at writing your own apps in the SmartThings IDE in Groovy (although who knows how long that will be around).

The basic rule of thumb with webCoRE is, define what will trigger the action and what conditions you want the action to happen in and then define the action you want to take. The rest is just learning where all the different commands are in the different menus.

UPDATE: Just after i posted i realize i had it for less than 20 mins. But it’s fixed now.

Makes sense.

Couldn’t I just have this for the trigger?

If garage door is open for 20 minutes OR time is sunset

Do I need the second check for the garage door being open for 20 minutes in the parens?

EDIT: here is a snapshot of what I mean

No, because that will trigger if the garage door has been open for 1 minute at sunset.

Yeah, I was aware of that but was initially worried that your version had an edge case where the garage might not have been open for 20 minutes at 5 minutes after sunset and therefore the event would be lost and not ever trigger, but thinking through it some more it appears that it would just retrigger once the door had been opened for 20 minutes. Revisiting it, it looks like it would work as intended.

Hopefully that made sense. given the difficulty of testing all the edge cases in a scenario like this I’ve been trying to opt for cleaner logic as a rule. I had a prior version of this code that I haven’t posted that had a situation where I missed an edge case and had a garage door open all night, so I am a little gun shy.

In any case, I really appreciate your help man. it’s good to talk to someone who knows what they’re doing.

Well, you eliminate edge cases if you do 2 two, eliminate edges and automate this function. This is after all, a Home AUTOMATION system… My question is, why would it be okay for the door to be open longer than 20 minutes during the day? Wouldn’t you want it closed then? Also, why not simply close the door if it’s been open for 20 minutes rather than alerting you? The alert will require you to do some action? what if you’re asleep? If you just closed the door, you would eliminate that failure point.

Those are great questions. Here are they in order:

  • why would it be okay for the door to be open longer than 20 minutes during the day? Wouldn’t you want it closed then?

I often keep it open during the day. We have two young children and when we are outside playing in the front yard (sometimes all day on the weekends) I want it open so that they can go in and out, getting their bikes and whatnot.

  • Also, why not simply close the door if it’s been open for 20 minutes rather than alerting you?

There are times when I don’t want it to close automatically, such as when we are out in front at night. One quick example that comes to mind is the fourth of july, when we are out for several hours after dark.

  • The alert will require you to do some action? what if you’re asleep?

As everything in life, you have to pick which negatives you want to manage. For me personally, it is less likely that someone will open the garage door after I am asleep, so if I am awake then I will be notified and be able to close it manually.

For me personally, there is only one thing more annoying than having to do everything manually, and that is having an automated system do it when I don’t want it to be done and i have to fight it to get it to do what I want. For other people this is not an issue, I get that.

And for those wondering, I use 20 minutes because that is enough time for someone to get home and unload a vehicle and do whatever they need to do without generating a false notification.

Thank you for your help on this! I hope this helps someone else manage their garage door too!

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.