Compounding Pistons with Timers's


#1

I’m using Pistons to Execute other Pistons. IE, I have a “Master Presence” Piston that has rules about phone location, and then I have other pistons that fire depending on what the Master Presence piston tell it to do.

One of the Pistons that gets fired is called “I’m Back”. Now, it has a timer in it for Sunset. I don’t want it to execute the section with the timer unless I’ve actually executed the piston. How can I do that? Example of the “I’m Back” piston below.


#2

I like your logic. I have structured many of my pistons in a similar fashion…

One thing I do different is I make sure there are no triggers in the “I’m Back!” piston. This lets any other piston call it, but prevents the piston from running itself, so to speak.

When the piston is saved, you want to see this up top:

For example, in your pic above, the entire logic will run thru (top to bottom) each time Contact Sensor 1 is closed. (line 29) The way it is currently worded, closing that contact after sunset will turn on Switch 1, and also turn 3 other bulbs to 50%.

Heck, it might even unlock your doors. **shivers at the thought**

I always recommend EXTREME caution if you absolutely must program Auto-Unlocks.

If it were me, I would not leave the house until I resolved this, or at the very least, disabled that section of code.


Anyways, back on topic…
If you do not wish to remove the subscribed triggers, then you have many other options revolving around variables and/or arguments in some way. Probably the easiest is having your other piston send the current piston’s External URL in a GET web request to pass the data. (instead of the Execute piston command you are using now) Then, in your “I’m Back!” piston, you can set it to only do commands if a specific argument has been passed.

A example would be.

Piston 1

Set variable {triggered} = {"true"};
Make a GET request to https://api.smartthings.com/api/token/abc123/smartapps/installations/def456/execute/:ghi789:?triggered={triggered};

This link points to the External URL of “I’m Back!”, but I added to the end of the URL:
?triggered={triggered}
Which actually sends:
?triggered=true


Then we can add one line to

Piston 2 - "I’m Back!"

IF
    Date & Time is after sunset
    and 
    {$args.triggered} = true       <-- new line
THEN
    Set Bulbs to whatever
END IF

Any block of code with that extra line in it, will only follow thru if the right parameters were sent from another piston.


#3

Hey WCMore-

Thanks for your response. It was very helpful in us understanding the logic of how Webcore thinks.

What we have done to combat this issue, is we’ve turned off subscriptions on specific events so the piston won’t run on its own, and we’ve also placed Exits in various places so the piston won’t run all the way through if an action in the middle is triggered.

Got a little deep, but this seems quite clean to us in the end. Thank you!


#4

Glad to be able to help. Sorry if I rambled on a bit, LOL

Just be aware that the logic will start at the top each time the “middle” section you mentioned is triggered. (the Exit will only prevent the LOWER commands from being run)