Run a series of commands once only


#1

1) Give a description of the problem
I am writing a simple piston that when activated (by blue iris) I want it to run once. I have a series of commands but they keep repeating.

2) What is the expected behavior?
I would like the piston to do each command only once. When the piston is activated externally I want several lights to toggle, wait several seconds, then toggle again and then stop.

3) What is happening/not happening?
Piston commands keep running and running. Toggling incessantly.

4) Post a Green Snapshot of the pistonimage
(UPLOAD YOUR IMAGE HERE)

5) Attach any logs (From ST IDE and by turning logging level to Full)

REMOVE BELOW AFTER READING


#2

What do you mean externally? You mean by using it via the external url?


#3

yes exactly. I activate the piston by using the external url.
thanks for considering.
I’ve spent a lot of time writing it and have many pistons I use. Something about how I’ve written this one makes it loop like crazy.


#4

Try adding a Boolean variable to determine if ran today.

I know this minimalistic to what you wrote, but should give you an idea and a springboard…

Also, just a note… your first if statement doesn’t have a comparison… ?


#5

It keeps looping, because when you toggle or turn the switch/outlet off, it triggers the various if statements again because the conditions are being met as true again. Thus the loops.


#6

The switches are light switches I would like to see blink on and off once any time URL activates piston. So will have to “activate” several times in a day. I have a lot of actions (several lights), can you think of a way I can get webcore to go run the piston (from top to bottom) one time for each command only each time it’s activated? I need to be sure the piston is ?“inactivated” or “stopped?”, “paused?” at the end of each run through. The first and last one ?“loop” does not have an “if” statement since I want those to simply run once each time the piston is activated without other conditions. (I’ll join those statements (1st and last) since they’re identical and that will simplify my code a tiny bit. Thanks!


#8

Hmm I’m stumped at the moment… @michicago @WCmore any ideas? The problem I’m running into, is not a loop… but it revolves around if one of the longer timers is currently running, it cancels it out, or starts it over and toggles the lights…

What I’m currently thinking is a master piston that calls sub pistons for each switch, not sure if that’s going to work either though.


#9

I am a bit pressed for time at the moment, but my first thought is that the entire piston is 100% conditions. (so they are all acting like triggers)

Since this is triggered externally, my first step would be to unsubscribe to each line that has a lightning bolt. This will not solve it entirely, but it will keep other events from messing with the flow.

You definitely want to see this when the piston is saved:


The second area I would focus on is probably dropping the “IF switch is not off” since that same command is going to toggle the same light, thereby cancelling the condition.

I would likely store the current switch state at the beginning, and make sure the final command is outside of any blocking conditions.

Notice, no matter what state the switch is in at the beginning, the first command and the wait can initiate regardless. The only real goal (in my mind) is do I end the cycle in the on or off position. (hence, my suggestion to store the state earlier)


#10

Also, if you want all 4 devices to go live at the same time, and with each on a different timer before turning off, I would code it very differently.

Turn on 4 devices
Wait 2 seconds
Turn off one device
Wait 2 seconds
Turn off another device
Wait 9m 56s
Turn off another device
Wait 20 minutes
Turn off the last device

#12

Can you explain in just plain english what you want to accomplish with this piston? I have an idea in my head, want to be sure I understand the goal.

Is it simply:
URL triggers piston
4 lights turn on
each light turns off after various times

Questions:
Do you want all 4 lights to come on at the same time, or only as the previous light in the sequence switches off?

Do you want the time fixed until the lights turn off (10 minutes, 20 seconds, etc.) or do you want it to vary?

If one of the lights was already on when the URL is triggered, what do you want to happen?


#13

Yes. URL triggers piston and 4 lights turn on various times (except if they are already on). If they are already on they I would like them to blink (turn off for 2 seconds). Essentially a notification that a sensor was activated.
Thanks for your thoughts on this!


#14

Ok, I think this closely replicates what you had in your original piston and described above as what you want. It might need a few tweaks to finalize, but it’ll be a good starting point.

Lines 44, 54, and 66 in the green snapshot, you’ll need to write in the name of the applicable device for the expression to work (they’re written to the ones I used for testing now).

Any questions on this, let me know! A quick overview of what it does:

First it saves the 3 switches you had with varying timers into two groups (on or off at the time of piston execution)
Next it toggles all lights that were already on, plus one light that you had toggle for regardless of it being on or off. Two seconds later the set of lights are toggled again.
When the lights above are toggled, any lights that were off at the beginning of piston execution are turned on.

With the IF block above complete, all that’s left to do now is go through the timers to shut lights off. 4 seconds for the first light; 10 minutes for the next light, and an additional 20 minutes for the last light (for a total of 30 minutes).


#15

Woah!
I am going to implement that and try to actually figure it out. That’s some cool programming!. Thank you


#16

Glad to help! Let me know if you have questions and I’ll help you get it set up so it does what you want it to (and you understand it so you can use the approach in new pistons).


#17

Why not use the IFTTT trigger as your overarching IF and then your lower conditions won’t matter. IF you have one trigger, all the conditions automatically turn from triggers to conditions only.
If you use device “Location” and then select IFTTT, that will give you a URL that you can call form anywhere, not just IFTTT. Then build the rest of your piston as you have it. I would never use the link at the top of the piston to execute a piston except for testing.


#18

Ryan - I thought that is what I was doing with my original piston. I think it got tangled up. Do you have a good example of a piston which activates several actions only one time using the “location” and then IFTTT? My camera software was activating the URL from the piston on my original one.

Michicago - I activated above piston and it seems to work, but not just one time. The piston stays on despite clicking on the lights and my place becomes haunted - random flickering lights over the next hours until I shut it down. I’m sure I messed something up. I’m trying to learn the “Trace” feature so I can figure out where it is going. If I decrease the times for testing I should be able to figure out where it is not stopping.

thanks!


#19

LOL, been there! If you post a snapshot of your piston and the logs from a couple recent activations, we’ll get it working.


#20


Here’s an upload of the haunted house.


#21

I can’t seem to get the log in correctly. Does it need to be full or does medium suffice?


#22

If you can’t get full to work, we can try medium. I’m not on a pc now but I’ll look at your piston in a bit.